Machine learning to help Elderly
Population of the world is progressively getting older. According to United Nations,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).
In 2050, two out of every three oldest-old persons will live in developing regions.
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.
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/>”
test = pd.read_csv(test_url)
solution = pd.read_csv(soultion_url)
# generate ‘activitydf’ DF
actdf = pd.DataFrame(train[‘activity’].value_counts().reset_index())
actdf.columns = [‘activity’, ‘count’]
Lets look at the date-times
from datetime import datetime
train[“onlydate”] = train.date.apply(lambda x : x.split())
train[“hour”] = train.date.apply(lambda x : x.split().split(“:”))
train[“min”] = train.date.apply(lambda x : x.split().split(“:”))
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)
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”])
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
sn.heatmap(corrMatt, mask=mask,vmax=.8, square=True,annot=True)
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(
fig = go.Figure(data=data, layout=layout)
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.
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.