Machine learning to help Elderly

Source: un.org

Population of the world is progressively getting older. According to United Nations[1],by 2030, older persons will outnumber children aged 0-9 years (1.4 billion vs. 1.3 billion); by 2050, there will be more people aged 60 or over than adolescents and youth aged 10-24 years (2.1 billion vs. 2.0 billion).

Source: http://www.un.org/en/development/desa/population/publications/pdf/ageing/WPA2015_Report.pdf

In 2050, two out of every three oldest-old persons will live in developing regions.

Source: un.org

These people will need help and fortunately with the development of machine learning, and proliferation of IOT devices we will be able to help. One paper that talks about using machine learning to help the elderly is An Agent-based Approach to Care in Independent Living.

The paper introduces a fall detector based on a neural network and a multi-agent architecture for requesting emergency services. It presented a multi-agent system for the care of elderly people living at home on their own, with the aim to prolong their independence. The system is composed of seven groups of agents providing a reliable, robust and flexible monitoring by sensing the user in the environment, reconstructing the position and posture to create the physical awareness of the user in the environment, reacting to critical situations, calling for help in the case of an emergency, and issuing warnings if unusual behavior is detected.

Source: http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=D4F68AC886F5F0470207D1ACB782BF7A?doi=10.1.1.301.3380&rep=rep1&type=pdf

The system has been tested during several on-line demonstration. People used for recording of the data were wearing four tags (ankle left, ankle right, belt and chest). Each instance is a localization data for one of the tags. The tag can be identified by one of the attributes.

The authors of the paper donated the data to UCI repository and we have data readily available in test and train form, from arithmetica.io to analyze . The goal for arithmetica’s practice was to predict activity, given the type and location of sensor. In the next few paragraphs we will look at the code for doing this in python. The ipython notebook can be downloaded from here.

import pandas as pd
# Read Data from URL
train_url = “<download from
https://arithmetica.io/practice/4/>”
test_url = “<download from
https://arithmetica.io/practice/4/>”
soultion_url = “<download from
https://arithmetica.io/practice/4/>”
train=pd.read_csv(train_url)
test = pd.read_csv(test_url)
solution = pd.read_csv(soultion_url)

View the test and train data

# generate ‘activitydf’ DF
actdf = pd.DataFrame(train[‘activity’].value_counts().reset_index())
actdf.columns = [‘activity’, ‘count’]
actdf

Analysis

Lets look at the date-times

import datetime
from datetime import datetime
import calendar

train[“onlydate”] = train.date.apply(lambda x : x.split()[0])
train[“hour”] = train.date.apply(lambda x : x.split()[1].split(“:”)[0])
train[“min”] = train.date.apply(lambda x : x.split()[1].split(“:”)[1])

train[“weekday”] = train.date.apply(lambda dateString : calendar.day_name[datetime.strptime(dateString,”%d.%m.%Y %H:%M:%S:%f”).weekday()])
train[“month”] = train.date.apply(lambda dateString : calendar.month_name[datetime.strptime(dateString,”%d.%m.%Y %H:%M:%S:%f”).month])
# drop non-necessary columns
train = train.drop([“date”],axis=1)

Lets look at the X-Y-Z co-ordinates

train[[‘xcord’,’ycord’,’zcord’]] = train[[‘xcord’,’ycord’,’zcord’]].apply(pd.to_numeric)

Using MatplotLib

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection=’3d’)
#ax = fig.add_subplot(111, projection=’3d’)

for row in range(0, 100):
 ax.scatter(train.iloc[row][“xcord”], train.iloc[row][“ycord”], train.iloc[row][“zcord”])
 
ax.set_xlabel(‘X ‘)
ax.set_ylabel(‘Y ‘)
ax.set_zlabel(‘Z ‘)

plt.show()

Using Seaborn — Correlation Matrix

#import missingno as msno
import seaborn as sn
corrMatt = train[[“sequence”,”tag”,”xcord”,”ycord”,”zcord”,”activity”]].corr()

#corrMatt = train[[“sequence”,”tag”,”xcord”,”ycord”,”zcord”,”onlydate”,”hour”,”min”,”activity”]].corr()
mask = np.array(corrMatt)
mask[np.tril_indices_from(mask)] = False
fig,ax= plt.subplots()
fig.set_size_inches(20,10)
sn.heatmap(corrMatt, mask=mask,vmax=.8, square=True,annot=True)
plt.show()

Using Plotly

import plotly as py
py.tools.set_credentials_file(username=’<your username>’, api_key=’<your apikey>’)

#import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np

#x, y, z = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose()
train = train[0:200]
trace1 = go.Scatter3d(x=train[“xcord”],y=train[“ycord”],z=train[“zcord”],mode=’markers’)

data = [trace1]
layout = go.Layout(
 margin=dict(
 l=0,
 r=0,
 b=0,
 t=0
 )
)
fig = go.Figure(data=data, layout=layout)
py.plotly.iplot(fig, filename=’simple-3d-scatter’)

X-Y-Z visualized through plotly

In the spirit of learning, I will leave the reader inquisitive and provide you part my work, as ipython notebook. I would like the reader to play with data and submit their work for this practice data-set on arithmetica.

Author’s Note:

Taposh Dutta Roy, leads Innovation Team of Decision Support at Kaiser Permanente. These thoughts and recommendations are not of Kaiser Permanente and Kaiser Permanente is not responsible for the content. If you have questions Mr. Dutta Roy can be reached via linkedin.

Resources:

http://archive.ics.uci.edu/ml/datasets.html