Last Updated on
The personal IoT is dominated by the use of wearable and technological devices designed to be worn on body; they are used in tandem with an app on a smartphone.
The first wearable available was the Pulsar Calculator watch made by Time Computer Inc, USA (at that time known as Hamilton Watch Company). It was a standalone device not connected to the internet. Soon, with the growth of the internet, wearables that can connect to the internet became a fad.
The wearable market is expected to jump from an estimate of 325million in 2016 to over 830million by 2020:
This graph shows the number of wearables worldwide from 2016–2021 (data source: Statista).
With so many devices connected online, continuously generating data, AI/ML tools are a natural choice to analyse this data and make informed decisions.
See also: Wearable fitness tracker as an IoT application
In this article, you will learn about some successful personal IoT solutions.
SuperShoes by MIT
Holding your mobile in one hand and navigating your way along the road with the help of Google Maps, how often have you thought that it is cumbersome? How often have you wished for magic slippers that will take you anywhere you want? SuperShoes by MIT Media
Lab (https://www.media.mit.edu/projects/supershoes/overview/) are almost like those magic slippers; they allow the user to navigate through the sidewalks without any need to check the smartphone screen.
SuperShoes have flexible insoles, embedded with vibrating motors under the toes. They connect wirelessly to an app on the smartphone. The app not only allows the user to interface with the SuperShoes, but it also stores likes/dislikes, hobbies, shops, foods, people, interests, and so on in a cloud account.
The vibrating motors generate tickles that communicate with the user. Once the user enters a destination on the app, the shoes start their work. If the left toe tickles then the user is supposed to take a left turn; if the right toe tickles then the user has to take a right turn. When there is no tickle, then the user has to continue straight. If both tickle repeatedly, the user has arrived at their destination.
Besides navigation, it can also recommend places of interest nearby; the user updates their likes and dislikes on the cloud. Based on the likes and dislikes of the user, SuperShoe also gives an indication (both toes tickle once) when the user is near a recommended place of interest.
Another interesting feature of SuperShoes is that it can give reminders as well; it can remind you if you have a task on a location nearby.
The hardware required to make this shoe is very simple, it requires the following:
- Three vibrotactile ticklers to tickle the toes
- A capacitive pad to sense the walk
- A microcontroller that takes the commands from the app, and accordingly, controls the ticklers
- A Bluetooth device to connect with the smartphone
- Batteries to power the entire system
The magic is performed by the software coded into the app. You can learn more about the SuperShoes at this website: http://dhairyadand.com/works/supershoes.
Continuous glucose monitoring
A major application of AI has been in IoT for healthcare, with one of the most successful commercial applications being continuous monitoring of the body’s glucose level. Abbott’s FreeStyle CGM, DexCom CGM, and Medtronic CGM are some of the commercially available brands.
Continuous glucose monitoring (CGM) allows people suffering from diabetes to check their body’s glucose level in real time. It helps them in monitoring the readings over a period of time, and the data can also be used to prediction of future glucose level, thus helping them to deal with conditions like hypoglycemia.
In CGM, normally a sensor is placed either under the skin of the belly or adhered to the back of your arm. The sensor sends the readings to a connected pager/smartphone app.
The app has additional AI-based algorithms that can inform the user of any clinically relevant glucose patterns. The availability of this data not only helps the user to proactively manage their glucose highs and lows, but additionally, it can also provide an insight into the impact that meals, exercise, or illness may have on a person’s glucose levels.
The sensors have a lifespan ranging from 7 to 14 days, normally this time is sufficient for a medical practitioner to understand the person’s lifestyle, and accordingly, suggest changes.
Hypoglycemia prediction using CGM data
Once a person has CGM data, it can be analyzed using AI/ML to gather more information or to make a prediction about hypoglycemia. In this section, we see how we can use the algorithms make a glucose-predictor system.We will build our predictor based on the research paper Glucose Concentration can be Predicted Ahead in Time From Continuous Glucose Monitoring sensor Time-Series by Sparacino et al. (10.1109/TBME.2006.889774).
In the paper, the CGM time series glucose data is described by a times series model; the paper considered two models, one a simple first order polynomial and second a first order autoregressive model. The model parameters are fitted at each sampling time, ts, against the past glucose data. Here, we will implement the simple first order polynomial using scikit linear regressor:
We import the modules pandas to read the csv file, NumpPy for data processing, Matplolib for plotting, and scikit-learn for the linear regressor, as follows:
import pandas as pd importnumpy as np importmatplotlib.pyplot as plt fromsklearn.linear_model import LinearRegression %matplotlib inline
Save the data obtained from your CGM in the data folder and read it. We require two values, the glucose reading and its time. The data that we are using has these available in two CSV files, ys.csv and ts.csv. The first one contains the glucose value and the second one contains the corresponding time, as follows:
# Read the data ys = pd.read_csv('data/ys.csv') ts = pd.read_csv('data/ts.csv')
According to the paper, we define two parameters of the predictive model ph, the prediction horizon, and mu the forgetting factor:
# MODEL FIT AND PREDICTION
# MODEL FIT AND PREDICTION # Parameters of the predictive model.ph is Prediction horizon, mu is Forgetting factor. ph = 10 mu = 0.98
We create the arrays to hold our predicted values, shown as follows:
n_s = len(ys) # Arrays to hold predicted values tp_pred = np.zeros(n_s-1) yp_pred = np.zeros(n_s-1)
We now read the CGM data simulating the real-time acquisition and predict the glucose level ph minutes forward. All the past data is used to determine the model parameters; however, each has a different contribution decided by the individual weight assigned to it muk (to the sample taken k instants before the actual sampling time):
# At every iteration of the for loop a new sample from CGM is acquired. for i in range(2, n_s+1): ts_tmp = ts[0:i] ys_tmp = ys[0:i] ns = len(ys_tmp) # The mu**k assigns the weight to the previous samples. weights = np.ones(ns)*mu for k in range(ns): weights[k] = weights[k]**k weights = np.flip(weights, 0) # MODEL # Linear Regression. lm_tmp = LinearRegression() model_tmp = lm_tmp.fit(ts_tmp, ys_tmp, sample_weight=weights) # Coefficients of the linear model, y = mx + q m_tmp = model_tmp.coef_ q_tmp = modeltmp.intercept # PREDICTION tp = ts.iloc[ns-1,0] + ph yp = m_tmp*tp + q_tmp tp_pred[i-2] = tp yp_pred[i-2] = yp
We can see that the prediction is lagging behind the actual. The normal glucose level lies in the range 70 to 180. Below 70, the patient can suffer from hypoglycemia and above 180 it can lead to hyperglycemia. Let us see the plot of our predicted data:
# PLOT # Hypoglycemia threshold vector. t_tot = [l for l in range(int(ts.min()), int(tp_pred.max())+1)] hypoglycemiaTH = 70*np.ones(len(t_tot)) #hyperglycemiaTH = 180*np.ones(len(t_tot)) fig, ax = plt.subplots(figsize=(10,10)) fig.suptitle('Glucose Level Prediction', fontsize=22, fontweight='bold') ax.set_title('mu = %g, ph=%g ' %(mu, ph)) ax.plot(tp_pred, yp_pred, label='Predicted Value') ax.plot(ts.iloc[:,0], ys.iloc[:,0], label='CGM data') ax.plot(t_tot, hypoglycemiaTH, label='Hypoglycemia threshold') #ax.plot(t_tot, hyperglycemiaTH, label='Hyperglycemia threshold') ax.set_xlabel('time (min)') ax.set_ylabel('glucose (mg/dl)') ax.legend()
The RMSE error will be 27 for the following code:
fromsklearn.metrics import mean_squared_error as mse print("RMSE is", mse(ys[1:],yp_pred))
You can refer to the complete code located at https://github.com/PacktPublishing/Hands-On-Artificial-Intelligence-for-IoT/blob/master/Chapter09/Hypoglycemia%20Prediction.ipynb. The glucose-prediction system is available in many commercial products. You can make one too, based on the model that we just made. You can also use an artificial neural network to make a similar prediction with better results (refer to https://www.ncbi.nlm.nih.gov/pubmed/20082589).
Another very useful personal application of AI in IoT is in the detection of heart disease. A large number of wearables exist that can be used to monitor and record heart rate. The data can be used to predict any harmful heart condition.
Here, we will employ AI/ML tools to predict cardiac arrhythmia, a group of conditions where the heart rate is irregular; it can be either too fast (above 100 beats per minute) or too slow (below 60 beats per minute). The data used is taken from the UCI Machine learning Repository dataset at https://archive.ics.uci.edu/ml/datasets/heart+Disease.
The dataset consists of 76 attributes, not all required for prediction of the presence of disease; the dataset has a goal field associated with each data row. It has five possible values 0–4, the value 0 indicates a healthy heart, and any other value means there is a disease.
The problem can be broken into binary classification problems for better accuracy. The code is inspired from the GitHub link of Mohammed Rashad, it is shared under the GNU GPL 3.0 license at https://github.com/MohammedRashad/Deep-Learning-and-Wearable-IoT-to-Monitor-and-Predict-Cardiac-Arrhytmia.
The complete code can be accessed from GitHub repository at https://github.com/PacktPublishing/Hands-On-Artificial-Intelligence-for-IoT/blob/master/Chapter09/Heart_Disease_Prediction.ipynb:
The first step as always is to import the necessary modules. Since we are now classifying the patients as suffering from heart disease or not, we will need a classifier. Here for simplicity, we use the SVC classifier. You can experiment with the MLP classifier, shown as follows:
# importing required libraries importnumpy as np import pandas as pd importmatplotlib.pyplot as plt fromsklearn.svm import SVC fromsklearn import metrics fromsklearn.metrics import confusion_matrix fromsklearn.model_selection import train_test_split
Next, read the dataset, preprocess the dataset to select the attributes you will be considering. We chose 13 attributes from 76, and then we convert the target from a multi-class value to binary class. Finally, the data is split into the train and test dataset, as follows:
# reading csv file and extracting class column to y. dataset = pd.read_csv("data.csv") dataset.fillna(dataset.mean(), inplace=True) dataset_to_array = np.array(dataset) label = dataset_to_array[:,57] # "Target" classes having 0 and 1 label = label.astype('int') label[label>0] = 1 # When it is 0 heart is healthy, 1 otherwise # extracting 13 features dataset = np.column_stack(( dataset_to_array[:,4] , # pain location dataset_to_array[:,6] , # relieved after rest dataset_to_array[:,9] , # pain type dataset_to_array[:,11], # resting blood pressure dataset_to_array[:,33], # maximum heart rate achieve dataset_to_array[:,34], # resting heart rate dataset_to_array[:,35], # peak exercise blood pressure (first of 2 parts) dataset_to_array[:,36], # peak exercise blood pressure (second of 2 parts) dataset_to_array[:,38], # resting blood pressure dataset_to_array[:,39], # exercise induced angina (1 = yes; 0 = no) dataset.age, # age dataset.sex , # sex dataset.hypertension # hyper tension )) print ("The Dataset dimensions are : " , dataset.shape , "\n") # dividing data into train and test data X_train, X_test, y_train, y_test = train_test_split(dataset, label, random_state = 223)
Now, we define the model to be used. Here we are using a support vector classifier, using the ‘fit’ function to train the dataset:
model = SVC(kernel = 'linear').fit(X_train, y_train)
Let us see its performance on the test dataset:
model_predictions = model.predict(X_test) # model accuracy for X_test accuracy = metrics.accuracy_score(y_test, model_predictions) print ("Accuracy of the model is :" , accuracy , "\nApproximately : ", round(accuracy*100) , "%\n")
You can see that it provides an accuracy of 74%, using MLP, we can increase it further. But do remember to normalize all the input features before using the MLP classifier. The following is the confusion matrix of our trained support vector classifier on the test dataset:
#creating a confusion matrix cm = confusion_matrix(y_test, model_predictions) import pandas as pd importseaborn as sn importmatplotlib.pyplot as plt %matplotlib inline df_cm = pd.DataFrame(cm, index = [i for i in "01"], columns = [i for i in "01"]) plt.figure(figsize = (10,7)) sn.heatmap(df_cm, annot=True)
The following output shows the confusion matrix for the test dataset:
You can train your model on the same dataset and use your trained model to predict heart conditions for your friends, family, or clients.
Digital assistants are one of the oldest conceived AI applications.
Initial attempts at digital assistants never really took off. But with the advent and mass spread of smartphones, today we have a large number of digital assistants providing services such as dialing a phone number, writing a text message, scheduling appointments, or even searching the internet for you.
You can ask them for recommendations for nearby restaurants and bars or any other similar thing.
Some of the following are popular digital assistants:
- Siri: Developed by Apple, it allows the user to send/make calls, add appointments in the calendar, play music or video, and even send a text. Today, a voice-activated interface is available on almost all Apple products.
- Cortana: Created by Microsoft, it helps you to stay on schedule by reminding you to do things based on time, place, or even people. You can ask Cortana to order lunch for you or use any other app it partners with. It comes integrated with Edge and invokes a voice-activated speaker featuring Cortana.
- Alexa: Developed by Amazon, this is available with Amazon Echo smart speakers. It can play music, make a to-do list, set alarms for you, play audio books, and provide real-time information on stocks, weather, and more. It is also capable of voice interaction.
- Google Assistant: This is a voice-controlled smart assistant. It provides continued conversation, that is you don’t have to say Hey Google for any follow-up requests, once you start talking, it listens for a response without needing the triggering phrase. It can also recognize the voice profiles for different people and can tailor its response according to the personal likes and dislikes of that person. It is available not only on Android smartphones but also on Google Home.
In 2018, Google went even further, releasing Google Duplex, an assistant that can make calls for you and book your appointments. It talks like a human, and also understands the context when speaking.
To sum up, the focus of this article was personal IoT solutions. The large-scale use of smartphones has brought wearable sensors to every person’s reach, resulting in a plethora of personal apps.
We explored and implemented some successful personal AI-powered IoT solutions. We learned about SuperShoes by MIT, shoes that can find their own path to the destination.
We learned about CGM systems and implemented code to predict hyperglycemia. This article also demonstrated how personalized heart monitors can be implemented.
About the author:
Amita Kapoor, an associate professor in the Department of Electronics, SRCASW, University of Delhi completed her master’s in electronics in 1996 and her PhD in 2011. During her PhD she was awarded the prestigious DAAD fellowship to pursue part of her research at the Karlsruhe Institute of Technology, Karlsruhe, Germany. She was awarded the Best Presentation Award at the Photonics 2008 international conference. She is an active member of ACM, AAAI, IEEE, and INNS. She has co-authored two books. She has more than 40 publications in international journals and conferences. Her present research areas include machine learning, artificial intelligence, deep reinforcement learning, and robotics.
featured image credit: Inside feature images all small images credit Pixabay