Professional Documents
Culture Documents
CHAPTER 1
INTRODUCTION
Human activity detection plays one of the most significant roles in smart home
Environments and covers a wide range of applications including healthcare, daily fitness
recording, and anomalous situations alerting. Some of the simple human activities
includes (walking, running, sitting, etc.) are necessary for understanding complex human
behaviors. Also, the detection of activities such as walking and sitting can provide useful
information about a person's health condition. Nowadays, smartphone is not only a
device for communication but also smartphone-based applications are used everywhere.
Most smart phones have a tri-axial accelerometer and gyroscope as well as orientation
sensors. All these sensors can be used to know the acceleration and rate of rotation on
and around three physical axes (X, Y, and Z). With all these embedded sensors, we can
recognize different kinds of activities instead of using other wearable sensors attached to
human body. In this project, we are trying to build a smart phone-based human activity
detection system. The data are collected by the embedded sensors of the smartphones.
And some machine learning algorithms (Naive Bayes, Decision tree and Multilayer
Perceptron) are used to make the classifications.
study in the activity detection has been so quick and progressive that it started to serve
as the applications that go beyond the activity detection.
The classical workflow of a human activity detection system deals with data
acquisition from different sensors of the smartphones generated during each activity
performed by the users that are recorded and sent to the remote system. This data is then
processed to remove noise and to obtain a cleaner and transformed data suitable for
further processing. The data is then explored to understand its nature and the type of
processing that can be applied in the next stages. The design of the later phases could
differ vastly on the application and its domain. But typically, the data is engineered to
make it more suitable by extracting more useful features from it. Moreover, the data is
segmented on basis of the window size of some frequency that needs to be performed.
Finally, a analytical model is created to recognize the activities performed by the user and
is assessed for its performance. This detected activity can be repurposed for numerous
applications as detecting change in the user activity, assistance in regard to the detected
activity etc.
machine learning algorithms are employed to make the classifications and predict the
activities with promising preliminary results.
Human activity detection has been extensively studied in the literature. Some
approaches and prototypes have been developed according to the different kinds of
information and algorithms. The data used for detection comprise video data or sensor
data (acceleration, orientation, and angular speed, etc.). The sensors could be on-board
smartphone sensors or sensors installed in wearable devices. Additionally, different
methods and algorithms can be used for activity detection. The hidden Markov model
(HMM) and the conditional random field (CRF) are among the most popular modelling
techniques.
values are being recorded. The sampling frequency is about 20Hz. Moreover, four-time
domain features (maximum, minimum, mean, and standard deviation of every 20 values)
are computed and stored. So, a fixed window length without overlapping is used in the
feature extraction phase. For each sensor, we consider its three axes as three individual
features. As we monitor four sensors and there are five-time domain features for each
axis as well as three axes for each sensor, a total of 60 features are extracted for each
instance. The activity types are labelled manually in each file.
1.5.3 SEGMENTATION
After the data preprocessing, comes the segmentation where the data is being
segmented based on the window size. Here, window size refers to the time interval
between each activity.
Feature extraction includes a large number of features, and hence the array is
reduced before classifier construction. The step includes selection of the most significant
features for classification. Here, we monitor the changes in linear accelerometer,
gyroscope and orientation sensors values. The values are changes after a fixed time
interval and are recorded and we are finding out the relation within the data values such
as maximum, minimum, standard deviation and the mean. Hence the data values are
computed and stored. So, a fixed window size without overlapping is used in the feature
extraction.
CHAPTER 2
LITERATURE SURVEY
The use of multiple sensors to achieve the same goal makes the application bulky
leading to slower processing of the data and also affects its cost.
In most of the application positioning of the device is also concerned with the
success of the application i.e. Most of the application build are position specific device. If
the device kept in hands then the values will be different from the values being generated
when the device is kept in pocket.
• Firstly, the data generated from the different sensors are taken as an input to the
system for the analysis.
• After the data is provided by the user the code comes into action and from that
machine learning algorithms and tools will come into action.
• The first step will be the preparation of the data for the analysis purpose which
also involves cleaning of the data and discarding the data with null or no values.
• After the data is prepared for the analysis purpose the data is segmented further
according the window size. Here the window size is the time interval between each
activity.
• After the data is being segmented the data is further sent for feature extraction
where we find out the relationship between the data values. (MAX, MIN, MEAN,
Standard Deviation).
• And finally, with the help of different classifier algorithm the system will be able
to detect the human activity.
2.4.1 Python
Python and its libraries like NumPy, SciPy, Scikit-Learn, Matplotlib are used in data
science and data analysis. They are also widely used for creating scalable machine
learning algorithms. Python implements popular machine learning techniques such as
Classification, Regression, Recommendation, and Clustering.
Python offers convenient framework for performing data mining tasks on large
volumes of data effectively and efficiently in lesser time. It comprises several
implementations achieved through algorithms such as linear regression, logistic
regression, Naïve Bayes, k-means, K nearest neighbor, and Random Forest.
Data science, machine learning and artificial intelligence are some of the most top
trending topics in the tech world today. Data mining and Bayesian analysis are trending
and this is adding the demand for machine learning.
The developed machine learning algorithms are used in various applications such as –
▪ Vision processing
▪ Language processing
▪ Pattern recognition
▪ Games
▪ Data mining
▪ Expert systems
▪ Robotics
▪ Defining a Problem
▪ Preparing Data
▪ Evaluating Algorithms
▪ Improving Results
▪ Presenting Results
The best way to get started using Python for machine learning is to work through a
project end-to-end and cover the crucial steps like loading data, summarizing data,
evaluating algorithms and making some predictions. This gives you a replicable method
that can be used dataset after dataset. You can also add further data and improve the
results.
In order to understand machine learning, first you need to have a basic knowledge
of Python programming. Furthermore, there are a number of libraries and packages that
are generally used in performing several machine learning tasks as listed below –
scikit-learn − is the algorithms used for data analysis and data mining tasks.
Install Anaconda
To install Python and other scientific computing and machine learning packages at
the same time, we need to install Anaconda distribution. It is a Python implementation
for Linux, Windows and OSX, and includes various machine learning packages like numpy,
scikit-learn, and matplotlib. It also includes Jupyter Notebook, an interactive Python
environment. We can install Python 2.7 or any 3.x version as per our requirement. Note
that you have to ensure that Anaconda’s Python distribution installs into a single
directory, and does not affect other Python installations, if any, on your system. In order
to work with graphs and plots, we will need these Python library packages -
matplotlib and seaborn.
common classification algorithms include logistic regression, Naïve Bayes, decision trees,
and K Neighbors.
Bayes theorem delivers a way of calculating posterior probability P(c|x) from P(c),
P(x) and P(x|c). Look at the equation below:
• P(c|x) is the posterior probability of class (c, target) given predictor (x, attributes).
Let’s try to understand it using a simple example. In the following example I have a
training data set of weather and corresponding target variable ‘Play’ (suggesting
possibilities of playing). Now, we need to classify whether players will play or not based
on weather condition. Let’s follow the following steps to perform it.
Step 2: Create Likelihood table by finding the probabilities like Overcast probability = 0.29
and probability of playing is 0.64.
Step 3: Now, use Naive Bayesian equation to calculate the posterior probability for each
class. The class with the highest posterior probability is the outcome of prediction.
Problem: Players will play if weather is sunny. Is this statement being correct?
Here we have P (Sunny |Yes) = 3/9 = 0.33, P(Sunny) = 5/14 = 0.36, P(Yes)= 9/14 = 0.64
Now, P (Yes | Sunny) = 0.33 * 0.64 / 0.36 = 0.60, which has higher probability.
Naive Bayes uses a similar method to predict the probability of different class based
on various attributes. This algorithm is mostly used in text classification and with problems
having multiple classes.
Advantages:
▪ It is easy and fast to predict class of test data set. It also accomplishes well in multi
class prediction
▪ When assumption of independence holds, a Naive Bayes classifier performs better
when compare to other models like logistic regression and you need less training
data.
▪ It performs well in case of categorical input variables compared to numerical
variable(s). For numerical variable, normal distribution is assumed (bell curve,
which is a strong assumption).
Disadvantages:
▪ If categorical variable has a category (in test data set), not being observed in
training data set, then the model will assign a 0 (zero) probability and will be
unable to make a prediction. This is often known as “Zero Frequency”. To solve
this, we can use the smoothing technique. One of the simplest smoothing
techniques is called Laplace estimation.
▪ On the other hand, naive Bayes is also known as a bad estimator, so the probability
outputs from predict_proba are not to be taken too seriously.
▪ Links – It is basically a set of connection links that carries a weight including a bias
having a weight 1.
▪ Adder – It basically adds the input after they are being multiplied with their
respective weights.
▪ Activation Function – It basically limits the output of neuron and returns 1, if the
input is positive and 0 for any negative input.
Training Algorithm
The perceptron network can be trained for single as well as multiple output units.
The basics steps involved in training the single Output Unit is described below:
• Weights
• Bias
• Learning rate α
For the ease of calculation and simplicity, weights and bias must be assigned to 0 and the
learning rate must be equal to 1.
Step 2 – Continue step 3-8 when the stopping condition is not true.
Step 5 – Now find the net input with the following relation -
Step 6 – Apply the following activation function to obtain the final output.
Case 1 – if y ≠ t then,
Case 2 – if y = t then,
Step 8 – This is Test for the stopping condition that would arise when there is no change
in weight.
• Weights
• Bias
• Learning rate α
For the ease of calculation and simplicity, weights and bias must be assigned to 0 and the
learning rate must be equal to 1.
Step 2 – Continue step 3-8 when the stopping condition is not true.
Step 5 – Now find the net input with the following relation -
Step 6 – Apply the following activation function to obtain the final output for each
output unit j = 1 to m –
Case 1 – if yj ≠ tj then,
Case 2 - if yj = tj then,
Step 8 – This is Test for the stopping condition that would arise when there is no change
in weight.
Training Algorithm
The training algorithm for the BPN uses binary sigmoid activation function and
consist of these three phases –
• Weights
• Learning rate α
For the ease of calculation and simplicity, take some random values.
Step 2 – Continue step 3-11 when the stopping condition is not true.
Phase 1
Step 4 − Each input unit receives input signal xi and sends it to the hidden unit for all i = 1
to n
Step 5 − Calculate the net input at the hidden unit using the following relation –
Here b0j is the bias on hidden unit, vij is the weight on j unit of the hidden layer coming
from i unit of the input layer.
Now calculate the net output by applying the following activation function -
Send these output signals of the hidden layer units to the output layer units.
Step 6 − Calculate the net input at the output layer unit using the following relation −
Here b0k is the bias on output unit, wjk is the weight on k unit of the output layer coming
from j unit of the hidden layer.
Phase 2
Step 7 − Calculate the error correcting term, in correspondence with the target pattern
received at each output unit, as follows −
Step 8 − Now each hidden unit will be the sum of its delta inputs from the output units.
Phase 3
Step 9 − Each output unit (ykk = 1 to m) updates the weight and bias as follows −
Step 10 − Each output unit (zjj = 1 to p) updates the weight and bias as follows –
Step 11 – Now check for the stopping condition, that can be either the number of
epochs reached or the target output matches the actual output.
Decision Tree is an important algorithm for predictive modeling and can be used to
visualize and explicitly represent decisions. It is basically a graphical representation of
branching methodology to demonstrate all possible outcomes based on certain
conditions. The decision tree consists of:
Classification Tree:
The Classification Tree is used to separate a dataset into different classes based on
the particular basis and is generally used when we expect response variable in categorical
nature.
Regression Tree:
The other type of decision tree is known as Regression Tree which is used when the
response variable is continuous or numerical.
Decision Tree classifier is the simplest and widely used classification technique. It
applies a straightforward idea to solve the classification problem.
▪ Tree Construction
2. Divide the given data into sets on the basis of this attribute.
3. For every set created above – repeat 1 and 2 until you find leaf nodes in all the
branches of the tree – Terminate.
Identify and remove branches in the Decision Tree that are not useful for
classification.
Table 2.3 Three Data Sets formed after division at root node on the basis of “age” attribute.
age?
<=30
31...40
>40
Student?
Credit rating?
no yes Yes
excellent fair
no Yes
no Yes
Fig 2.6 Decision Tree
The final decision tree is constructed on the basis of described manner, classify a test
sample.
Information Gain
Gini Ratio
The information gain is partial for the attributes with many outcomes which means
it prefers the attribute with larger number of distinct values. C4.5, is an improvement of
ID3, uses an extension to the information gain known as gain ratio.
Gini Index
It is used in Classification and Regression Tree and thus measures the impurity of D,
a data partition or set of training tuples as
CHAPTER 3
REQUIREMENT ANALYSIS
3.1 PURPOSE
1) Framework for Activity detection of Human, by applying Machine Learning
Algorithm.
3.1.1 Scope
▪ The system should be capable of taking data input from the user.
▪ The system should be able to train the model using the training sets and assign
labels to the parameter.
▪ The system must validate trained model using test set as well as labeled data.
▪ The system should be able to classify the data based on the labels.
▪ The system should be able to accurately classify the activity being performed by
the user.
▪ Reliability
▪ Maintainability
▪ Performance
▪ Portability
▪ Scalability
▪ Flexibility
CHAPTER 4
DESIGN
The architecture diagram shown above shows the details of system which is been
carried in our proposed work, activity is being sensed first. Then these activities are then
filtered for the removal of noise and normalization of data. After that in feature extraction,
we monitor the changes in linear accelerometer, gyroscope and orientation sensors
values. The values are changes after a fixed time interval and are recorded and we are
finding out the relation within the data values maximum, minimum, standard deviation
and the mean. Hence the data values are computed and stored. So, a fixed window size
without overlapping is used in the feature extraction. And after that the based on the
classification algorithms the data is being trained first in the training phase and then from
the learned model the activity is prediction is made and the predicted activity is being
recognized in the testing phase.
Data Segmentation
based on Window
Size Segmented Data
Feature Extraction
(MAX, MIN, MEAN and
Standard Deviation)
Features
Classifier Algorithms
The above diagram shows us the flow of the program. The data is first collected
from linear accelerometer and then the raw data is filtered and then it is being segmented
and then data is sent for feature extraction where the relation (MAX, MIN, MEAN and
Standard Deviation) between the data value is found. After that the classifier algorithms
like Naïve Bayes, Multilayer Perceptron and Decision Tree is being applied and the
corresponding activity of the human being is detected with the better accuracy result.
CHAPTER 5
The raw data is first converted into CSV file before they are analyzed and the results
are produced. To do so we are using Python inbuilt libraries like pandas and NumPy.
The splitting of data into training and testing set is one of the most key elements
in machine learning. Here we are making the use of inbuilt Python libraries and function
to achieve our task. Here we need to determine the test size sample before splitting the
data. In our project we have taken test size as 20 percent of the original data.
Below is the Python code for building a model using Naïve Bayes:
Below is the Python code for building a model using Decision Tree:
Below is the Python code for building a model using Multilayer Perceptron:
Here,
The above confusion matrix diagram shows that through Multilayer Perceptron
classifier we got an accuracy of 97% while in case of Naïve Bayes it is 81.3% and in case of
Decision Tree it is 86.28%. The classes that are being correctly classified is inside the
diagonal while the classes that are being misclassified are outside of the diagonal.
Accuracy:
Recall:
Precision:
F1 score:
It is the harmonic mean of precision and recall taking both metrics into account in
the following equation:
CHAPTER 6
SNAPSHOT
CHAPTER 6
6.1 CONCLUSION
Human Activity Detection has wide-range of applications in medical research and
human health domain. Through this project, we can recognize six different human activities:
walking, laying, sitting, standing, walking upstairs and walking downstairs. The system
collected time series data using the inbuilt smartphone sensors like accelerometer,
gyroscope and orientation sensor. The activity data were trained and tested using 3
classifiers algorithms like Naïve Bayes, Decision Tree and Multilayer Perceptron.
The best out of the three classifiers in terms of accuracy is being the Multilayer
Perceptron with an accuracy rate of 97.36% while the Decision Tree has the accuracy rate
of 86.28% and the Naïve Bayes being the lowest with an accuracy rate of 81.30%. Hence
these results are enough to demonstrate that the Multilayer Perceptron is the optimal
choice for our problem.
REFERENCES
1 Z. Zhou, X. Chen, Y. Chung, Z. He, T.X. Han, J.M. Keller, "Activity Analysis,
Summarization, and Visualization for Indoor Human Activity Monitoring, " IEEE
Transactions on Circuits and Systems for Video Technology, 18(11), 1489-1498, 2008.
2 J. Cho, J.T. Kim, T. Kim, "Smart Phone-based Human Activity Classification and Energy
Expenditure Generation in Building Environments, " 7th International Symposium on
Sustainable Healthy Buildings (SHB'2012), 2012.
4 S. Chen, Y. Huang, "Recognizing human activities from multi-modal sensors, " IEEE
International Conference on Intelligence and Security Informatics (ISI'09), pp.
220,222, 2009.
7 E. Kim, s. Helal, D. Cook, "Human Activity Recognition and Pattern Discovery, " IEEE
Pervasive Computing, 9(1), 48-53, 2010. [2] Z. Zhou, X. Chen, Y. Chung, Z. He, T.X.
Han, J.M. Keller, "Activity Analysis, Summarization, and Visualization for Indoor
Human Activity Monitoring, " IEEE Transactions on Circuits and Systems for Video
Technology, 18(11), 1489-1498, 2008.
8 M. Zhang, A.A. Sawchuk, "USC-HAD: a daily activity dataset for ubiquitous activity
recognition using wearable sensors, " ACM Conference on Ubiquitous Computing
(UbiComp'12), pp. 1036,1043, 2012.
9 B. Dong, S. Biswas, "Wearable networked sensing for human mobility and activity
analytics: A systems study, " Fourth International Conference on Communication
Systems and Networks (COMSNETS), pp. 1,6, 2012.
10 J. Yin, Q. Yang, J.J. Pan, "Sensor-Based Abnormal Human-Activity Detection, " IEEE
Transactions on Knowledge and Data Engineering, 20(8), 1082-1090, 2008.
11 D. Curone, G.M. Bertolotti, A. Cristiani, E.L. Secco, G. Magenes, "A Real-Time and
Self-Calibrating Algorithm Based on Triaxial Accelerometer Signals for the Detection
of Human Posture and Activity, " IEEE Transactions on Information Technology in
Biomedicine, 14(4), 1098-1105, 2010.
12 C.V.c. Bouten, K. T.M. Koekkoek, M. Verduin, R. Kodde, J.D. Janssen, "A triaxial
accelerometer and portable data processing unit for the assessment of daily physical
activity, " IEEE Transactions on Biomedical Engineering, 44(3), \36-147, 1997.