Skip to content

The intuition behind this project is to Recognize Human Activity using Waist-mounted smartphone with an embedded inertial sensor. The objective is to classify activities into one of the six activities performed. The Dataset is collected from kaggle.com

Notifications You must be signed in to change notification settings

adnanrahin/Human-Activity-Recognition-Classifier

Repository files navigation

Train Data

tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) angle(Y,gravityMean) angle(Z,gravityMean) subject Activity
0 0.288585 -0.020294 -0.132905 -0.995279 -0.983111 -0.913526 -0.995112 -0.983185 -0.923527 -0.934724 ... -0.710304 -0.112754 0.030400 -0.464761 -0.018446 -0.841247 0.179941 -0.058627 1 STANDING
1 0.278419 -0.016411 -0.123520 -0.998245 -0.975300 -0.960322 -0.998807 -0.974914 -0.957686 -0.943068 ... -0.861499 0.053477 -0.007435 -0.732626 0.703511 -0.844788 0.180289 -0.054317 1 STANDING
2 0.279653 -0.019467 -0.113462 -0.995380 -0.967187 -0.978944 -0.996520 -0.963668 -0.977469 -0.938692 ... -0.760104 -0.118559 0.177899 0.100699 0.808529 -0.848933 0.180637 -0.049118 1 STANDING
3 0.279174 -0.026201 -0.123283 -0.996091 -0.983403 -0.990675 -0.997099 -0.982750 -0.989302 -0.938692 ... -0.482845 -0.036788 -0.012892 0.640011 -0.485366 -0.848649 0.181935 -0.047663 1 STANDING
4 0.276629 -0.016570 -0.115362 -0.998139 -0.980817 -0.990482 -0.998321 -0.979672 -0.990441 -0.942469 ... -0.699205 0.123320 0.122542 0.693578 -0.615971 -0.847865 0.185151 -0.043892 1 STANDING

5 rows × 563 columns

Test Data

tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) angle(Y,gravityMean) angle(Z,gravityMean) subject Activity
0 0.257178 -0.023285 -0.014654 -0.938404 -0.920091 -0.667683 -0.952501 -0.925249 -0.674302 -0.894088 ... -0.705974 0.006462 0.162920 -0.825886 0.271151 -0.720009 0.276801 -0.057978 2 STANDING
1 0.286027 -0.013163 -0.119083 -0.975415 -0.967458 -0.944958 -0.986799 -0.968401 -0.945823 -0.894088 ... -0.594944 -0.083495 0.017500 -0.434375 0.920593 -0.698091 0.281343 -0.083898 2 STANDING
2 0.275485 -0.026050 -0.118152 -0.993819 -0.969926 -0.962748 -0.994403 -0.970735 -0.963483 -0.939260 ... -0.640736 -0.034956 0.202302 0.064103 0.145068 -0.702771 0.280083 -0.079346 2 STANDING
3 0.270298 -0.032614 -0.117520 -0.994743 -0.973268 -0.967091 -0.995274 -0.974471 -0.968897 -0.938610 ... -0.736124 -0.017067 0.154438 0.340134 0.296407 -0.698954 0.284114 -0.077108 2 STANDING
4 0.274833 -0.027848 -0.129527 -0.993852 -0.967445 -0.978295 -0.994111 -0.965953 -0.977346 -0.938610 ... -0.846595 -0.002223 -0.040046 0.736715 -0.118545 -0.692245 0.290722 -0.073857 2 STANDING

5 rows × 563 columns

Train Data Vizualization

Trainning Classes

png

How Training data are speread into data set

png

tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... fBodyBodyGyroJerkMag-skewness() fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) angle(Y,gravityMean) angle(Z,gravityMean) subject
count 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 ... 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000 7352.000000
mean 0.274488 -0.017695 -0.109141 -0.605438 -0.510938 -0.604754 -0.630512 -0.526907 -0.606150 -0.468604 ... -0.307009 -0.625294 0.008684 0.002186 0.008726 -0.005981 -0.489547 0.058593 -0.056515 17.413085
std 0.070261 0.040811 0.056635 0.448734 0.502645 0.418687 0.424073 0.485942 0.414122 0.544547 ... 0.321011 0.307584 0.336787 0.448306 0.608303 0.477975 0.511807 0.297480 0.279122 8.975143
min -1.000000 -1.000000 -1.000000 -1.000000 -0.999873 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 ... -0.995357 -0.999765 -0.976580 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 1.000000
25% 0.262975 -0.024863 -0.120993 -0.992754 -0.978129 -0.980233 -0.993591 -0.978162 -0.980251 -0.936219 ... -0.542602 -0.845573 -0.121527 -0.289549 -0.482273 -0.376341 -0.812065 -0.017885 -0.143414 8.000000
50% 0.277193 -0.017219 -0.108676 -0.946196 -0.851897 -0.859365 -0.950709 -0.857328 -0.857143 -0.881637 ... -0.343685 -0.711692 0.009509 0.008943 0.008735 -0.000368 -0.709417 0.182071 0.003181 19.000000
75% 0.288461 -0.010783 -0.097794 -0.242813 -0.034231 -0.262415 -0.292680 -0.066701 -0.265671 -0.017129 ... -0.126979 -0.503878 0.150865 0.292861 0.506187 0.359368 -0.509079 0.248353 0.107659 26.000000
max 1.000000 1.000000 1.000000 1.000000 0.916238 1.000000 1.000000 0.967664 1.000000 1.000000 ... 0.989538 0.956845 1.000000 1.000000 0.998702 0.996078 1.000000 0.478157 1.000000 30.000000

8 rows × 562 columns

Best Parameter for DecisionTreeClassifier Using RandomSearchCV

RandomizedSearchCV(cv=None, error_score=nan,
                   estimator=DecisionTreeClassifier(ccp_alpha=0.0,
                                                    class_weight=None,
                                                    criterion='gini',
                                                    max_depth=None,
                                                    max_features=None,
                                                    max_leaf_nodes=None,
                                                    min_impurity_decrease=0.0,
                                                    min_impurity_split=None,
                                                    min_samples_leaf=1,
                                                    min_samples_split=2,
                                                    min_weight_fraction_leaf=0.0,
                                                    presort='deprecated',
                                                    random_state=None,
                                                    splitter='best'),
                   iid='deprecated', n_iter=10, n_jobs=None,
                   param_distributions={'criterion': ['gini', 'entropy'],
                                        'max_depth': [5, 6, 7, 8, 9, 10, 15],
                                        'min_samples_leaf': [2, 4, 6]},
                   pre_dispatch='2*n_jobs', random_state=42, refit=True,
                   return_train_score=False, scoring=None, verbose=0)

Decision Tree Confusion Matrix

png

Classification Report

                    precision    recall  f1-score   support

            LAYING       1.00      1.00      1.00       537
           SITTING       0.82      0.81      0.81       491
          STANDING       0.83      0.83      0.83       532
           WALKING       0.82      0.91      0.86       496
WALKING_DOWNSTAIRS       0.82      0.86      0.84       420
  WALKING_UPSTAIRS       0.86      0.73      0.79       471

          accuracy                           0.86      2947
         macro avg       0.86      0.86      0.86      2947
      weighted avg       0.86      0.86      0.86      2947

K - Nearest Neighbor

Hyperparameter Tuning using GridSearchCV

GridSearchCV(cv=10, error_score=nan,
             estimator=KNeighborsClassifier(algorithm='auto', leaf_size=30,
                                            metric='minkowski',
                                            metric_params=None, n_jobs=None,
                                            n_neighbors=5, p=2,
                                            weights='uniform'),
             iid='deprecated', n_jobs=None,
             param_grid={'leaf_size': [100, 200, 400],
                         'n_neighbors': [5, 10, 15, 20],
                         'weights': ['uniform', 'distance']},
             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,
             scoring=None, verbose=0)

Parameters Cross validation Scores

{'mean_fit_time': array([0.9833288 , 1.01018047, 0.97393866, 1.03180003, 1.00484285,
        1.0009861 , 0.95736079, 0.95537102, 0.86311636, 0.83865423,
        0.84260538, 0.81234019, 0.81643698, 0.82432711, 0.83826373,
        0.81385148, 0.69424596, 0.72932589, 0.69188905, 0.71505296,
        0.68060167, 0.73592076, 0.73995571, 0.75275621]),
 'std_fit_time': array([0.06628775, 0.06133024, 0.02741047, 0.03346197, 0.02662681,
        0.0371974 , 0.04174371, 0.03046969, 0.02637069, 0.04391606,
        0.02216211, 0.02602417, 0.02653173, 0.03268621, 0.02836933,
        0.01965087, 0.02920461, 0.05515497, 0.03741543, 0.01354451,
        0.03011129, 0.04008596, 0.02800346, 0.04655738]),
 'mean_score_time': array([1.06189265, 1.07332931, 1.10777717, 1.13303299, 1.21390772,
        1.17987356, 1.23332827, 1.17406003, 1.04527724, 1.01447372,
        1.08605642, 1.03799293, 1.08341451, 1.07243233, 1.13417971,
        1.11480918, 1.02674885, 1.005845  , 1.08556042, 1.03169703,
        1.08297384, 1.11800549, 1.16635559, 1.17006154]),
 'std_score_time': array([0.23956356, 0.26363011, 0.2598528 , 0.25333403, 0.27462399,
        0.26992445, 0.28593096, 0.2628897 , 0.24671801, 0.2257647 ,
        0.27324628, 0.21937784, 0.26188519, 0.25724271, 0.25782156,
        0.26369499, 0.27830301, 0.2187268 , 0.27953336, 0.25301241,
        0.24835224, 0.26079719, 0.29660296, 0.27657547]),
 'param_leaf_size': masked_array(data=[100, 100, 100, 100, 100, 100, 100, 100, 200, 200, 200,
                    200, 200, 200, 200, 200, 400, 400, 400, 400, 400, 400,
                    400, 400],
              mask=[False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False],
        fill_value='?',
             dtype=object),
 'param_n_neighbors': masked_array(data=[5, 5, 10, 10, 15, 15, 20, 20, 5, 5, 10, 10, 15, 15, 20,
                    20, 5, 5, 10, 10, 15, 15, 20, 20],
              mask=[False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False],
        fill_value='?',
             dtype=object),
 'param_weights': masked_array(data=['uniform', 'distance', 'uniform', 'distance',
                    'uniform', 'distance', 'uniform', 'distance',
                    'uniform', 'distance', 'uniform', 'distance',
                    'uniform', 'distance', 'uniform', 'distance',
                    'uniform', 'distance', 'uniform', 'distance',
                    'uniform', 'distance', 'uniform', 'distance'],
              mask=[False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False],
        fill_value='?',
             dtype=object),
 'params': [{'leaf_size': 100, 'n_neighbors': 5, 'weights': 'uniform'},
  {'leaf_size': 100, 'n_neighbors': 5, 'weights': 'distance'},
  {'leaf_size': 100, 'n_neighbors': 10, 'weights': 'uniform'},
  {'leaf_size': 100, 'n_neighbors': 10, 'weights': 'distance'},
  {'leaf_size': 100, 'n_neighbors': 15, 'weights': 'uniform'},
  {'leaf_size': 100, 'n_neighbors': 15, 'weights': 'distance'},
  {'leaf_size': 100, 'n_neighbors': 20, 'weights': 'uniform'},
  {'leaf_size': 100, 'n_neighbors': 20, 'weights': 'distance'},
  {'leaf_size': 200, 'n_neighbors': 5, 'weights': 'uniform'},
  {'leaf_size': 200, 'n_neighbors': 5, 'weights': 'distance'},
  {'leaf_size': 200, 'n_neighbors': 10, 'weights': 'uniform'},
  {'leaf_size': 200, 'n_neighbors': 10, 'weights': 'distance'},
  {'leaf_size': 200, 'n_neighbors': 15, 'weights': 'uniform'},
  {'leaf_size': 200, 'n_neighbors': 15, 'weights': 'distance'},
  {'leaf_size': 200, 'n_neighbors': 20, 'weights': 'uniform'},
  {'leaf_size': 200, 'n_neighbors': 20, 'weights': 'distance'},
  {'leaf_size': 400, 'n_neighbors': 5, 'weights': 'uniform'},
  {'leaf_size': 400, 'n_neighbors': 5, 'weights': 'distance'},
  {'leaf_size': 400, 'n_neighbors': 10, 'weights': 'uniform'},
  {'leaf_size': 400, 'n_neighbors': 10, 'weights': 'distance'},
  {'leaf_size': 400, 'n_neighbors': 15, 'weights': 'uniform'},
  {'leaf_size': 400, 'n_neighbors': 15, 'weights': 'distance'},
  {'leaf_size': 400, 'n_neighbors': 20, 'weights': 'uniform'},
  {'leaf_size': 400, 'n_neighbors': 20, 'weights': 'distance'}],
 'split0_test_score': array([0.74320652, 0.74048913, 0.72826087, 0.73777174, 0.72554348,
        0.72282609, 0.72418478, 0.72418478, 0.74320652, 0.74048913,
        0.72826087, 0.73777174, 0.72554348, 0.72282609, 0.72418478,
        0.72418478, 0.74320652, 0.74048913, 0.72826087, 0.73777174,
        0.72554348, 0.72282609, 0.72418478, 0.72418478]),
 'split1_test_score': array([0.81793478, 0.81929348, 0.8111413 , 0.81929348, 0.80298913,
        0.80434783, 0.79891304, 0.80298913, 0.81793478, 0.81929348,
        0.8111413 , 0.81929348, 0.80298913, 0.80434783, 0.79891304,
        0.80298913, 0.81793478, 0.81929348, 0.8111413 , 0.81929348,
        0.80298913, 0.80434783, 0.79891304, 0.80298913]),
 'split2_test_score': array([0.80136054, 0.79319728, 0.78911565, 0.78231293, 0.78503401,
        0.78367347, 0.77823129, 0.77687075, 0.80136054, 0.79319728,
        0.78911565, 0.78231293, 0.78503401, 0.78367347, 0.77823129,
        0.77687075, 0.80136054, 0.79319728, 0.78911565, 0.78231293,
        0.78503401, 0.78367347, 0.77823129, 0.77687075]),
 'split3_test_score': array([0.72244898, 0.71972789, 0.71972789, 0.72380952, 0.7170068 ,
        0.7170068 , 0.72108844, 0.7170068 , 0.72244898, 0.71972789,
        0.71972789, 0.72380952, 0.7170068 , 0.7170068 , 0.72108844,
        0.7170068 , 0.72244898, 0.71972789, 0.71972789, 0.72380952,
        0.7170068 , 0.7170068 , 0.72108844, 0.7170068 ]),
 'split4_test_score': array([0.84081633, 0.84489796, 0.84081633, 0.84217687, 0.82721088,
        0.83129252, 0.83401361, 0.82993197, 0.84081633, 0.84489796,
        0.84081633, 0.84217687, 0.82721088, 0.83129252, 0.83401361,
        0.82993197, 0.84081633, 0.84489796, 0.84081633, 0.84217687,
        0.82721088, 0.83129252, 0.83401361, 0.82993197]),
 'split5_test_score': array([0.87346939, 0.87346939, 0.8707483 , 0.86938776, 0.86938776,
        0.86938776, 0.85578231, 0.86258503, 0.87346939, 0.87346939,
        0.8707483 , 0.86938776, 0.86938776, 0.86938776, 0.85578231,
        0.86258503, 0.87346939, 0.87346939, 0.8707483 , 0.86938776,
        0.86938776, 0.86938776, 0.85578231, 0.86258503]),
 'split6_test_score': array([0.88435374, 0.88707483, 0.88435374, 0.89659864, 0.89795918,
        0.89795918, 0.89387755, 0.8952381 , 0.88435374, 0.88707483,
        0.88435374, 0.89659864, 0.89795918, 0.89795918, 0.89387755,
        0.8952381 , 0.88435374, 0.88707483, 0.88435374, 0.89659864,
        0.89795918, 0.89795918, 0.89387755, 0.8952381 ]),
 'split7_test_score': array([0.81904762, 0.81496599, 0.82721088, 0.81632653, 0.82040816,
        0.81768707, 0.83537415, 0.82585034, 0.81904762, 0.81496599,
        0.82721088, 0.81632653, 0.82040816, 0.81768707, 0.83537415,
        0.82585034, 0.81904762, 0.81496599, 0.82721088, 0.81632653,
        0.82040816, 0.81768707, 0.83537415, 0.82585034]),
 'split8_test_score': array([0.88571429, 0.88707483, 0.90748299, 0.90340136, 0.90340136,
        0.9047619 , 0.89931973, 0.8952381 , 0.88571429, 0.88707483,
        0.90748299, 0.90340136, 0.90340136, 0.9047619 , 0.89931973,
        0.8952381 , 0.88571429, 0.88707483, 0.90748299, 0.90340136,
        0.90340136, 0.9047619 , 0.89931973, 0.8952381 ]),
 'split9_test_score': array([0.88163265, 0.87755102, 0.89659864, 0.90068027, 0.88843537,
        0.88979592, 0.89115646, 0.89659864, 0.88163265, 0.87755102,
        0.89659864, 0.90068027, 0.88843537, 0.88979592, 0.89115646,
        0.89659864, 0.88163265, 0.87755102, 0.89659864, 0.90068027,
        0.88843537, 0.88979592, 0.89115646, 0.89659864]),
 'mean_test_score': array([0.82699848, 0.82577418, 0.82754566, 0.82917591, 0.82373761,
        0.82387385, 0.82319414, 0.82264936, 0.82699848, 0.82577418,
        0.82754566, 0.82917591, 0.82373761, 0.82387385, 0.82319414,
        0.82264936, 0.82699848, 0.82577418, 0.82754566, 0.82917591,
        0.82373761, 0.82387385, 0.82319414, 0.82264936]),
 'std_test_score': array([0.05552198, 0.0570757 , 0.06297321, 0.06234568, 0.06411713,
        0.06493891, 0.0629104 , 0.06403336, 0.05552198, 0.0570757 ,
        0.06297321, 0.06234568, 0.06411713, 0.06493891, 0.0629104 ,
        0.06403336, 0.05552198, 0.0570757 , 0.06297321, 0.06234568,
        0.06411713, 0.06493891, 0.0629104 , 0.06403336]),
 'rank_test_score': array([ 7, 10,  4,  1, 16, 13, 19, 22,  7, 10,  4,  1, 16, 13, 19, 22,  7,
        10,  4,  1, 16, 13, 19, 22])}

About

The intuition behind this project is to Recognize Human Activity using Waist-mounted smartphone with an embedded inertial sensor. The objective is to classify activities into one of the six activities performed. The Dataset is collected from kaggle.com

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published