Created
September 2, 2021 06:11
-
-
Save joksim/12f6d2b445c57e71e9c3b6227b561833 to your computer and use it in GitHub Desktop.
Datasets for AAL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Datasets for AAL" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Dataset input" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"from sklearn import preprocessing\n", | |
"from sklearn.impute import SimpleImputer" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The data set given below contains data from different sensors divided according to the type of activity in which that data was obtained." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"activity_recognition = pd.read_csv(\"activity_recognition.csv\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>tBodyAcc-mean()-X</th>\n", | |
" <th>tBodyAcc-mean()-Y</th>\n", | |
" <th>tBodyAcc-mean()-Z</th>\n", | |
" <th>tBodyAcc-std()-X</th>\n", | |
" <th>tBodyAcc-std()-Y</th>\n", | |
" <th>tBodyAcc-std()-Z</th>\n", | |
" <th>tBodyAcc-mad()-X</th>\n", | |
" <th>tBodyAcc-mad()-Y</th>\n", | |
" <th>tBodyAcc-mad()-Z</th>\n", | |
" <th>tBodyAcc-max()-X</th>\n", | |
" <th>...</th>\n", | |
" <th>fBodyBodyGyroJerkMag-kurtosis()</th>\n", | |
" <th>angle(tBodyAccMean,gravity)</th>\n", | |
" <th>angle(tBodyAccJerkMean),gravityMean)</th>\n", | |
" <th>angle(tBodyGyroMean,gravityMean)</th>\n", | |
" <th>angle(tBodyGyroJerkMean,gravityMean)</th>\n", | |
" <th>angle(X,gravityMean)</th>\n", | |
" <th>angle(Y,gravityMean)</th>\n", | |
" <th>angle(Z,gravityMean)</th>\n", | |
" <th>subject</th>\n", | |
" <th>Activity</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0.288585</td>\n", | |
" <td>-0.020294</td>\n", | |
" <td>2.000000</td>\n", | |
" <td>-0.995279</td>\n", | |
" <td>-0.983111</td>\n", | |
" <td>-0.913526</td>\n", | |
" <td>-0.995112</td>\n", | |
" <td>-0.983185</td>\n", | |
" <td>-0.923527</td>\n", | |
" <td>-0.934724</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.710304</td>\n", | |
" <td>-0.112754</td>\n", | |
" <td>0.030400</td>\n", | |
" <td>-0.464761</td>\n", | |
" <td>-0.018446</td>\n", | |
" <td>-0.841247</td>\n", | |
" <td>0.179941</td>\n", | |
" <td>-0.058627</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0.278419</td>\n", | |
" <td>-0.016411</td>\n", | |
" <td>NaN</td>\n", | |
" <td>-0.998245</td>\n", | |
" <td>-0.975300</td>\n", | |
" <td>-0.960322</td>\n", | |
" <td>-0.998807</td>\n", | |
" <td>-0.974914</td>\n", | |
" <td>-0.957686</td>\n", | |
" <td>-0.943068</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.861499</td>\n", | |
" <td>0.053477</td>\n", | |
" <td>-0.007435</td>\n", | |
" <td>-0.732626</td>\n", | |
" <td>0.703511</td>\n", | |
" <td>-0.844788</td>\n", | |
" <td>0.180289</td>\n", | |
" <td>-0.054317</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0.279653</td>\n", | |
" <td>NaN</td>\n", | |
" <td>-0.113462</td>\n", | |
" <td>-0.995380</td>\n", | |
" <td>-0.967187</td>\n", | |
" <td>-0.978944</td>\n", | |
" <td>-0.996520</td>\n", | |
" <td>-0.963668</td>\n", | |
" <td>-0.977469</td>\n", | |
" <td>-0.938692</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.760104</td>\n", | |
" <td>-0.118559</td>\n", | |
" <td>0.177899</td>\n", | |
" <td>0.100699</td>\n", | |
" <td>0.808529</td>\n", | |
" <td>-0.848933</td>\n", | |
" <td>0.180637</td>\n", | |
" <td>-0.049118</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0.279174</td>\n", | |
" <td>-0.026201</td>\n", | |
" <td>-0.123283</td>\n", | |
" <td>-0.996091</td>\n", | |
" <td>NaN</td>\n", | |
" <td>-0.990675</td>\n", | |
" <td>-0.997099</td>\n", | |
" <td>-0.982750</td>\n", | |
" <td>-0.989302</td>\n", | |
" <td>-0.938692</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.482845</td>\n", | |
" <td>-0.036788</td>\n", | |
" <td>-0.012892</td>\n", | |
" <td>0.640011</td>\n", | |
" <td>-0.485366</td>\n", | |
" <td>-0.848649</td>\n", | |
" <td>0.181935</td>\n", | |
" <td>-0.047663</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0.276629</td>\n", | |
" <td>-0.016570</td>\n", | |
" <td>-0.115362</td>\n", | |
" <td>-0.998139</td>\n", | |
" <td>-0.980817</td>\n", | |
" <td>-0.990482</td>\n", | |
" <td>-0.998321</td>\n", | |
" <td>-0.979672</td>\n", | |
" <td>-0.990441</td>\n", | |
" <td>-0.942469</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.699205</td>\n", | |
" <td>0.123320</td>\n", | |
" <td>0.122542</td>\n", | |
" <td>0.693578</td>\n", | |
" <td>-0.615971</td>\n", | |
" <td>-0.847865</td>\n", | |
" <td>0.185151</td>\n", | |
" <td>-0.043892</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9212</th>\n", | |
" <td>0.280272</td>\n", | |
" <td>-0.009753</td>\n", | |
" <td>-0.101004</td>\n", | |
" <td>-0.990222</td>\n", | |
" <td>-0.936652</td>\n", | |
" <td>-0.917424</td>\n", | |
" <td>-0.991822</td>\n", | |
" <td>-0.931656</td>\n", | |
" <td>-0.915447</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.587673</td>\n", | |
" <td>-0.013873</td>\n", | |
" <td>0.023064</td>\n", | |
" <td>-0.678024</td>\n", | |
" <td>0.554907</td>\n", | |
" <td>-0.830144</td>\n", | |
" <td>0.202810</td>\n", | |
" <td>-0.037548</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9213</th>\n", | |
" <td>0.279837</td>\n", | |
" <td>-0.010076</td>\n", | |
" <td>-0.104020</td>\n", | |
" <td>-0.990730</td>\n", | |
" <td>-0.937395</td>\n", | |
" <td>-0.930183</td>\n", | |
" <td>-0.992462</td>\n", | |
" <td>-0.934817</td>\n", | |
" <td>-0.927397</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.534130</td>\n", | |
" <td>0.001598</td>\n", | |
" <td>0.214234</td>\n", | |
" <td>-0.757211</td>\n", | |
" <td>-0.858485</td>\n", | |
" <td>-0.833311</td>\n", | |
" <td>0.199265</td>\n", | |
" <td>-0.039705</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9214</th>\n", | |
" <td>0.284586</td>\n", | |
" <td>0.009560</td>\n", | |
" <td>-0.127466</td>\n", | |
" <td>-0.987178</td>\n", | |
" <td>-0.907089</td>\n", | |
" <td>-0.869253</td>\n", | |
" <td>-0.988715</td>\n", | |
" <td>-0.900716</td>\n", | |
" <td>-0.860351</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.734724</td>\n", | |
" <td>0.049755</td>\n", | |
" <td>-0.083072</td>\n", | |
" <td>-0.566907</td>\n", | |
" <td>-0.890635</td>\n", | |
" <td>-0.838057</td>\n", | |
" <td>0.194527</td>\n", | |
" <td>-0.041538</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9215</th>\n", | |
" <td>0.278569</td>\n", | |
" <td>-0.019880</td>\n", | |
" <td>-0.113155</td>\n", | |
" <td>-0.978584</td>\n", | |
" <td>-0.816673</td>\n", | |
" <td>-0.840812</td>\n", | |
" <td>-0.981292</td>\n", | |
" <td>-0.801595</td>\n", | |
" <td>-0.833486</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.807478</td>\n", | |
" <td>-0.072195</td>\n", | |
" <td>-0.095446</td>\n", | |
" <td>-0.606008</td>\n", | |
" <td>0.904715</td>\n", | |
" <td>-0.851110</td>\n", | |
" <td>0.186154</td>\n", | |
" <td>-0.037937</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9216</th>\n", | |
" <td>0.269317</td>\n", | |
" <td>-0.036996</td>\n", | |
" <td>-0.084908</td>\n", | |
" <td>-0.984239</td>\n", | |
" <td>-0.856710</td>\n", | |
" <td>-0.915329</td>\n", | |
" <td>-0.987352</td>\n", | |
" <td>-0.856968</td>\n", | |
" <td>-0.907003</td>\n", | |
" <td>-0.922066</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.388797</td>\n", | |
" <td>-0.006762</td>\n", | |
" <td>0.096378</td>\n", | |
" <td>0.827367</td>\n", | |
" <td>0.828512</td>\n", | |
" <td>-0.848590</td>\n", | |
" <td>0.188972</td>\n", | |
" <td>-0.036494</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>9217 rows × 563 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z \\\n", | |
"0 0.288585 -0.020294 2.000000 \n", | |
"1 0.278419 -0.016411 NaN \n", | |
"2 0.279653 NaN -0.113462 \n", | |
"3 0.279174 -0.026201 -0.123283 \n", | |
"4 0.276629 -0.016570 -0.115362 \n", | |
"... ... ... ... \n", | |
"9212 0.280272 -0.009753 -0.101004 \n", | |
"9213 0.279837 -0.010076 -0.104020 \n", | |
"9214 0.284586 0.009560 -0.127466 \n", | |
"9215 0.278569 -0.019880 -0.113155 \n", | |
"9216 0.269317 -0.036996 -0.084908 \n", | |
"\n", | |
" tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X \\\n", | |
"0 -0.995279 -0.983111 -0.913526 -0.995112 \n", | |
"1 -0.998245 -0.975300 -0.960322 -0.998807 \n", | |
"2 -0.995380 -0.967187 -0.978944 -0.996520 \n", | |
"3 -0.996091 NaN -0.990675 -0.997099 \n", | |
"4 -0.998139 -0.980817 -0.990482 -0.998321 \n", | |
"... ... ... ... ... \n", | |
"9212 -0.990222 -0.936652 -0.917424 -0.991822 \n", | |
"9213 -0.990730 -0.937395 -0.930183 -0.992462 \n", | |
"9214 -0.987178 -0.907089 -0.869253 -0.988715 \n", | |
"9215 -0.978584 -0.816673 -0.840812 -0.981292 \n", | |
"9216 -0.984239 -0.856710 -0.915329 -0.987352 \n", | |
"\n", | |
" tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... \\\n", | |
"0 -0.983185 -0.923527 -0.934724 ... \n", | |
"1 -0.974914 -0.957686 -0.943068 ... \n", | |
"2 -0.963668 -0.977469 -0.938692 ... \n", | |
"3 -0.982750 -0.989302 -0.938692 ... \n", | |
"4 -0.979672 -0.990441 -0.942469 ... \n", | |
"... ... ... ... ... \n", | |
"9212 -0.931656 -0.915447 -0.926574 ... \n", | |
"9213 -0.934817 -0.927397 -0.926574 ... \n", | |
"9214 -0.900716 -0.860351 -0.921330 ... \n", | |
"9215 -0.801595 -0.833486 -0.921330 ... \n", | |
"9216 -0.856968 -0.907003 -0.922066 ... \n", | |
"\n", | |
" fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) \\\n", | |
"0 -0.710304 -0.112754 \n", | |
"1 -0.861499 0.053477 \n", | |
"2 -0.760104 -0.118559 \n", | |
"3 -0.482845 -0.036788 \n", | |
"4 -0.699205 0.123320 \n", | |
"... ... ... \n", | |
"9212 -0.587673 -0.013873 \n", | |
"9213 -0.534130 0.001598 \n", | |
"9214 -0.734724 0.049755 \n", | |
"9215 -0.807478 -0.072195 \n", | |
"9216 -0.388797 -0.006762 \n", | |
"\n", | |
" angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) \\\n", | |
"0 0.030400 -0.464761 \n", | |
"1 -0.007435 -0.732626 \n", | |
"2 0.177899 0.100699 \n", | |
"3 -0.012892 0.640011 \n", | |
"4 0.122542 0.693578 \n", | |
"... ... ... \n", | |
"9212 0.023064 -0.678024 \n", | |
"9213 0.214234 -0.757211 \n", | |
"9214 -0.083072 -0.566907 \n", | |
"9215 -0.095446 -0.606008 \n", | |
"9216 0.096378 0.827367 \n", | |
"\n", | |
" angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) \\\n", | |
"0 -0.018446 -0.841247 \n", | |
"1 0.703511 -0.844788 \n", | |
"2 0.808529 -0.848933 \n", | |
"3 -0.485366 -0.848649 \n", | |
"4 -0.615971 -0.847865 \n", | |
"... ... ... \n", | |
"9212 0.554907 -0.830144 \n", | |
"9213 -0.858485 -0.833311 \n", | |
"9214 -0.890635 -0.838057 \n", | |
"9215 0.904715 -0.851110 \n", | |
"9216 0.828512 -0.848590 \n", | |
"\n", | |
" angle(Y,gravityMean) angle(Z,gravityMean) subject Activity \n", | |
"0 0.179941 -0.058627 1 STANDING \n", | |
"1 0.180289 -0.054317 1 STANDING \n", | |
"2 0.180637 -0.049118 1 STANDING \n", | |
"3 0.181935 -0.047663 1 STANDING \n", | |
"4 0.185151 -0.043892 1 STANDING \n", | |
"... ... ... ... ... \n", | |
"9212 0.202810 -0.037548 18 STANDING \n", | |
"9213 0.199265 -0.039705 18 STANDING \n", | |
"9214 0.194527 -0.041538 18 STANDING \n", | |
"9215 0.186154 -0.037937 18 STANDING \n", | |
"9216 0.188972 -0.036494 18 STANDING \n", | |
"\n", | |
"[9217 rows x 563 columns]" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Претроцесирање " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Справување со вредности кои недостасуваат" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Отстранување на вредностите кои недостасуваат" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"activity_recognition_no_nan = activity_recognition.dropna()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>tBodyAcc-mean()-X</th>\n", | |
" <th>tBodyAcc-mean()-Y</th>\n", | |
" <th>tBodyAcc-mean()-Z</th>\n", | |
" <th>tBodyAcc-std()-X</th>\n", | |
" <th>tBodyAcc-std()-Y</th>\n", | |
" <th>tBodyAcc-std()-Z</th>\n", | |
" <th>tBodyAcc-mad()-X</th>\n", | |
" <th>tBodyAcc-mad()-Y</th>\n", | |
" <th>tBodyAcc-mad()-Z</th>\n", | |
" <th>tBodyAcc-max()-X</th>\n", | |
" <th>...</th>\n", | |
" <th>fBodyBodyGyroJerkMag-kurtosis()</th>\n", | |
" <th>angle(tBodyAccMean,gravity)</th>\n", | |
" <th>angle(tBodyAccJerkMean),gravityMean)</th>\n", | |
" <th>angle(tBodyGyroMean,gravityMean)</th>\n", | |
" <th>angle(tBodyGyroJerkMean,gravityMean)</th>\n", | |
" <th>angle(X,gravityMean)</th>\n", | |
" <th>angle(Y,gravityMean)</th>\n", | |
" <th>angle(Z,gravityMean)</th>\n", | |
" <th>subject</th>\n", | |
" <th>Activity</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0.288585</td>\n", | |
" <td>-0.020294</td>\n", | |
" <td>2.000000</td>\n", | |
" <td>-0.995279</td>\n", | |
" <td>-0.983111</td>\n", | |
" <td>-0.913526</td>\n", | |
" <td>-0.995112</td>\n", | |
" <td>-0.983185</td>\n", | |
" <td>-0.923527</td>\n", | |
" <td>-0.934724</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.710304</td>\n", | |
" <td>-0.112754</td>\n", | |
" <td>0.030400</td>\n", | |
" <td>-0.464761</td>\n", | |
" <td>-0.018446</td>\n", | |
" <td>-0.841247</td>\n", | |
" <td>0.179941</td>\n", | |
" <td>-0.058627</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0.276629</td>\n", | |
" <td>-0.016570</td>\n", | |
" <td>-0.115362</td>\n", | |
" <td>-0.998139</td>\n", | |
" <td>-0.980817</td>\n", | |
" <td>-0.990482</td>\n", | |
" <td>-0.998321</td>\n", | |
" <td>-0.979672</td>\n", | |
" <td>-0.990441</td>\n", | |
" <td>-0.942469</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.699205</td>\n", | |
" <td>0.123320</td>\n", | |
" <td>0.122542</td>\n", | |
" <td>0.693578</td>\n", | |
" <td>-0.615971</td>\n", | |
" <td>-0.847865</td>\n", | |
" <td>0.185151</td>\n", | |
" <td>-0.043892</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>0.277432</td>\n", | |
" <td>-0.030488</td>\n", | |
" <td>-0.125360</td>\n", | |
" <td>-0.996559</td>\n", | |
" <td>-0.966728</td>\n", | |
" <td>-0.981585</td>\n", | |
" <td>-0.996485</td>\n", | |
" <td>-0.966313</td>\n", | |
" <td>-0.982982</td>\n", | |
" <td>-0.940987</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.421715</td>\n", | |
" <td>-0.020888</td>\n", | |
" <td>0.593996</td>\n", | |
" <td>-0.561871</td>\n", | |
" <td>0.467383</td>\n", | |
" <td>-0.851017</td>\n", | |
" <td>0.183779</td>\n", | |
" <td>-0.041976</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>0.277293</td>\n", | |
" <td>-0.021751</td>\n", | |
" <td>-0.120751</td>\n", | |
" <td>-0.997328</td>\n", | |
" <td>-0.961245</td>\n", | |
" <td>-0.983672</td>\n", | |
" <td>-0.997596</td>\n", | |
" <td>-0.957236</td>\n", | |
" <td>-0.984379</td>\n", | |
" <td>-0.940598</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.572995</td>\n", | |
" <td>0.012954</td>\n", | |
" <td>0.080936</td>\n", | |
" <td>-0.234313</td>\n", | |
" <td>0.117797</td>\n", | |
" <td>-0.847971</td>\n", | |
" <td>0.188982</td>\n", | |
" <td>-0.037364</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>0.276880</td>\n", | |
" <td>-0.012722</td>\n", | |
" <td>-0.103438</td>\n", | |
" <td>-0.994815</td>\n", | |
" <td>-0.973077</td>\n", | |
" <td>-0.985357</td>\n", | |
" <td>-0.995509</td>\n", | |
" <td>-0.973948</td>\n", | |
" <td>-0.985172</td>\n", | |
" <td>-0.940028</td>\n", | |
" <td>...</td>\n", | |
" <td>0.057682</td>\n", | |
" <td>0.080699</td>\n", | |
" <td>0.595791</td>\n", | |
" <td>-0.475802</td>\n", | |
" <td>0.115931</td>\n", | |
" <td>-0.851562</td>\n", | |
" <td>0.187609</td>\n", | |
" <td>-0.034681</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9212</th>\n", | |
" <td>0.280272</td>\n", | |
" <td>-0.009753</td>\n", | |
" <td>-0.101004</td>\n", | |
" <td>-0.990222</td>\n", | |
" <td>-0.936652</td>\n", | |
" <td>-0.917424</td>\n", | |
" <td>-0.991822</td>\n", | |
" <td>-0.931656</td>\n", | |
" <td>-0.915447</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.587673</td>\n", | |
" <td>-0.013873</td>\n", | |
" <td>0.023064</td>\n", | |
" <td>-0.678024</td>\n", | |
" <td>0.554907</td>\n", | |
" <td>-0.830144</td>\n", | |
" <td>0.202810</td>\n", | |
" <td>-0.037548</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9213</th>\n", | |
" <td>0.279837</td>\n", | |
" <td>-0.010076</td>\n", | |
" <td>-0.104020</td>\n", | |
" <td>-0.990730</td>\n", | |
" <td>-0.937395</td>\n", | |
" <td>-0.930183</td>\n", | |
" <td>-0.992462</td>\n", | |
" <td>-0.934817</td>\n", | |
" <td>-0.927397</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.534130</td>\n", | |
" <td>0.001598</td>\n", | |
" <td>0.214234</td>\n", | |
" <td>-0.757211</td>\n", | |
" <td>-0.858485</td>\n", | |
" <td>-0.833311</td>\n", | |
" <td>0.199265</td>\n", | |
" <td>-0.039705</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9214</th>\n", | |
" <td>0.284586</td>\n", | |
" <td>0.009560</td>\n", | |
" <td>-0.127466</td>\n", | |
" <td>-0.987178</td>\n", | |
" <td>-0.907089</td>\n", | |
" <td>-0.869253</td>\n", | |
" <td>-0.988715</td>\n", | |
" <td>-0.900716</td>\n", | |
" <td>-0.860351</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.734724</td>\n", | |
" <td>0.049755</td>\n", | |
" <td>-0.083072</td>\n", | |
" <td>-0.566907</td>\n", | |
" <td>-0.890635</td>\n", | |
" <td>-0.838057</td>\n", | |
" <td>0.194527</td>\n", | |
" <td>-0.041538</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9215</th>\n", | |
" <td>0.278569</td>\n", | |
" <td>-0.019880</td>\n", | |
" <td>-0.113155</td>\n", | |
" <td>-0.978584</td>\n", | |
" <td>-0.816673</td>\n", | |
" <td>-0.840812</td>\n", | |
" <td>-0.981292</td>\n", | |
" <td>-0.801595</td>\n", | |
" <td>-0.833486</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.807478</td>\n", | |
" <td>-0.072195</td>\n", | |
" <td>-0.095446</td>\n", | |
" <td>-0.606008</td>\n", | |
" <td>0.904715</td>\n", | |
" <td>-0.851110</td>\n", | |
" <td>0.186154</td>\n", | |
" <td>-0.037937</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9216</th>\n", | |
" <td>0.269317</td>\n", | |
" <td>-0.036996</td>\n", | |
" <td>-0.084908</td>\n", | |
" <td>-0.984239</td>\n", | |
" <td>-0.856710</td>\n", | |
" <td>-0.915329</td>\n", | |
" <td>-0.987352</td>\n", | |
" <td>-0.856968</td>\n", | |
" <td>-0.907003</td>\n", | |
" <td>-0.922066</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.388797</td>\n", | |
" <td>-0.006762</td>\n", | |
" <td>0.096378</td>\n", | |
" <td>0.827367</td>\n", | |
" <td>0.828512</td>\n", | |
" <td>-0.848590</td>\n", | |
" <td>0.188972</td>\n", | |
" <td>-0.036494</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>9205 rows × 563 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z \\\n", | |
"0 0.288585 -0.020294 2.000000 \n", | |
"4 0.276629 -0.016570 -0.115362 \n", | |
"7 0.277432 -0.030488 -0.125360 \n", | |
"8 0.277293 -0.021751 -0.120751 \n", | |
"10 0.276880 -0.012722 -0.103438 \n", | |
"... ... ... ... \n", | |
"9212 0.280272 -0.009753 -0.101004 \n", | |
"9213 0.279837 -0.010076 -0.104020 \n", | |
"9214 0.284586 0.009560 -0.127466 \n", | |
"9215 0.278569 -0.019880 -0.113155 \n", | |
"9216 0.269317 -0.036996 -0.084908 \n", | |
"\n", | |
" tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X \\\n", | |
"0 -0.995279 -0.983111 -0.913526 -0.995112 \n", | |
"4 -0.998139 -0.980817 -0.990482 -0.998321 \n", | |
"7 -0.996559 -0.966728 -0.981585 -0.996485 \n", | |
"8 -0.997328 -0.961245 -0.983672 -0.997596 \n", | |
"10 -0.994815 -0.973077 -0.985357 -0.995509 \n", | |
"... ... ... ... ... \n", | |
"9212 -0.990222 -0.936652 -0.917424 -0.991822 \n", | |
"9213 -0.990730 -0.937395 -0.930183 -0.992462 \n", | |
"9214 -0.987178 -0.907089 -0.869253 -0.988715 \n", | |
"9215 -0.978584 -0.816673 -0.840812 -0.981292 \n", | |
"9216 -0.984239 -0.856710 -0.915329 -0.987352 \n", | |
"\n", | |
" tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... \\\n", | |
"0 -0.983185 -0.923527 -0.934724 ... \n", | |
"4 -0.979672 -0.990441 -0.942469 ... \n", | |
"7 -0.966313 -0.982982 -0.940987 ... \n", | |
"8 -0.957236 -0.984379 -0.940598 ... \n", | |
"10 -0.973948 -0.985172 -0.940028 ... \n", | |
"... ... ... ... ... \n", | |
"9212 -0.931656 -0.915447 -0.926574 ... \n", | |
"9213 -0.934817 -0.927397 -0.926574 ... \n", | |
"9214 -0.900716 -0.860351 -0.921330 ... \n", | |
"9215 -0.801595 -0.833486 -0.921330 ... \n", | |
"9216 -0.856968 -0.907003 -0.922066 ... \n", | |
"\n", | |
" fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) \\\n", | |
"0 -0.710304 -0.112754 \n", | |
"4 -0.699205 0.123320 \n", | |
"7 -0.421715 -0.020888 \n", | |
"8 -0.572995 0.012954 \n", | |
"10 0.057682 0.080699 \n", | |
"... ... ... \n", | |
"9212 -0.587673 -0.013873 \n", | |
"9213 -0.534130 0.001598 \n", | |
"9214 -0.734724 0.049755 \n", | |
"9215 -0.807478 -0.072195 \n", | |
"9216 -0.388797 -0.006762 \n", | |
"\n", | |
" angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) \\\n", | |
"0 0.030400 -0.464761 \n", | |
"4 0.122542 0.693578 \n", | |
"7 0.593996 -0.561871 \n", | |
"8 0.080936 -0.234313 \n", | |
"10 0.595791 -0.475802 \n", | |
"... ... ... \n", | |
"9212 0.023064 -0.678024 \n", | |
"9213 0.214234 -0.757211 \n", | |
"9214 -0.083072 -0.566907 \n", | |
"9215 -0.095446 -0.606008 \n", | |
"9216 0.096378 0.827367 \n", | |
"\n", | |
" angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) \\\n", | |
"0 -0.018446 -0.841247 \n", | |
"4 -0.615971 -0.847865 \n", | |
"7 0.467383 -0.851017 \n", | |
"8 0.117797 -0.847971 \n", | |
"10 0.115931 -0.851562 \n", | |
"... ... ... \n", | |
"9212 0.554907 -0.830144 \n", | |
"9213 -0.858485 -0.833311 \n", | |
"9214 -0.890635 -0.838057 \n", | |
"9215 0.904715 -0.851110 \n", | |
"9216 0.828512 -0.848590 \n", | |
"\n", | |
" angle(Y,gravityMean) angle(Z,gravityMean) subject Activity \n", | |
"0 0.179941 -0.058627 1 STANDING \n", | |
"4 0.185151 -0.043892 1 STANDING \n", | |
"7 0.183779 -0.041976 1 STANDING \n", | |
"8 0.188982 -0.037364 1 STANDING \n", | |
"10 0.187609 -0.034681 1 STANDING \n", | |
"... ... ... ... ... \n", | |
"9212 0.202810 -0.037548 18 STANDING \n", | |
"9213 0.199265 -0.039705 18 STANDING \n", | |
"9214 0.194527 -0.041538 18 STANDING \n", | |
"9215 0.186154 -0.037937 18 STANDING \n", | |
"9216 0.188972 -0.036494 18 STANDING \n", | |
"\n", | |
"[9205 rows x 563 columns]" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_no_nan" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>tBodyAcc-mean()-X</th>\n", | |
" <th>tBodyAcc-mean()-Y</th>\n", | |
" <th>tBodyAcc-mean()-Z</th>\n", | |
" <th>tBodyAcc-std()-X</th>\n", | |
" <th>tBodyAcc-std()-Y</th>\n", | |
" <th>tBodyAcc-std()-Z</th>\n", | |
" <th>tBodyAcc-mad()-X</th>\n", | |
" <th>tBodyAcc-mad()-Y</th>\n", | |
" <th>tBodyAcc-mad()-Z</th>\n", | |
" <th>tBodyAcc-max()-X</th>\n", | |
" <th>...</th>\n", | |
" <th>fBodyBodyGyroJerkMag-kurtosis()</th>\n", | |
" <th>angle(tBodyAccMean,gravity)</th>\n", | |
" <th>angle(tBodyAccJerkMean),gravityMean)</th>\n", | |
" <th>angle(tBodyGyroMean,gravityMean)</th>\n", | |
" <th>angle(tBodyGyroJerkMean,gravityMean)</th>\n", | |
" <th>angle(X,gravityMean)</th>\n", | |
" <th>angle(Y,gravityMean)</th>\n", | |
" <th>angle(Z,gravityMean)</th>\n", | |
" <th>subject</th>\n", | |
" <th>Activity</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0.288585</td>\n", | |
" <td>-0.020294</td>\n", | |
" <td>2.000000</td>\n", | |
" <td>-0.995279</td>\n", | |
" <td>-0.983111</td>\n", | |
" <td>-0.913526</td>\n", | |
" <td>-0.995112</td>\n", | |
" <td>-0.983185</td>\n", | |
" <td>-0.923527</td>\n", | |
" <td>-0.934724</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.710304</td>\n", | |
" <td>-0.112754</td>\n", | |
" <td>0.030400</td>\n", | |
" <td>-0.464761</td>\n", | |
" <td>-0.018446</td>\n", | |
" <td>-0.841247</td>\n", | |
" <td>0.179941</td>\n", | |
" <td>-0.058627</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0.276629</td>\n", | |
" <td>-0.016570</td>\n", | |
" <td>-0.115362</td>\n", | |
" <td>-0.998139</td>\n", | |
" <td>-0.980817</td>\n", | |
" <td>-0.990482</td>\n", | |
" <td>-0.998321</td>\n", | |
" <td>-0.979672</td>\n", | |
" <td>-0.990441</td>\n", | |
" <td>-0.942469</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.699205</td>\n", | |
" <td>0.123320</td>\n", | |
" <td>0.122542</td>\n", | |
" <td>0.693578</td>\n", | |
" <td>-0.615971</td>\n", | |
" <td>-0.847865</td>\n", | |
" <td>0.185151</td>\n", | |
" <td>-0.043892</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0.277432</td>\n", | |
" <td>-0.030488</td>\n", | |
" <td>-0.125360</td>\n", | |
" <td>-0.996559</td>\n", | |
" <td>-0.966728</td>\n", | |
" <td>-0.981585</td>\n", | |
" <td>-0.996485</td>\n", | |
" <td>-0.966313</td>\n", | |
" <td>-0.982982</td>\n", | |
" <td>-0.940987</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.421715</td>\n", | |
" <td>-0.020888</td>\n", | |
" <td>0.593996</td>\n", | |
" <td>-0.561871</td>\n", | |
" <td>0.467383</td>\n", | |
" <td>-0.851017</td>\n", | |
" <td>0.183779</td>\n", | |
" <td>-0.041976</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0.277293</td>\n", | |
" <td>-0.021751</td>\n", | |
" <td>-0.120751</td>\n", | |
" <td>-0.997328</td>\n", | |
" <td>-0.961245</td>\n", | |
" <td>-0.983672</td>\n", | |
" <td>-0.997596</td>\n", | |
" <td>-0.957236</td>\n", | |
" <td>-0.984379</td>\n", | |
" <td>-0.940598</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.572995</td>\n", | |
" <td>0.012954</td>\n", | |
" <td>0.080936</td>\n", | |
" <td>-0.234313</td>\n", | |
" <td>0.117797</td>\n", | |
" <td>-0.847971</td>\n", | |
" <td>0.188982</td>\n", | |
" <td>-0.037364</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0.276880</td>\n", | |
" <td>-0.012722</td>\n", | |
" <td>-0.103438</td>\n", | |
" <td>-0.994815</td>\n", | |
" <td>-0.973077</td>\n", | |
" <td>-0.985357</td>\n", | |
" <td>-0.995509</td>\n", | |
" <td>-0.973948</td>\n", | |
" <td>-0.985172</td>\n", | |
" <td>-0.940028</td>\n", | |
" <td>...</td>\n", | |
" <td>0.057682</td>\n", | |
" <td>0.080699</td>\n", | |
" <td>0.595791</td>\n", | |
" <td>-0.475802</td>\n", | |
" <td>0.115931</td>\n", | |
" <td>-0.851562</td>\n", | |
" <td>0.187609</td>\n", | |
" <td>-0.034681</td>\n", | |
" <td>1</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9200</th>\n", | |
" <td>0.280272</td>\n", | |
" <td>-0.009753</td>\n", | |
" <td>-0.101004</td>\n", | |
" <td>-0.990222</td>\n", | |
" <td>-0.936652</td>\n", | |
" <td>-0.917424</td>\n", | |
" <td>-0.991822</td>\n", | |
" <td>-0.931656</td>\n", | |
" <td>-0.915447</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.587673</td>\n", | |
" <td>-0.013873</td>\n", | |
" <td>0.023064</td>\n", | |
" <td>-0.678024</td>\n", | |
" <td>0.554907</td>\n", | |
" <td>-0.830144</td>\n", | |
" <td>0.202810</td>\n", | |
" <td>-0.037548</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9201</th>\n", | |
" <td>0.279837</td>\n", | |
" <td>-0.010076</td>\n", | |
" <td>-0.104020</td>\n", | |
" <td>-0.990730</td>\n", | |
" <td>-0.937395</td>\n", | |
" <td>-0.930183</td>\n", | |
" <td>-0.992462</td>\n", | |
" <td>-0.934817</td>\n", | |
" <td>-0.927397</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.534130</td>\n", | |
" <td>0.001598</td>\n", | |
" <td>0.214234</td>\n", | |
" <td>-0.757211</td>\n", | |
" <td>-0.858485</td>\n", | |
" <td>-0.833311</td>\n", | |
" <td>0.199265</td>\n", | |
" <td>-0.039705</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9202</th>\n", | |
" <td>0.284586</td>\n", | |
" <td>0.009560</td>\n", | |
" <td>-0.127466</td>\n", | |
" <td>-0.987178</td>\n", | |
" <td>-0.907089</td>\n", | |
" <td>-0.869253</td>\n", | |
" <td>-0.988715</td>\n", | |
" <td>-0.900716</td>\n", | |
" <td>-0.860351</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.734724</td>\n", | |
" <td>0.049755</td>\n", | |
" <td>-0.083072</td>\n", | |
" <td>-0.566907</td>\n", | |
" <td>-0.890635</td>\n", | |
" <td>-0.838057</td>\n", | |
" <td>0.194527</td>\n", | |
" <td>-0.041538</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9203</th>\n", | |
" <td>0.278569</td>\n", | |
" <td>-0.019880</td>\n", | |
" <td>-0.113155</td>\n", | |
" <td>-0.978584</td>\n", | |
" <td>-0.816673</td>\n", | |
" <td>-0.840812</td>\n", | |
" <td>-0.981292</td>\n", | |
" <td>-0.801595</td>\n", | |
" <td>-0.833486</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.807478</td>\n", | |
" <td>-0.072195</td>\n", | |
" <td>-0.095446</td>\n", | |
" <td>-0.606008</td>\n", | |
" <td>0.904715</td>\n", | |
" <td>-0.851110</td>\n", | |
" <td>0.186154</td>\n", | |
" <td>-0.037937</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9204</th>\n", | |
" <td>0.269317</td>\n", | |
" <td>-0.036996</td>\n", | |
" <td>-0.084908</td>\n", | |
" <td>-0.984239</td>\n", | |
" <td>-0.856710</td>\n", | |
" <td>-0.915329</td>\n", | |
" <td>-0.987352</td>\n", | |
" <td>-0.856968</td>\n", | |
" <td>-0.907003</td>\n", | |
" <td>-0.922066</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.388797</td>\n", | |
" <td>-0.006762</td>\n", | |
" <td>0.096378</td>\n", | |
" <td>0.827367</td>\n", | |
" <td>0.828512</td>\n", | |
" <td>-0.848590</td>\n", | |
" <td>0.188972</td>\n", | |
" <td>-0.036494</td>\n", | |
" <td>18</td>\n", | |
" <td>STANDING</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>9205 rows × 563 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z \\\n", | |
"0 0.288585 -0.020294 2.000000 \n", | |
"1 0.276629 -0.016570 -0.115362 \n", | |
"2 0.277432 -0.030488 -0.125360 \n", | |
"3 0.277293 -0.021751 -0.120751 \n", | |
"4 0.276880 -0.012722 -0.103438 \n", | |
"... ... ... ... \n", | |
"9200 0.280272 -0.009753 -0.101004 \n", | |
"9201 0.279837 -0.010076 -0.104020 \n", | |
"9202 0.284586 0.009560 -0.127466 \n", | |
"9203 0.278569 -0.019880 -0.113155 \n", | |
"9204 0.269317 -0.036996 -0.084908 \n", | |
"\n", | |
" tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X \\\n", | |
"0 -0.995279 -0.983111 -0.913526 -0.995112 \n", | |
"1 -0.998139 -0.980817 -0.990482 -0.998321 \n", | |
"2 -0.996559 -0.966728 -0.981585 -0.996485 \n", | |
"3 -0.997328 -0.961245 -0.983672 -0.997596 \n", | |
"4 -0.994815 -0.973077 -0.985357 -0.995509 \n", | |
"... ... ... ... ... \n", | |
"9200 -0.990222 -0.936652 -0.917424 -0.991822 \n", | |
"9201 -0.990730 -0.937395 -0.930183 -0.992462 \n", | |
"9202 -0.987178 -0.907089 -0.869253 -0.988715 \n", | |
"9203 -0.978584 -0.816673 -0.840812 -0.981292 \n", | |
"9204 -0.984239 -0.856710 -0.915329 -0.987352 \n", | |
"\n", | |
" tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... \\\n", | |
"0 -0.983185 -0.923527 -0.934724 ... \n", | |
"1 -0.979672 -0.990441 -0.942469 ... \n", | |
"2 -0.966313 -0.982982 -0.940987 ... \n", | |
"3 -0.957236 -0.984379 -0.940598 ... \n", | |
"4 -0.973948 -0.985172 -0.940028 ... \n", | |
"... ... ... ... ... \n", | |
"9200 -0.931656 -0.915447 -0.926574 ... \n", | |
"9201 -0.934817 -0.927397 -0.926574 ... \n", | |
"9202 -0.900716 -0.860351 -0.921330 ... \n", | |
"9203 -0.801595 -0.833486 -0.921330 ... \n", | |
"9204 -0.856968 -0.907003 -0.922066 ... \n", | |
"\n", | |
" fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) \\\n", | |
"0 -0.710304 -0.112754 \n", | |
"1 -0.699205 0.123320 \n", | |
"2 -0.421715 -0.020888 \n", | |
"3 -0.572995 0.012954 \n", | |
"4 0.057682 0.080699 \n", | |
"... ... ... \n", | |
"9200 -0.587673 -0.013873 \n", | |
"9201 -0.534130 0.001598 \n", | |
"9202 -0.734724 0.049755 \n", | |
"9203 -0.807478 -0.072195 \n", | |
"9204 -0.388797 -0.006762 \n", | |
"\n", | |
" angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) \\\n", | |
"0 0.030400 -0.464761 \n", | |
"1 0.122542 0.693578 \n", | |
"2 0.593996 -0.561871 \n", | |
"3 0.080936 -0.234313 \n", | |
"4 0.595791 -0.475802 \n", | |
"... ... ... \n", | |
"9200 0.023064 -0.678024 \n", | |
"9201 0.214234 -0.757211 \n", | |
"9202 -0.083072 -0.566907 \n", | |
"9203 -0.095446 -0.606008 \n", | |
"9204 0.096378 0.827367 \n", | |
"\n", | |
" angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) \\\n", | |
"0 -0.018446 -0.841247 \n", | |
"1 -0.615971 -0.847865 \n", | |
"2 0.467383 -0.851017 \n", | |
"3 0.117797 -0.847971 \n", | |
"4 0.115931 -0.851562 \n", | |
"... ... ... \n", | |
"9200 0.554907 -0.830144 \n", | |
"9201 -0.858485 -0.833311 \n", | |
"9202 -0.890635 -0.838057 \n", | |
"9203 0.904715 -0.851110 \n", | |
"9204 0.828512 -0.848590 \n", | |
"\n", | |
" angle(Y,gravityMean) angle(Z,gravityMean) subject Activity \n", | |
"0 0.179941 -0.058627 1 STANDING \n", | |
"1 0.185151 -0.043892 1 STANDING \n", | |
"2 0.183779 -0.041976 1 STANDING \n", | |
"3 0.188982 -0.037364 1 STANDING \n", | |
"4 0.187609 -0.034681 1 STANDING \n", | |
"... ... ... ... ... \n", | |
"9200 0.202810 -0.037548 18 STANDING \n", | |
"9201 0.199265 -0.039705 18 STANDING \n", | |
"9202 0.194527 -0.041538 18 STANDING \n", | |
"9203 0.186154 -0.037937 18 STANDING \n", | |
"9204 0.188972 -0.036494 18 STANDING \n", | |
"\n", | |
"[9205 rows x 563 columns]" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_no_nan = activity_recognition_no_nan.reset_index(drop=True)\n", | |
"activity_recognition_no_nan" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Отстранување (само) на класни атрибути кои недоставуваат" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"nan_class = []\n", | |
"for i in range(len(activity_recognition)):\n", | |
" row = activity_recognition.iloc[i]\n", | |
" if pd.isna(row['Activity']):\n", | |
" nan_class.append(i)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[18]" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"nan_class" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"activity_no_null_class = activity_recognition.drop(nan_class)\n", | |
"activity_no_null_class = activity_no_null_class.reset_index(drop=True)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Заменување на вредностите кои недостасуваат со средната вредност за колоната во која се наоѓа вредноста која недостасува. За пополнување на ваквите вредности може да се користи и медијаната или модата на колоната, или пак некоја константна вредност." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"SimpleImputer кога како стратегија за пополнување се користи средната вредност работи само со нумерички вредности. Затоа следнит повик нема да биде успешен." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ValueError", | |
"evalue": "Cannot use mean strategy with non-numeric data:\ncould not convert string to float: 'STANDING'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-10-9d444bd280cc>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mimp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mSimpleImputer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmissing_values\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnan\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstrategy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'mean'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mimp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mactivity_no_null_class\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\impute\\_base.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, X, y)\u001b[0m\n\u001b[0;32m 266\u001b[0m \u001b[0mself\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mSimpleImputer\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 267\u001b[0m \"\"\"\n\u001b[1;32m--> 268\u001b[1;33m \u001b[0mX\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 269\u001b[0m \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fit_indicator\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 270\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\impute\\_base.py\u001b[0m in \u001b[0;36m_validate_input\u001b[1;34m(self, X)\u001b[0m\n\u001b[0;32m 238\u001b[0m new_ve = ValueError(\"Cannot use {} strategy with non-numeric \"\n\u001b[0;32m 239\u001b[0m \"data:\\n{}\".format(self.strategy, ve))\n\u001b[1;32m--> 240\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mnew_ve\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 241\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 242\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mve\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;31mValueError\u001b[0m: Cannot use mean strategy with non-numeric data:\ncould not convert string to float: 'STANDING'" | |
] | |
} | |
], | |
"source": [ | |
"imp = SimpleImputer(missing_values=np.nan, strategy='mean')\n", | |
"imp.fit(activity_no_null_class)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Тука класата е единствениот атрибут кој не е нумерички, па можеме да го поделиме множеството на X - атрибути кои се користат за класификација и Y - класниот атрибут." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"SimpleImputer(add_indicator=False, copy=True, fill_value=None,\n", | |
" missing_values=nan, strategy='mean', verbose=0)" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_X = activity_no_null_class.iloc[:,0:561]\n", | |
"activity_recognition_Y = activity_no_null_class.iloc[:,562]\n", | |
"\n", | |
"imp = SimpleImputer(missing_values=np.nan, strategy='mean')\n", | |
"imp.fit(activity_recognition_X)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>tBodyAcc-mean()-X</th>\n", | |
" <th>tBodyAcc-mean()-Y</th>\n", | |
" <th>tBodyAcc-mean()-Z</th>\n", | |
" <th>tBodyAcc-std()-X</th>\n", | |
" <th>tBodyAcc-std()-Y</th>\n", | |
" <th>tBodyAcc-std()-Z</th>\n", | |
" <th>tBodyAcc-mad()-X</th>\n", | |
" <th>tBodyAcc-mad()-Y</th>\n", | |
" <th>tBodyAcc-mad()-Z</th>\n", | |
" <th>tBodyAcc-max()-X</th>\n", | |
" <th>...</th>\n", | |
" <th>fBodyBodyGyroJerkMag-meanFreq()</th>\n", | |
" <th>fBodyBodyGyroJerkMag-skewness()</th>\n", | |
" <th>fBodyBodyGyroJerkMag-kurtosis()</th>\n", | |
" <th>angle(tBodyAccMean,gravity)</th>\n", | |
" <th>angle(tBodyAccJerkMean),gravityMean)</th>\n", | |
" <th>angle(tBodyGyroMean,gravityMean)</th>\n", | |
" <th>angle(tBodyGyroJerkMean,gravityMean)</th>\n", | |
" <th>angle(X,gravityMean)</th>\n", | |
" <th>angle(Y,gravityMean)</th>\n", | |
" <th>angle(Z,gravityMean)</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0.288585</td>\n", | |
" <td>-0.020294</td>\n", | |
" <td>2.000000</td>\n", | |
" <td>-0.995279</td>\n", | |
" <td>-0.983111</td>\n", | |
" <td>-0.913526</td>\n", | |
" <td>-0.995112</td>\n", | |
" <td>-0.983185</td>\n", | |
" <td>-0.923527</td>\n", | |
" <td>-0.934724</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.074323</td>\n", | |
" <td>-0.298676</td>\n", | |
" <td>-0.710304</td>\n", | |
" <td>-0.112754</td>\n", | |
" <td>0.030400</td>\n", | |
" <td>-0.464761</td>\n", | |
" <td>-0.018446</td>\n", | |
" <td>-0.841247</td>\n", | |
" <td>0.179941</td>\n", | |
" <td>-0.058627</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0.278419</td>\n", | |
" <td>-0.016411</td>\n", | |
" <td>NaN</td>\n", | |
" <td>-0.998245</td>\n", | |
" <td>-0.975300</td>\n", | |
" <td>-0.960322</td>\n", | |
" <td>-0.998807</td>\n", | |
" <td>-0.974914</td>\n", | |
" <td>-0.957686</td>\n", | |
" <td>-0.943068</td>\n", | |
" <td>...</td>\n", | |
" <td>0.158075</td>\n", | |
" <td>-0.595051</td>\n", | |
" <td>-0.861499</td>\n", | |
" <td>0.053477</td>\n", | |
" <td>-0.007435</td>\n", | |
" <td>-0.732626</td>\n", | |
" <td>0.703511</td>\n", | |
" <td>-0.844788</td>\n", | |
" <td>0.180289</td>\n", | |
" <td>-0.054317</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0.279653</td>\n", | |
" <td>NaN</td>\n", | |
" <td>-0.113462</td>\n", | |
" <td>-0.995380</td>\n", | |
" <td>-0.967187</td>\n", | |
" <td>-0.978944</td>\n", | |
" <td>-0.996520</td>\n", | |
" <td>-0.963668</td>\n", | |
" <td>-0.977469</td>\n", | |
" <td>-0.938692</td>\n", | |
" <td>...</td>\n", | |
" <td>0.414503</td>\n", | |
" <td>-0.390748</td>\n", | |
" <td>-0.760104</td>\n", | |
" <td>-0.118559</td>\n", | |
" <td>0.177899</td>\n", | |
" <td>0.100699</td>\n", | |
" <td>0.808529</td>\n", | |
" <td>-0.848933</td>\n", | |
" <td>0.180637</td>\n", | |
" <td>-0.049118</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0.279174</td>\n", | |
" <td>-0.026201</td>\n", | |
" <td>-0.123283</td>\n", | |
" <td>-0.996091</td>\n", | |
" <td>NaN</td>\n", | |
" <td>-0.990675</td>\n", | |
" <td>-0.997099</td>\n", | |
" <td>-0.982750</td>\n", | |
" <td>-0.989302</td>\n", | |
" <td>-0.938692</td>\n", | |
" <td>...</td>\n", | |
" <td>0.404573</td>\n", | |
" <td>-0.117290</td>\n", | |
" <td>-0.482845</td>\n", | |
" <td>-0.036788</td>\n", | |
" <td>-0.012892</td>\n", | |
" <td>0.640011</td>\n", | |
" <td>-0.485366</td>\n", | |
" <td>-0.848649</td>\n", | |
" <td>0.181935</td>\n", | |
" <td>-0.047663</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0.276629</td>\n", | |
" <td>-0.016570</td>\n", | |
" <td>-0.115362</td>\n", | |
" <td>-0.998139</td>\n", | |
" <td>-0.980817</td>\n", | |
" <td>-0.990482</td>\n", | |
" <td>-0.998321</td>\n", | |
" <td>-0.979672</td>\n", | |
" <td>-0.990441</td>\n", | |
" <td>-0.942469</td>\n", | |
" <td>...</td>\n", | |
" <td>0.087753</td>\n", | |
" <td>-0.351471</td>\n", | |
" <td>-0.699205</td>\n", | |
" <td>0.123320</td>\n", | |
" <td>0.122542</td>\n", | |
" <td>0.693578</td>\n", | |
" <td>-0.615971</td>\n", | |
" <td>-0.847865</td>\n", | |
" <td>0.185151</td>\n", | |
" <td>-0.043892</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9211</th>\n", | |
" <td>0.280272</td>\n", | |
" <td>-0.009753</td>\n", | |
" <td>-0.101004</td>\n", | |
" <td>-0.990222</td>\n", | |
" <td>-0.936652</td>\n", | |
" <td>-0.917424</td>\n", | |
" <td>-0.991822</td>\n", | |
" <td>-0.931656</td>\n", | |
" <td>-0.915447</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>0.007027</td>\n", | |
" <td>-0.248929</td>\n", | |
" <td>-0.587673</td>\n", | |
" <td>-0.013873</td>\n", | |
" <td>0.023064</td>\n", | |
" <td>-0.678024</td>\n", | |
" <td>0.554907</td>\n", | |
" <td>-0.830144</td>\n", | |
" <td>0.202810</td>\n", | |
" <td>-0.037548</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9212</th>\n", | |
" <td>0.279837</td>\n", | |
" <td>-0.010076</td>\n", | |
" <td>-0.104020</td>\n", | |
" <td>-0.990730</td>\n", | |
" <td>-0.937395</td>\n", | |
" <td>-0.930183</td>\n", | |
" <td>-0.992462</td>\n", | |
" <td>-0.934817</td>\n", | |
" <td>-0.927397</td>\n", | |
" <td>-0.926574</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.097033</td>\n", | |
" <td>-0.148461</td>\n", | |
" <td>-0.534130</td>\n", | |
" <td>0.001598</td>\n", | |
" <td>0.214234</td>\n", | |
" <td>-0.757211</td>\n", | |
" <td>-0.858485</td>\n", | |
" <td>-0.833311</td>\n", | |
" <td>0.199265</td>\n", | |
" <td>-0.039705</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9213</th>\n", | |
" <td>0.284586</td>\n", | |
" <td>0.009560</td>\n", | |
" <td>-0.127466</td>\n", | |
" <td>-0.987178</td>\n", | |
" <td>-0.907089</td>\n", | |
" <td>-0.869253</td>\n", | |
" <td>-0.988715</td>\n", | |
" <td>-0.900716</td>\n", | |
" <td>-0.860351</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.113810</td>\n", | |
" <td>-0.372284</td>\n", | |
" <td>-0.734724</td>\n", | |
" <td>0.049755</td>\n", | |
" <td>-0.083072</td>\n", | |
" <td>-0.566907</td>\n", | |
" <td>-0.890635</td>\n", | |
" <td>-0.838057</td>\n", | |
" <td>0.194527</td>\n", | |
" <td>-0.041538</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9214</th>\n", | |
" <td>0.278569</td>\n", | |
" <td>-0.019880</td>\n", | |
" <td>-0.113155</td>\n", | |
" <td>-0.978584</td>\n", | |
" <td>-0.816673</td>\n", | |
" <td>-0.840812</td>\n", | |
" <td>-0.981292</td>\n", | |
" <td>-0.801595</td>\n", | |
" <td>-0.833486</td>\n", | |
" <td>-0.921330</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.270843</td>\n", | |
" <td>-0.467902</td>\n", | |
" <td>-0.807478</td>\n", | |
" <td>-0.072195</td>\n", | |
" <td>-0.095446</td>\n", | |
" <td>-0.606008</td>\n", | |
" <td>0.904715</td>\n", | |
" <td>-0.851110</td>\n", | |
" <td>0.186154</td>\n", | |
" <td>-0.037937</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9215</th>\n", | |
" <td>0.269317</td>\n", | |
" <td>-0.036996</td>\n", | |
" <td>-0.084908</td>\n", | |
" <td>-0.984239</td>\n", | |
" <td>-0.856710</td>\n", | |
" <td>-0.915329</td>\n", | |
" <td>-0.987352</td>\n", | |
" <td>-0.856968</td>\n", | |
" <td>-0.907003</td>\n", | |
" <td>-0.922066</td>\n", | |
" <td>...</td>\n", | |
" <td>-0.328289</td>\n", | |
" <td>0.008684</td>\n", | |
" <td>-0.388797</td>\n", | |
" <td>-0.006762</td>\n", | |
" <td>0.096378</td>\n", | |
" <td>0.827367</td>\n", | |
" <td>0.828512</td>\n", | |
" <td>-0.848590</td>\n", | |
" <td>0.188972</td>\n", | |
" <td>-0.036494</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>9216 rows × 561 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z \\\n", | |
"0 0.288585 -0.020294 2.000000 \n", | |
"1 0.278419 -0.016411 NaN \n", | |
"2 0.279653 NaN -0.113462 \n", | |
"3 0.279174 -0.026201 -0.123283 \n", | |
"4 0.276629 -0.016570 -0.115362 \n", | |
"... ... ... ... \n", | |
"9211 0.280272 -0.009753 -0.101004 \n", | |
"9212 0.279837 -0.010076 -0.104020 \n", | |
"9213 0.284586 0.009560 -0.127466 \n", | |
"9214 0.278569 -0.019880 -0.113155 \n", | |
"9215 0.269317 -0.036996 -0.084908 \n", | |
"\n", | |
" tBodyAcc-std()-X tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X \\\n", | |
"0 -0.995279 -0.983111 -0.913526 -0.995112 \n", | |
"1 -0.998245 -0.975300 -0.960322 -0.998807 \n", | |
"2 -0.995380 -0.967187 -0.978944 -0.996520 \n", | |
"3 -0.996091 NaN -0.990675 -0.997099 \n", | |
"4 -0.998139 -0.980817 -0.990482 -0.998321 \n", | |
"... ... ... ... ... \n", | |
"9211 -0.990222 -0.936652 -0.917424 -0.991822 \n", | |
"9212 -0.990730 -0.937395 -0.930183 -0.992462 \n", | |
"9213 -0.987178 -0.907089 -0.869253 -0.988715 \n", | |
"9214 -0.978584 -0.816673 -0.840812 -0.981292 \n", | |
"9215 -0.984239 -0.856710 -0.915329 -0.987352 \n", | |
"\n", | |
" tBodyAcc-mad()-Y tBodyAcc-mad()-Z tBodyAcc-max()-X ... \\\n", | |
"0 -0.983185 -0.923527 -0.934724 ... \n", | |
"1 -0.974914 -0.957686 -0.943068 ... \n", | |
"2 -0.963668 -0.977469 -0.938692 ... \n", | |
"3 -0.982750 -0.989302 -0.938692 ... \n", | |
"4 -0.979672 -0.990441 -0.942469 ... \n", | |
"... ... ... ... ... \n", | |
"9211 -0.931656 -0.915447 -0.926574 ... \n", | |
"9212 -0.934817 -0.927397 -0.926574 ... \n", | |
"9213 -0.900716 -0.860351 -0.921330 ... \n", | |
"9214 -0.801595 -0.833486 -0.921330 ... \n", | |
"9215 -0.856968 -0.907003 -0.922066 ... \n", | |
"\n", | |
" fBodyBodyGyroJerkMag-meanFreq() fBodyBodyGyroJerkMag-skewness() \\\n", | |
"0 -0.074323 -0.298676 \n", | |
"1 0.158075 -0.595051 \n", | |
"2 0.414503 -0.390748 \n", | |
"3 0.404573 -0.117290 \n", | |
"4 0.087753 -0.351471 \n", | |
"... ... ... \n", | |
"9211 0.007027 -0.248929 \n", | |
"9212 -0.097033 -0.148461 \n", | |
"9213 -0.113810 -0.372284 \n", | |
"9214 -0.270843 -0.467902 \n", | |
"9215 -0.328289 0.008684 \n", | |
"\n", | |
" fBodyBodyGyroJerkMag-kurtosis() angle(tBodyAccMean,gravity) \\\n", | |
"0 -0.710304 -0.112754 \n", | |
"1 -0.861499 0.053477 \n", | |
"2 -0.760104 -0.118559 \n", | |
"3 -0.482845 -0.036788 \n", | |
"4 -0.699205 0.123320 \n", | |
"... ... ... \n", | |
"9211 -0.587673 -0.013873 \n", | |
"9212 -0.534130 0.001598 \n", | |
"9213 -0.734724 0.049755 \n", | |
"9214 -0.807478 -0.072195 \n", | |
"9215 -0.388797 -0.006762 \n", | |
"\n", | |
" angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) \\\n", | |
"0 0.030400 -0.464761 \n", | |
"1 -0.007435 -0.732626 \n", | |
"2 0.177899 0.100699 \n", | |
"3 -0.012892 0.640011 \n", | |
"4 0.122542 0.693578 \n", | |
"... ... ... \n", | |
"9211 0.023064 -0.678024 \n", | |
"9212 0.214234 -0.757211 \n", | |
"9213 -0.083072 -0.566907 \n", | |
"9214 -0.095446 -0.606008 \n", | |
"9215 0.096378 0.827367 \n", | |
"\n", | |
" angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) \\\n", | |
"0 -0.018446 -0.841247 \n", | |
"1 0.703511 -0.844788 \n", | |
"2 0.808529 -0.848933 \n", | |
"3 -0.485366 -0.848649 \n", | |
"4 -0.615971 -0.847865 \n", | |
"... ... ... \n", | |
"9211 0.554907 -0.830144 \n", | |
"9212 -0.858485 -0.833311 \n", | |
"9213 -0.890635 -0.838057 \n", | |
"9214 0.904715 -0.851110 \n", | |
"9215 0.828512 -0.848590 \n", | |
"\n", | |
" angle(Y,gravityMean) angle(Z,gravityMean) \n", | |
"0 0.179941 -0.058627 \n", | |
"1 0.180289 -0.054317 \n", | |
"2 0.180637 -0.049118 \n", | |
"3 0.181935 -0.047663 \n", | |
"4 0.185151 -0.043892 \n", | |
"... ... ... \n", | |
"9211 0.202810 -0.037548 \n", | |
"9212 0.199265 -0.039705 \n", | |
"9213 0.194527 -0.041538 \n", | |
"9214 0.186154 -0.037937 \n", | |
"9215 0.188972 -0.036494 \n", | |
"\n", | |
"[9216 rows x 561 columns]" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_X" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0 STANDING\n", | |
"1 STANDING\n", | |
"2 STANDING\n", | |
"3 STANDING\n", | |
"4 STANDING\n", | |
" ... \n", | |
"9211 STANDING\n", | |
"9212 STANDING\n", | |
"9213 STANDING\n", | |
"9214 STANDING\n", | |
"9215 STANDING\n", | |
"Name: Activity, Length: 9216, dtype: object" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_Y" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 0.28858451, -0.02029417, 2. , ..., -0.84124676,\n", | |
" 0.17994061, -0.05862692],\n", | |
" [ 0.27841883, -0.01641057, -0.10880255, ..., -0.8447876 ,\n", | |
" 0.18028889, -0.05431672],\n", | |
" [ 0.27965306, -0.01777186, -0.11346169, ..., -0.84893347,\n", | |
" 0.18063731, -0.04911782],\n", | |
" ...,\n", | |
" [ 0.28458557, 0.0095602 , -0.12746582, ..., -0.83805746,\n", | |
" 0.19452695, -0.04153752],\n", | |
" [ 0.27856919, -0.01988 , -0.11315545, ..., -0.85111022,\n", | |
" 0.18615411, -0.03793675],\n", | |
" [ 0.26931702, -0.0369961 , -0.08490836, ..., -0.84859031,\n", | |
" 0.1889719 , -0.03649362]])" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_mean = imp.transform(activity_recognition_X)\n", | |
"activity_recognition_mean" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Друг начин за надополнување на вредностите кои недостасуваат нивна проценка користејќи ги останатите карактеристики во множеството. За проценка по defualt се користи Bayesian Ridge методот, но може да се внесе и друг, како и сопствен проценувач." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from sklearn.experimental import enable_iterative_imputer\n", | |
"from sklearn.impute import IterativeImputer" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Ова податочно множество содржи повеќе од 500 колони и доколку за проценка се користат сите овие, пресметката ќе трае значително долго. Затоа за проценка во слениот пример се користат само најблиските 10 карактеристики до онаа која се проценува." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"C:\\Users\\PC\\Anaconda3\\lib\\site-packages\\sklearn\\impute\\_iterative.py:638: ConvergenceWarning: [IterativeImputer] Early stopping criterion not reached.\n", | |
" \" reached.\", ConvergenceWarning)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"IterativeImputer(add_indicator=False, estimator=None,\n", | |
" imputation_order='ascending', initial_strategy='mean',\n", | |
" max_iter=10, max_value=None, min_value=None,\n", | |
" missing_values=nan, n_nearest_features=20, random_state=0,\n", | |
" sample_posterior=False, skip_complete=False, tol=0.001,\n", | |
" verbose=0)" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"imp_est = IterativeImputer(random_state=0, n_nearest_features=20)\n", | |
"imp_est.fit(activity_recognition_X)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 0.28858451, -0.02029417, 2. , ..., -0.84124676,\n", | |
" 0.17994061, -0.05862692],\n", | |
" [ 0.27841883, -0.01641057, -0.10506427, ..., -0.8447876 ,\n", | |
" 0.18028889, -0.05431672],\n", | |
" [ 0.27965306, -0.01656104, -0.11346169, ..., -0.84893347,\n", | |
" 0.18063731, -0.04911782],\n", | |
" ...,\n", | |
" [ 0.28458557, 0.0095602 , -0.12746582, ..., -0.83805746,\n", | |
" 0.19452695, -0.04153752],\n", | |
" [ 0.27856919, -0.01988 , -0.11315545, ..., -0.85111022,\n", | |
" 0.18615411, -0.03793675],\n", | |
" [ 0.26931702, -0.0369961 , -0.08490836, ..., -0.84859031,\n", | |
" 0.1889719 , -0.03649362]])" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"imp_est.transform(activity_recognition_X)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Справување со аутлаери" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 51, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"activity_recognition_fin_X = []\n", | |
"activity_recognition_fin_Y = []\n", | |
"for i in range(len(activity_recognition_mean)):\n", | |
" sample = activity_recognition_mean[i]\n", | |
" if all([x <= 1 and x >= -1 for x in sample]):\n", | |
" activity_recognition_fin_X.append(np.array(sample))\n", | |
" activity_recognition_fin_Y.append(activity_recognition_Y[i])\n", | |
"\n", | |
"activity_recognition_fin_X = np.array(activity_recognition_fin_X)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 0.27965306, -0.01777186, -0.11346169, ..., -0.84893347,\n", | |
" 0.18063731, -0.04911782],\n", | |
" [ 0.27917394, -0.02620065, -0.12328257, ..., -0.84864938,\n", | |
" 0.18193476, -0.04766318],\n", | |
" [ 0.27662877, -0.01656965, -0.11536185, ..., -0.84786525,\n", | |
" 0.18515116, -0.04389225],\n", | |
" ...,\n", | |
" [ 0.28458557, 0.0095602 , -0.12746582, ..., -0.83805746,\n", | |
" 0.19452695, -0.04153752],\n", | |
" [ 0.27856919, -0.01988 , -0.11315545, ..., -0.85111022,\n", | |
" 0.18615411, -0.03793675],\n", | |
" [ 0.26931702, -0.0369961 , -0.08490836, ..., -0.84859031,\n", | |
" 0.1889719 , -0.03649362]])" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"activity_recognition_fin_X" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name 'activity_recognition_mean' is not defined", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-16-aa107bb93a83>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mactivity_recognition_fin_X2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mactivity_recognition_fin_Y2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mactivity_recognition_mean\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0msample\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mactivity_recognition_mean\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msample\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;31mNameError\u001b[0m: name 'activity_recognition_mean' is not defined" | |
] | |
} | |
], | |
"source": [ | |
"activity_recognition_fin_X2 = []\n", | |
"activity_recognition_fin_Y2 = []\n", | |
"for i in range(len(activity_recognition_mean)):\n", | |
" sample = activity_recognition_mean[i]\n", | |
" for j in range(len(sample)):\n", | |
" if sample[j] < -1:\n", | |
" sample[j] = -1\n", | |
" if sample[j] > 1:\n", | |
" sample[j] = 1\n", | |
" activity_recognition_fin_X2.append(np.array(sample))\n", | |
" activity_recognition_fin_Y2.append(activity_recognition_Y[i])\n", | |
" \n", | |
"\n", | |
"activity_recognition_fin_X2 = np.array(activity_recognition_fin_X2)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Следното множество содржи податоци за детекција на падови. Во првите три колони се дадени х, у и z координатите на акселерометар, а колоната sensor кажува од кој сензор од четири можни позиции/сензори доаѓаат овие податови. Последната колона кажува дали во дадениот случај доаѓа до пад или не." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"fall_detection = pd.read_csv(\"fall_detection.csv\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" <th>anomaly</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>18.495860</td>\n", | |
" <td>13.766527</td>\n", | |
" <td>14.362624</td>\n", | |
" <td>CHEST</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>18.501072</td>\n", | |
" <td>13.827225</td>\n", | |
" <td>14.270268</td>\n", | |
" <td>BELT</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>18.405950</td>\n", | |
" <td>13.868976</td>\n", | |
" <td>14.094804</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>18.444572</td>\n", | |
" <td>13.910701</td>\n", | |
" <td>14.116078</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>18.418470</td>\n", | |
" <td>13.933917</td>\n", | |
" <td>14.320566</td>\n", | |
" <td>CHEST</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5800</th>\n", | |
" <td>13.071400</td>\n", | |
" <td>13.964593</td>\n", | |
" <td>14.014944</td>\n", | |
" <td>CHEST</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5801</th>\n", | |
" <td>13.170663</td>\n", | |
" <td>14.089759</td>\n", | |
" <td>13.972008</td>\n", | |
" <td>BELT</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5802</th>\n", | |
" <td>13.262426</td>\n", | |
" <td>14.129938</td>\n", | |
" <td>13.811263</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5803</th>\n", | |
" <td>13.282711</td>\n", | |
" <td>14.161534</td>\n", | |
" <td>13.781787</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5804</th>\n", | |
" <td>13.356316</td>\n", | |
" <td>14.236007</td>\n", | |
" <td>13.767518</td>\n", | |
" <td>CHEST</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>5805 rows × 5 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor anomaly\n", | |
"0 18.495860 13.766527 14.362624 CHEST 0\n", | |
"1 18.501072 13.827225 14.270268 BELT 0\n", | |
"2 18.405950 13.868976 14.094804 ANKLE_LEFT 0\n", | |
"3 18.444572 13.910701 14.116078 ANKLE_RIGHT 0\n", | |
"4 18.418470 13.933917 14.320566 CHEST 0\n", | |
"... ... ... ... ... ...\n", | |
"5800 13.071400 13.964593 14.014944 CHEST 0\n", | |
"5801 13.170663 14.089759 13.972008 BELT 0\n", | |
"5802 13.262426 14.129938 13.811263 ANKLE_LEFT 0\n", | |
"5803 13.282711 14.161534 13.781787 ANKLE_RIGHT 0\n", | |
"5804 13.356316 14.236007 13.767518 CHEST 0\n", | |
"\n", | |
"[5805 rows x 5 columns]" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fall_detection" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Енкодирање на кардинални податоци" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 54, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from sklearn.neural_network import MLPClassifier\n", | |
"from sklearn.model_selection import train_test_split\n", | |
"\n", | |
"clf = MLPClassifier(solver='lbfgs', hidden_layer_sizes=(5), random_state=1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"fd_X = fall_detection[[\"x\", \"y\", \"z\", \"sensor\"]]\n", | |
"fd_Y = fall_detection[\"anomaly\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>18.495860</td>\n", | |
" <td>13.766527</td>\n", | |
" <td>14.362624</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>18.501072</td>\n", | |
" <td>13.827225</td>\n", | |
" <td>14.270268</td>\n", | |
" <td>BELT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>18.405950</td>\n", | |
" <td>13.868976</td>\n", | |
" <td>14.094804</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>18.444572</td>\n", | |
" <td>13.910701</td>\n", | |
" <td>14.116078</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>18.418470</td>\n", | |
" <td>13.933917</td>\n", | |
" <td>14.320566</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5800</th>\n", | |
" <td>13.071400</td>\n", | |
" <td>13.964593</td>\n", | |
" <td>14.014944</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5801</th>\n", | |
" <td>13.170663</td>\n", | |
" <td>14.089759</td>\n", | |
" <td>13.972008</td>\n", | |
" <td>BELT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5802</th>\n", | |
" <td>13.262426</td>\n", | |
" <td>14.129938</td>\n", | |
" <td>13.811263</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5803</th>\n", | |
" <td>13.282711</td>\n", | |
" <td>14.161534</td>\n", | |
" <td>13.781787</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5804</th>\n", | |
" <td>13.356316</td>\n", | |
" <td>14.236007</td>\n", | |
" <td>13.767518</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>5805 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor\n", | |
"0 18.495860 13.766527 14.362624 CHEST\n", | |
"1 18.501072 13.827225 14.270268 BELT\n", | |
"2 18.405950 13.868976 14.094804 ANKLE_LEFT\n", | |
"3 18.444572 13.910701 14.116078 ANKLE_RIGHT\n", | |
"4 18.418470 13.933917 14.320566 CHEST\n", | |
"... ... ... ... ...\n", | |
"5800 13.071400 13.964593 14.014944 CHEST\n", | |
"5801 13.170663 14.089759 13.972008 BELT\n", | |
"5802 13.262426 14.129938 13.811263 ANKLE_LEFT\n", | |
"5803 13.282711 14.161534 13.781787 ANKLE_RIGHT\n", | |
"5804 13.356316 14.236007 13.767518 CHEST\n", | |
"\n", | |
"[5805 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 20, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fd_X" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0 0\n", | |
"1 0\n", | |
"2 0\n", | |
"3 0\n", | |
"4 0\n", | |
" ..\n", | |
"5800 0\n", | |
"5801 0\n", | |
"5802 0\n", | |
"5803 0\n", | |
"5804 0\n", | |
"Name: anomaly, Length: 5805, dtype: int64" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fd_Y" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 59, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train, X_test, y_train, y_test = train_test_split(fd_X, fd_Y, test_size=0.25, random_state=0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 60, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>4827</th>\n", | |
" <td>7.808919</td>\n", | |
" <td>17.462564</td>\n", | |
" <td>10.336258</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4402</th>\n", | |
" <td>8.445435</td>\n", | |
" <td>16.781792</td>\n", | |
" <td>10.883452</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4730</th>\n", | |
" <td>7.387962</td>\n", | |
" <td>17.363925</td>\n", | |
" <td>9.790423</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1165</th>\n", | |
" <td>17.509135</td>\n", | |
" <td>9.690588</td>\n", | |
" <td>11.311750</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4375</th>\n", | |
" <td>9.690485</td>\n", | |
" <td>16.312149</td>\n", | |
" <td>12.095406</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4931</th>\n", | |
" <td>7.293185</td>\n", | |
" <td>17.744339</td>\n", | |
" <td>10.781552</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3264</th>\n", | |
" <td>13.556494</td>\n", | |
" <td>9.316183</td>\n", | |
" <td>14.421283</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1653</th>\n", | |
" <td>7.537048</td>\n", | |
" <td>17.002989</td>\n", | |
" <td>12.532262</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2607</th>\n", | |
" <td>17.491765</td>\n", | |
" <td>10.302281</td>\n", | |
" <td>10.800121</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2732</th>\n", | |
" <td>17.690924</td>\n", | |
" <td>10.043395</td>\n", | |
" <td>10.868089</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor\n", | |
"4827 7.808919 17.462564 10.336258 ANKLE_LEFT\n", | |
"4402 8.445435 16.781792 10.883452 ANKLE_RIGHT\n", | |
"4730 7.387962 17.363925 9.790423 CHEST\n", | |
"1165 17.509135 9.690588 11.311750 ANKLE_RIGHT\n", | |
"4375 9.690485 16.312149 12.095406 ANKLE_LEFT\n", | |
"... ... ... ... ...\n", | |
"4931 7.293185 17.744339 10.781552 ANKLE_LEFT\n", | |
"3264 13.556494 9.316183 14.421283 CHEST\n", | |
"1653 7.537048 17.002989 12.532262 CHEST\n", | |
"2607 17.491765 10.302281 10.800121 ANKLE_LEFT\n", | |
"2732 17.690924 10.043395 10.868089 CHEST\n", | |
"\n", | |
"[4353 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 60, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 61, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>1519</th>\n", | |
" <td>6.601192</td>\n", | |
" <td>14.365410</td>\n", | |
" <td>12.600944</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4941</th>\n", | |
" <td>7.744365</td>\n", | |
" <td>17.222940</td>\n", | |
" <td>11.285024</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>895</th>\n", | |
" <td>17.913727</td>\n", | |
" <td>9.296171</td>\n", | |
" <td>11.592793</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5719</th>\n", | |
" <td>9.494855</td>\n", | |
" <td>11.607346</td>\n", | |
" <td>13.532999</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2033</th>\n", | |
" <td>8.342002</td>\n", | |
" <td>16.944162</td>\n", | |
" <td>12.657538</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2147</th>\n", | |
" <td>8.805084</td>\n", | |
" <td>12.887988</td>\n", | |
" <td>13.077178</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2664</th>\n", | |
" <td>17.525626</td>\n", | |
" <td>10.393603</td>\n", | |
" <td>10.759197</td>\n", | |
" <td>BELT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1075</th>\n", | |
" <td>17.766620</td>\n", | |
" <td>9.361600</td>\n", | |
" <td>12.332116</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2400</th>\n", | |
" <td>17.132786</td>\n", | |
" <td>10.406924</td>\n", | |
" <td>10.506890</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5330</th>\n", | |
" <td>8.655747</td>\n", | |
" <td>11.042521</td>\n", | |
" <td>11.338261</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1452 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor\n", | |
"1519 6.601192 14.365410 12.600944 CHEST\n", | |
"4941 7.744365 17.222940 11.285024 ANKLE_RIGHT\n", | |
"895 17.913727 9.296171 11.592793 ANKLE_LEFT\n", | |
"5719 9.494855 11.607346 13.532999 CHEST\n", | |
"2033 8.342002 16.944162 12.657538 ANKLE_RIGHT\n", | |
"... ... ... ... ...\n", | |
"2147 8.805084 12.887988 13.077178 ANKLE_LEFT\n", | |
"2664 17.525626 10.393603 10.759197 BELT\n", | |
"1075 17.766620 9.361600 12.332116 ANKLE_LEFT\n", | |
"2400 17.132786 10.406924 10.506890 ANKLE_LEFT\n", | |
"5330 8.655747 11.042521 11.338261 ANKLE_RIGHT\n", | |
"\n", | |
"[1452 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 61, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 62, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"4827 0\n", | |
"4402 0\n", | |
"4730 0\n", | |
"1165 0\n", | |
"4375 0\n", | |
" ..\n", | |
"4931 0\n", | |
"3264 0\n", | |
"1653 0\n", | |
"2607 0\n", | |
"2732 0\n", | |
"Name: anomaly, Length: 4353, dtype: int64" | |
] | |
}, | |
"execution_count": 62, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"y_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 63, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1519 0\n", | |
"4941 0\n", | |
"895 0\n", | |
"5719 0\n", | |
"2033 0\n", | |
" ..\n", | |
"2147 0\n", | |
"2664 0\n", | |
"1075 0\n", | |
"2400 0\n", | |
"5330 1\n", | |
"Name: anomaly, Length: 1452, dtype: int64" | |
] | |
}, | |
"execution_count": 63, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"y_test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 64, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ValueError", | |
"evalue": "could not convert string to float: 'ANKLE_LEFT'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-64-4f66baab8f93>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mclf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, X, y)\u001b[0m\n\u001b[0;32m 993\u001b[0m \"\"\"\n\u001b[0;32m 994\u001b[0m return self._fit(X, y, incremental=(self.warm_start and\n\u001b[1;32m--> 995\u001b[1;33m hasattr(self, \"classes_\")))\n\u001b[0m\u001b[0;32m 996\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 997\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mproperty\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py\u001b[0m in \u001b[0;36m_fit\u001b[1;34m(self, X, y, incremental)\u001b[0m\n\u001b[0;32m 323\u001b[0m hidden_layer_sizes)\n\u001b[0;32m 324\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 325\u001b[1;33m \u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mincremental\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 326\u001b[0m \u001b[0mn_samples\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mn_features\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 327\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py\u001b[0m in \u001b[0;36m_validate_input\u001b[1;34m(self, X, y, incremental)\u001b[0m\n\u001b[0;32m 930\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_validate_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mincremental\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 931\u001b[0m X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'],\n\u001b[1;32m--> 932\u001b[1;33m multi_output=True)\n\u001b[0m\u001b[0;32m 933\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m2\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 934\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcolumn_or_1d\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mwarn\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py\u001b[0m in \u001b[0;36mcheck_X_y\u001b[1;34m(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)\u001b[0m\n\u001b[0;32m 753\u001b[0m \u001b[0mensure_min_features\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mensure_min_features\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 754\u001b[0m \u001b[0mwarn_on_dtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mwarn_on_dtype\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 755\u001b[1;33m estimator=estimator)\n\u001b[0m\u001b[0;32m 756\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mmulti_output\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 757\u001b[0m y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,\n", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[1;34m(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\u001b[0m\n\u001b[0;32m 529\u001b[0m \u001b[0marray\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0marray\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcasting\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"unsafe\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 530\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 531\u001b[1;33m \u001b[0marray\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0masarray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0morder\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0morder\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 532\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mComplexWarning\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 533\u001b[0m raise ValueError(\"Complex data not supported\\n\"\n", | |
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\numpy\\core\\_asarray.py\u001b[0m in \u001b[0;36masarray\u001b[1;34m(a, dtype, order)\u001b[0m\n\u001b[0;32m 81\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 82\u001b[0m \"\"\"\n\u001b[1;32m---> 83\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0morder\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0morder\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 84\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 85\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;31mValueError\u001b[0m: could not convert string to float: 'ANKLE_LEFT'" | |
] | |
} | |
], | |
"source": [ | |
"clf.fit(X_train, y_train)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### One-Hot Encoder" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 65, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"OneHotEncoder(categories='auto', drop=None, dtype=<class 'numpy.float64'>,\n", | |
" handle_unknown='error', sparse=True)" | |
] | |
}, | |
"execution_count": 65, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"enc = preprocessing.OneHotEncoder()\n", | |
"categorical = X_train[[\"sensor\"]]\n", | |
"enc.fit(categorical)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 66, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[array(['ANKLE_LEFT', 'ANKLE_RIGHT', 'BELT', 'CHEST'], dtype=object)]" | |
] | |
}, | |
"execution_count": 66, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"enc.categories_" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 67, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"one_hot_enc = enc.transform(categorical).toarray()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 68, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>4827</th>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4402</th>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4730</th>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1165</th>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4375</th>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4931</th>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3264</th>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1653</th>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2607</th>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2732</th>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 1 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" sensor\n", | |
"4827 ANKLE_LEFT\n", | |
"4402 ANKLE_RIGHT\n", | |
"4730 CHEST\n", | |
"1165 ANKLE_RIGHT\n", | |
"4375 ANKLE_LEFT\n", | |
"... ...\n", | |
"4931 ANKLE_LEFT\n", | |
"3264 CHEST\n", | |
"1653 CHEST\n", | |
"2607 ANKLE_LEFT\n", | |
"2732 CHEST\n", | |
"\n", | |
"[4353 rows x 1 columns]" | |
] | |
}, | |
"execution_count": 68, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"categorical" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 69, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[1., 0., 0., 0.],\n", | |
" [0., 1., 0., 0.],\n", | |
" [0., 0., 0., 1.],\n", | |
" ...,\n", | |
" [0., 0., 0., 1.],\n", | |
" [1., 0., 0., 0.],\n", | |
" [0., 0., 0., 1.]])" | |
] | |
}, | |
"execution_count": 69, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"one_hot_enc" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 70, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>4827</th>\n", | |
" <td>7.808919</td>\n", | |
" <td>17.462564</td>\n", | |
" <td>10.336258</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4402</th>\n", | |
" <td>8.445435</td>\n", | |
" <td>16.781792</td>\n", | |
" <td>10.883452</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4730</th>\n", | |
" <td>7.387962</td>\n", | |
" <td>17.363925</td>\n", | |
" <td>9.790423</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1165</th>\n", | |
" <td>17.509135</td>\n", | |
" <td>9.690588</td>\n", | |
" <td>11.311750</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4375</th>\n", | |
" <td>9.690485</td>\n", | |
" <td>16.312149</td>\n", | |
" <td>12.095406</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4931</th>\n", | |
" <td>7.293185</td>\n", | |
" <td>17.744339</td>\n", | |
" <td>10.781552</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3264</th>\n", | |
" <td>13.556494</td>\n", | |
" <td>9.316183</td>\n", | |
" <td>14.421283</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1653</th>\n", | |
" <td>7.537048</td>\n", | |
" <td>17.002989</td>\n", | |
" <td>12.532262</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2607</th>\n", | |
" <td>17.491765</td>\n", | |
" <td>10.302281</td>\n", | |
" <td>10.800121</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2732</th>\n", | |
" <td>17.690924</td>\n", | |
" <td>10.043395</td>\n", | |
" <td>10.868089</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor\n", | |
"4827 7.808919 17.462564 10.336258 ANKLE_LEFT\n", | |
"4402 8.445435 16.781792 10.883452 ANKLE_RIGHT\n", | |
"4730 7.387962 17.363925 9.790423 CHEST\n", | |
"1165 17.509135 9.690588 11.311750 ANKLE_RIGHT\n", | |
"4375 9.690485 16.312149 12.095406 ANKLE_LEFT\n", | |
"... ... ... ... ...\n", | |
"4931 7.293185 17.744339 10.781552 ANKLE_LEFT\n", | |
"3264 13.556494 9.316183 14.421283 CHEST\n", | |
"1653 7.537048 17.002989 12.532262 CHEST\n", | |
"2607 17.491765 10.302281 10.800121 ANKLE_LEFT\n", | |
"2732 17.690924 10.043395 10.868089 CHEST\n", | |
"\n", | |
"[4353 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 70, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 71, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3\n", | |
"0 1.0 0.0 0.0 0.0\n", | |
"1 0.0 1.0 0.0 0.0\n", | |
"2 0.0 0.0 0.0 1.0\n", | |
"3 0.0 1.0 0.0 0.0\n", | |
"4 1.0 0.0 0.0 0.0\n", | |
"... ... ... ... ...\n", | |
"4348 1.0 0.0 0.0 0.0\n", | |
"4349 0.0 0.0 0.0 1.0\n", | |
"4350 0.0 0.0 0.0 1.0\n", | |
"4351 1.0 0.0 0.0 0.0\n", | |
"4352 0.0 0.0 0.0 1.0\n", | |
"\n", | |
"[4353 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 71, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pd.DataFrame(one_hot_enc)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 72, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train = X_train.reset_index(drop=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 73, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>7.808919</td>\n", | |
" <td>17.462564</td>\n", | |
" <td>10.336258</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>8.445435</td>\n", | |
" <td>16.781792</td>\n", | |
" <td>10.883452</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>7.387962</td>\n", | |
" <td>17.363925</td>\n", | |
" <td>9.790423</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>17.509135</td>\n", | |
" <td>9.690588</td>\n", | |
" <td>11.311750</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>9.690485</td>\n", | |
" <td>16.312149</td>\n", | |
" <td>12.095406</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>7.293185</td>\n", | |
" <td>17.744339</td>\n", | |
" <td>10.781552</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>13.556494</td>\n", | |
" <td>9.316183</td>\n", | |
" <td>14.421283</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>7.537048</td>\n", | |
" <td>17.002989</td>\n", | |
" <td>12.532262</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>17.491765</td>\n", | |
" <td>10.302281</td>\n", | |
" <td>10.800121</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>17.690924</td>\n", | |
" <td>10.043395</td>\n", | |
" <td>10.868089</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor\n", | |
"0 7.808919 17.462564 10.336258 ANKLE_LEFT\n", | |
"1 8.445435 16.781792 10.883452 ANKLE_RIGHT\n", | |
"2 7.387962 17.363925 9.790423 CHEST\n", | |
"3 17.509135 9.690588 11.311750 ANKLE_RIGHT\n", | |
"4 9.690485 16.312149 12.095406 ANKLE_LEFT\n", | |
"... ... ... ... ...\n", | |
"4348 7.293185 17.744339 10.781552 ANKLE_LEFT\n", | |
"4349 13.556494 9.316183 14.421283 CHEST\n", | |
"4350 7.537048 17.002989 12.532262 CHEST\n", | |
"4351 17.491765 10.302281 10.800121 ANKLE_LEFT\n", | |
"4352 17.690924 10.043395 10.868089 CHEST\n", | |
"\n", | |
"[4353 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 73, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 74, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train_oneHot = pd.concat([X_train.iloc[:,:-1], pd.DataFrame(one_hot_enc)], axis=1, ignore_index=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 75, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" <th>4</th>\n", | |
" <th>5</th>\n", | |
" <th>6</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>7.808919</td>\n", | |
" <td>17.462564</td>\n", | |
" <td>10.336258</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>8.445435</td>\n", | |
" <td>16.781792</td>\n", | |
" <td>10.883452</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>7.387962</td>\n", | |
" <td>17.363925</td>\n", | |
" <td>9.790423</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>17.509135</td>\n", | |
" <td>9.690588</td>\n", | |
" <td>11.311750</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>9.690485</td>\n", | |
" <td>16.312149</td>\n", | |
" <td>12.095406</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>7.293185</td>\n", | |
" <td>17.744339</td>\n", | |
" <td>10.781552</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>13.556494</td>\n", | |
" <td>9.316183</td>\n", | |
" <td>14.421283</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>7.537048</td>\n", | |
" <td>17.002989</td>\n", | |
" <td>12.532262</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>17.491765</td>\n", | |
" <td>10.302281</td>\n", | |
" <td>10.800121</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>17.690924</td>\n", | |
" <td>10.043395</td>\n", | |
" <td>10.868089</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 7 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3 4 5 6\n", | |
"0 7.808919 17.462564 10.336258 1.0 0.0 0.0 0.0\n", | |
"1 8.445435 16.781792 10.883452 0.0 1.0 0.0 0.0\n", | |
"2 7.387962 17.363925 9.790423 0.0 0.0 0.0 1.0\n", | |
"3 17.509135 9.690588 11.311750 0.0 1.0 0.0 0.0\n", | |
"4 9.690485 16.312149 12.095406 1.0 0.0 0.0 0.0\n", | |
"... ... ... ... ... ... ... ...\n", | |
"4348 7.293185 17.744339 10.781552 1.0 0.0 0.0 0.0\n", | |
"4349 13.556494 9.316183 14.421283 0.0 0.0 0.0 1.0\n", | |
"4350 7.537048 17.002989 12.532262 0.0 0.0 0.0 1.0\n", | |
"4351 17.491765 10.302281 10.800121 1.0 0.0 0.0 0.0\n", | |
"4352 17.690924 10.043395 10.868089 0.0 0.0 0.0 1.0\n", | |
"\n", | |
"[4353 rows x 7 columns]" | |
] | |
}, | |
"execution_count": 75, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train_oneHot" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 76, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>ANKLE_LEFT</th>\n", | |
" <th>ANKLE_RIGHT</th>\n", | |
" <th>BELT</th>\n", | |
" <th>CHEST</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>7.808919</td>\n", | |
" <td>17.462564</td>\n", | |
" <td>10.336258</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>8.445435</td>\n", | |
" <td>16.781792</td>\n", | |
" <td>10.883452</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>7.387962</td>\n", | |
" <td>17.363925</td>\n", | |
" <td>9.790423</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>17.509135</td>\n", | |
" <td>9.690588</td>\n", | |
" <td>11.311750</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>9.690485</td>\n", | |
" <td>16.312149</td>\n", | |
" <td>12.095406</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>7.293185</td>\n", | |
" <td>17.744339</td>\n", | |
" <td>10.781552</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>13.556494</td>\n", | |
" <td>9.316183</td>\n", | |
" <td>14.421283</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>7.537048</td>\n", | |
" <td>17.002989</td>\n", | |
" <td>12.532262</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>17.491765</td>\n", | |
" <td>10.302281</td>\n", | |
" <td>10.800121</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>17.690924</td>\n", | |
" <td>10.043395</td>\n", | |
" <td>10.868089</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 7 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z ANKLE_LEFT ANKLE_RIGHT BELT CHEST\n", | |
"0 7.808919 17.462564 10.336258 1.0 0.0 0.0 0.0\n", | |
"1 8.445435 16.781792 10.883452 0.0 1.0 0.0 0.0\n", | |
"2 7.387962 17.363925 9.790423 0.0 0.0 0.0 1.0\n", | |
"3 17.509135 9.690588 11.311750 0.0 1.0 0.0 0.0\n", | |
"4 9.690485 16.312149 12.095406 1.0 0.0 0.0 0.0\n", | |
"... ... ... ... ... ... ... ...\n", | |
"4348 7.293185 17.744339 10.781552 1.0 0.0 0.0 0.0\n", | |
"4349 13.556494 9.316183 14.421283 0.0 0.0 0.0 1.0\n", | |
"4350 7.537048 17.002989 12.532262 0.0 0.0 0.0 1.0\n", | |
"4351 17.491765 10.302281 10.800121 1.0 0.0 0.0 0.0\n", | |
"4352 17.690924 10.043395 10.868089 0.0 0.0 0.0 1.0\n", | |
"\n", | |
"[4353 rows x 7 columns]" | |
] | |
}, | |
"execution_count": 76, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"new_names = {0:'x', 1:'y', 2:'z', 3:'ANKLE_LEFT',4:'ANKLE_RIGHT',5:'BELT',6:'CHEST'}\n", | |
"X_train_oneHot = X_train_oneHot.rename(columns=new_names)\n", | |
"X_train_oneHot" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 77, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"y_train = y_train.reset_index(drop=True)\n", | |
"X_test = X_test.reset_index(drop=True)\n", | |
"y_test = y_test.reset_index(drop=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 78, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[0., 0., 0., 1.],\n", | |
" [0., 1., 0., 0.],\n", | |
" [1., 0., 0., 0.],\n", | |
" ...,\n", | |
" [1., 0., 0., 0.],\n", | |
" [1., 0., 0., 0.],\n", | |
" [0., 1., 0., 0.]])" | |
] | |
}, | |
"execution_count": 78, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"onehot_test = enc.transform(X_test[[\"sensor\"]]).toarray()\n", | |
"onehot_test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 79, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_test_oneHot = pd.concat([X_test.iloc[:,:-1], pd.DataFrame(onehot_test)], axis=1, ignore_index=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 80, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" <th>4</th>\n", | |
" <th>5</th>\n", | |
" <th>6</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>6.601192</td>\n", | |
" <td>14.365410</td>\n", | |
" <td>12.600944</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>7.744365</td>\n", | |
" <td>17.222940</td>\n", | |
" <td>11.285024</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>17.913727</td>\n", | |
" <td>9.296171</td>\n", | |
" <td>11.592793</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>9.494855</td>\n", | |
" <td>11.607346</td>\n", | |
" <td>13.532999</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>8.342002</td>\n", | |
" <td>16.944162</td>\n", | |
" <td>12.657538</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1447</th>\n", | |
" <td>8.805084</td>\n", | |
" <td>12.887988</td>\n", | |
" <td>13.077178</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1448</th>\n", | |
" <td>17.525626</td>\n", | |
" <td>10.393603</td>\n", | |
" <td>10.759197</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1449</th>\n", | |
" <td>17.766620</td>\n", | |
" <td>9.361600</td>\n", | |
" <td>12.332116</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1450</th>\n", | |
" <td>17.132786</td>\n", | |
" <td>10.406924</td>\n", | |
" <td>10.506890</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1451</th>\n", | |
" <td>8.655747</td>\n", | |
" <td>11.042521</td>\n", | |
" <td>11.338261</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1452 rows × 7 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3 4 5 6\n", | |
"0 6.601192 14.365410 12.600944 0.0 0.0 0.0 1.0\n", | |
"1 7.744365 17.222940 11.285024 0.0 1.0 0.0 0.0\n", | |
"2 17.913727 9.296171 11.592793 1.0 0.0 0.0 0.0\n", | |
"3 9.494855 11.607346 13.532999 0.0 0.0 0.0 1.0\n", | |
"4 8.342002 16.944162 12.657538 0.0 1.0 0.0 0.0\n", | |
"... ... ... ... ... ... ... ...\n", | |
"1447 8.805084 12.887988 13.077178 1.0 0.0 0.0 0.0\n", | |
"1448 17.525626 10.393603 10.759197 0.0 0.0 1.0 0.0\n", | |
"1449 17.766620 9.361600 12.332116 1.0 0.0 0.0 0.0\n", | |
"1450 17.132786 10.406924 10.506890 1.0 0.0 0.0 0.0\n", | |
"1451 8.655747 11.042521 11.338261 0.0 1.0 0.0 0.0\n", | |
"\n", | |
"[1452 rows x 7 columns]" | |
] | |
}, | |
"execution_count": 80, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_test_oneHot" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 81, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_test_oneHot = X_test_oneHot.rename(columns=new_names)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 82, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>ANKLE_LEFT</th>\n", | |
" <th>ANKLE_RIGHT</th>\n", | |
" <th>BELT</th>\n", | |
" <th>CHEST</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>6.601192</td>\n", | |
" <td>14.365410</td>\n", | |
" <td>12.600944</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>7.744365</td>\n", | |
" <td>17.222940</td>\n", | |
" <td>11.285024</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>17.913727</td>\n", | |
" <td>9.296171</td>\n", | |
" <td>11.592793</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>9.494855</td>\n", | |
" <td>11.607346</td>\n", | |
" <td>13.532999</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>8.342002</td>\n", | |
" <td>16.944162</td>\n", | |
" <td>12.657538</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1447</th>\n", | |
" <td>8.805084</td>\n", | |
" <td>12.887988</td>\n", | |
" <td>13.077178</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1448</th>\n", | |
" <td>17.525626</td>\n", | |
" <td>10.393603</td>\n", | |
" <td>10.759197</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1449</th>\n", | |
" <td>17.766620</td>\n", | |
" <td>9.361600</td>\n", | |
" <td>12.332116</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1450</th>\n", | |
" <td>17.132786</td>\n", | |
" <td>10.406924</td>\n", | |
" <td>10.506890</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1451</th>\n", | |
" <td>8.655747</td>\n", | |
" <td>11.042521</td>\n", | |
" <td>11.338261</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1452 rows × 7 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z ANKLE_LEFT ANKLE_RIGHT BELT CHEST\n", | |
"0 6.601192 14.365410 12.600944 0.0 0.0 0.0 1.0\n", | |
"1 7.744365 17.222940 11.285024 0.0 1.0 0.0 0.0\n", | |
"2 17.913727 9.296171 11.592793 1.0 0.0 0.0 0.0\n", | |
"3 9.494855 11.607346 13.532999 0.0 0.0 0.0 1.0\n", | |
"4 8.342002 16.944162 12.657538 0.0 1.0 0.0 0.0\n", | |
"... ... ... ... ... ... ... ...\n", | |
"1447 8.805084 12.887988 13.077178 1.0 0.0 0.0 0.0\n", | |
"1448 17.525626 10.393603 10.759197 0.0 0.0 1.0 0.0\n", | |
"1449 17.766620 9.361600 12.332116 1.0 0.0 0.0 0.0\n", | |
"1450 17.132786 10.406924 10.506890 1.0 0.0 0.0 0.0\n", | |
"1451 8.655747 11.042521 11.338261 0.0 1.0 0.0 0.0\n", | |
"\n", | |
"[1452 rows x 7 columns]" | |
] | |
}, | |
"execution_count": 82, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_test_oneHot" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Нормализација на податоци" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 83, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,\n", | |
" beta_2=0.999, early_stopping=False, epsilon=1e-08,\n", | |
" hidden_layer_sizes=5, learning_rate='constant',\n", | |
" learning_rate_init=0.001, max_fun=15000, max_iter=200,\n", | |
" momentum=0.9, n_iter_no_change=10, nesterovs_momentum=True,\n", | |
" power_t=0.5, random_state=1, shuffle=True, solver='lbfgs',\n", | |
" tol=0.0001, validation_fraction=0.1, verbose=False,\n", | |
" warm_start=False)" | |
] | |
}, | |
"execution_count": 83, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf.fit(X_train_oneHot, y_train)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 84, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.949724517906336" | |
] | |
}, | |
"execution_count": 84, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf.score(X_test_oneHot, y_test)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 85, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from sklearn import metrics" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 86, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"y_pred = clf.predict(X_test_oneHot)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 87, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([0, 0, 0, ..., 0, 0, 0], dtype=int64)" | |
] | |
}, | |
"execution_count": 87, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"y_pred" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 88, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0.0\n", | |
"0.0\n", | |
"0.0\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"C:\\Users\\PC\\Anaconda3\\lib\\site-packages\\sklearn\\metrics\\_classification.py:1272: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. Use `zero_division` parameter to control this behavior.\n", | |
" _warn_prf(average, modifier, msg_start, len(result))\n" | |
] | |
} | |
], | |
"source": [ | |
"print(metrics.precision_score(y_test, y_pred))\n", | |
"print(metrics.recall_score(y_test, y_pred))\n", | |
"print(metrics.f1_score(y_test, y_pred))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 89, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0\n" | |
] | |
} | |
], | |
"source": [ | |
"pred1 = 0\n", | |
"\n", | |
"for p in y_pred:\n", | |
" if p == 1:\n", | |
" pred1 += 1\n", | |
" \n", | |
"print(pred1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 118, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"to_scale = X_train_oneHot[['x', 'y', 'z']]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 119, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[-1.23548405, 1.57118937, -1.50068592],\n", | |
" [-1.07431278, 1.34755848, -1.07441525],\n", | |
" [-1.34207404, 1.53878686, -1.92589775],\n", | |
" ...,\n", | |
" [-1.30432412, 1.42022057, 0.21002756],\n", | |
" [ 1.21629537, -0.78093498, -1.13933096],\n", | |
" [ 1.26672399, -0.86597801, -1.08638335]])" | |
] | |
}, | |
"execution_count": 119, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"scaler = preprocessing.StandardScaler()\n", | |
"X_train_scaled = scaler.fit_transform(to_scale)\n", | |
"X_train_scaled" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 120, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[-1.54129106, 0.55378644, 0.26353103],\n", | |
" [-1.25182965, 1.49247361, -0.76158553],\n", | |
" [ 1.32313966, -1.11143808, -0.52182977],\n", | |
" ...,\n", | |
" [ 1.28589087, -1.08994493, 0.05411137],\n", | |
" [ 1.1253989 , -0.74656038, -1.36776145],\n", | |
" [-1.02105993, -0.53776927, -0.7201138 ]])" | |
] | |
}, | |
"execution_count": 120, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"to_scale = X_test_oneHot[['x', 'y', 'z']]\n", | |
"X_test_scaled = scaler.transform(to_scale)\n", | |
"X_test_scaled" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 121, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train_scaled_onehot = pd.concat([pd.DataFrame(X_train_scaled), pd.DataFrame(one_hot_enc)], axis=1, ignore_index=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 122, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" <th>4</th>\n", | |
" <th>5</th>\n", | |
" <th>6</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-1.235484</td>\n", | |
" <td>1.571189</td>\n", | |
" <td>-1.500686</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>-1.074313</td>\n", | |
" <td>1.347558</td>\n", | |
" <td>-1.074415</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>-1.342074</td>\n", | |
" <td>1.538787</td>\n", | |
" <td>-1.925898</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>1.220694</td>\n", | |
" <td>-0.981874</td>\n", | |
" <td>-0.740766</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>-0.759056</td>\n", | |
" <td>1.193283</td>\n", | |
" <td>-0.130289</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>-1.366072</td>\n", | |
" <td>1.663751</td>\n", | |
" <td>-1.153796</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>0.219851</td>\n", | |
" <td>-1.104864</td>\n", | |
" <td>1.681597</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>-1.304324</td>\n", | |
" <td>1.420221</td>\n", | |
" <td>0.210028</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>1.216295</td>\n", | |
" <td>-0.780935</td>\n", | |
" <td>-1.139331</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>1.266724</td>\n", | |
" <td>-0.865978</td>\n", | |
" <td>-1.086383</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 7 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3 4 5 6\n", | |
"0 -1.235484 1.571189 -1.500686 1.0 0.0 0.0 0.0\n", | |
"1 -1.074313 1.347558 -1.074415 0.0 1.0 0.0 0.0\n", | |
"2 -1.342074 1.538787 -1.925898 0.0 0.0 0.0 1.0\n", | |
"3 1.220694 -0.981874 -0.740766 0.0 1.0 0.0 0.0\n", | |
"4 -0.759056 1.193283 -0.130289 1.0 0.0 0.0 0.0\n", | |
"... ... ... ... ... ... ... ...\n", | |
"4348 -1.366072 1.663751 -1.153796 1.0 0.0 0.0 0.0\n", | |
"4349 0.219851 -1.104864 1.681597 0.0 0.0 0.0 1.0\n", | |
"4350 -1.304324 1.420221 0.210028 0.0 0.0 0.0 1.0\n", | |
"4351 1.216295 -0.780935 -1.139331 1.0 0.0 0.0 0.0\n", | |
"4352 1.266724 -0.865978 -1.086383 0.0 0.0 0.0 1.0\n", | |
"\n", | |
"[4353 rows x 7 columns]" | |
] | |
}, | |
"execution_count": 122, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train_scaled_onehot" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 123, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_test_scaled_onehot = pd.concat([pd.DataFrame(X_test_scaled), pd.DataFrame(onehot_test)], axis=1, ignore_index=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 128, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,\n", | |
" beta_2=0.999, early_stopping=False, epsilon=1e-08,\n", | |
" hidden_layer_sizes=5, learning_rate='constant',\n", | |
" learning_rate_init=0.001, max_fun=15000, max_iter=200,\n", | |
" momentum=0.9, n_iter_no_change=10, nesterovs_momentum=True,\n", | |
" power_t=0.5, random_state=1, shuffle=True, solver='lbfgs',\n", | |
" tol=0.0001, validation_fraction=0.1, verbose=False,\n", | |
" warm_start=False)" | |
] | |
}, | |
"execution_count": 128, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf.fit(X_train_scaled_onehot, y_train)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 129, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.9738292011019284" | |
] | |
}, | |
"execution_count": 129, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf.score(X_test_scaled_onehot, y_test)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 131, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0.7464788732394366\n", | |
"0.726027397260274\n", | |
"0.736111111111111\n" | |
] | |
} | |
], | |
"source": [ | |
"y_pred = clf.predict(X_test_scaled_onehot)\n", | |
"\n", | |
"print(metrics.precision_score(y_test, y_pred))\n", | |
"print(metrics.recall_score(y_test, y_pred))\n", | |
"print(metrics.f1_score(y_test, y_pred))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 132, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"71\n" | |
] | |
} | |
], | |
"source": [ | |
"pred1 = 0\n", | |
"\n", | |
"for p in y_pred:\n", | |
" if p == 1:\n", | |
" pred1 += 1\n", | |
" \n", | |
"print(pred1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 133, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"enc_ord = preprocessing.OrdinalEncoder()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 134, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[0.],\n", | |
" [1.],\n", | |
" [3.],\n", | |
" ...,\n", | |
" [3.],\n", | |
" [0.],\n", | |
" [3.]])" | |
] | |
}, | |
"execution_count": 134, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ordinal_train = enc_ord.fit_transform(X_train[[\"sensor\"]])\n", | |
"ordinal_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 135, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>x</th>\n", | |
" <th>y</th>\n", | |
" <th>z</th>\n", | |
" <th>sensor</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>7.808919</td>\n", | |
" <td>17.462564</td>\n", | |
" <td>10.336258</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>8.445435</td>\n", | |
" <td>16.781792</td>\n", | |
" <td>10.883452</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>7.387962</td>\n", | |
" <td>17.363925</td>\n", | |
" <td>9.790423</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>17.509135</td>\n", | |
" <td>9.690588</td>\n", | |
" <td>11.311750</td>\n", | |
" <td>ANKLE_RIGHT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>9.690485</td>\n", | |
" <td>16.312149</td>\n", | |
" <td>12.095406</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>7.293185</td>\n", | |
" <td>17.744339</td>\n", | |
" <td>10.781552</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>13.556494</td>\n", | |
" <td>9.316183</td>\n", | |
" <td>14.421283</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>7.537048</td>\n", | |
" <td>17.002989</td>\n", | |
" <td>12.532262</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>17.491765</td>\n", | |
" <td>10.302281</td>\n", | |
" <td>10.800121</td>\n", | |
" <td>ANKLE_LEFT</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>17.690924</td>\n", | |
" <td>10.043395</td>\n", | |
" <td>10.868089</td>\n", | |
" <td>CHEST</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" x y z sensor\n", | |
"0 7.808919 17.462564 10.336258 ANKLE_LEFT\n", | |
"1 8.445435 16.781792 10.883452 ANKLE_RIGHT\n", | |
"2 7.387962 17.363925 9.790423 CHEST\n", | |
"3 17.509135 9.690588 11.311750 ANKLE_RIGHT\n", | |
"4 9.690485 16.312149 12.095406 ANKLE_LEFT\n", | |
"... ... ... ... ...\n", | |
"4348 7.293185 17.744339 10.781552 ANKLE_LEFT\n", | |
"4349 13.556494 9.316183 14.421283 CHEST\n", | |
"4350 7.537048 17.002989 12.532262 CHEST\n", | |
"4351 17.491765 10.302281 10.800121 ANKLE_LEFT\n", | |
"4352 17.690924 10.043395 10.868089 CHEST\n", | |
"\n", | |
"[4353 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 135, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 136, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ordinal_test = enc_ord.transform(X_test[[\"sensor\"]])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 137, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[3.],\n", | |
" [1.],\n", | |
" [0.],\n", | |
" ...,\n", | |
" [0.],\n", | |
" [0.],\n", | |
" [1.]])" | |
] | |
}, | |
"execution_count": 137, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ordinal_test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 139, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train_scaled_ordinal = pd.concat([pd.DataFrame(X_train_scaled), pd.DataFrame(ordinal_train)], axis=1, ignore_index=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 140, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-1.235484</td>\n", | |
" <td>1.571189</td>\n", | |
" <td>-1.500686</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>-1.074313</td>\n", | |
" <td>1.347558</td>\n", | |
" <td>-1.074415</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>-1.342074</td>\n", | |
" <td>1.538787</td>\n", | |
" <td>-1.925898</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>1.220694</td>\n", | |
" <td>-0.981874</td>\n", | |
" <td>-0.740766</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>-0.759056</td>\n", | |
" <td>1.193283</td>\n", | |
" <td>-0.130289</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4348</th>\n", | |
" <td>-1.366072</td>\n", | |
" <td>1.663751</td>\n", | |
" <td>-1.153796</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4349</th>\n", | |
" <td>0.219851</td>\n", | |
" <td>-1.104864</td>\n", | |
" <td>1.681597</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4350</th>\n", | |
" <td>-1.304324</td>\n", | |
" <td>1.420221</td>\n", | |
" <td>0.210028</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4351</th>\n", | |
" <td>1.216295</td>\n", | |
" <td>-0.780935</td>\n", | |
" <td>-1.139331</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4352</th>\n", | |
" <td>1.266724</td>\n", | |
" <td>-0.865978</td>\n", | |
" <td>-1.086383</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>4353 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3\n", | |
"0 -1.235484 1.571189 -1.500686 0.0\n", | |
"1 -1.074313 1.347558 -1.074415 1.0\n", | |
"2 -1.342074 1.538787 -1.925898 3.0\n", | |
"3 1.220694 -0.981874 -0.740766 1.0\n", | |
"4 -0.759056 1.193283 -0.130289 0.0\n", | |
"... ... ... ... ...\n", | |
"4348 -1.366072 1.663751 -1.153796 0.0\n", | |
"4349 0.219851 -1.104864 1.681597 3.0\n", | |
"4350 -1.304324 1.420221 0.210028 3.0\n", | |
"4351 1.216295 -0.780935 -1.139331 0.0\n", | |
"4352 1.266724 -0.865978 -1.086383 3.0\n", | |
"\n", | |
"[4353 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 140, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_train_scaled_ordinal" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 141, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>-1.541291</td>\n", | |
" <td>0.553786</td>\n", | |
" <td>0.263531</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>-1.251830</td>\n", | |
" <td>1.492474</td>\n", | |
" <td>-0.761586</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>1.323140</td>\n", | |
" <td>-1.111438</td>\n", | |
" <td>-0.521830</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>-0.808591</td>\n", | |
" <td>-0.352227</td>\n", | |
" <td>0.989613</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>-1.100503</td>\n", | |
" <td>1.400896</td>\n", | |
" <td>0.307619</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1447</th>\n", | |
" <td>-0.983247</td>\n", | |
" <td>0.068459</td>\n", | |
" <td>0.634523</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1448</th>\n", | |
" <td>1.224869</td>\n", | |
" <td>-0.750936</td>\n", | |
" <td>-1.171211</td>\n", | |
" <td>2.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1449</th>\n", | |
" <td>1.285891</td>\n", | |
" <td>-1.089945</td>\n", | |
" <td>0.054111</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1450</th>\n", | |
" <td>1.125399</td>\n", | |
" <td>-0.746560</td>\n", | |
" <td>-1.367761</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1451</th>\n", | |
" <td>-1.021060</td>\n", | |
" <td>-0.537769</td>\n", | |
" <td>-0.720114</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1452 rows × 4 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 1 2 3\n", | |
"0 -1.541291 0.553786 0.263531 3.0\n", | |
"1 -1.251830 1.492474 -0.761586 1.0\n", | |
"2 1.323140 -1.111438 -0.521830 0.0\n", | |
"3 -0.808591 -0.352227 0.989613 3.0\n", | |
"4 -1.100503 1.400896 0.307619 1.0\n", | |
"... ... ... ... ...\n", | |
"1447 -0.983247 0.068459 0.634523 0.0\n", | |
"1448 1.224869 -0.750936 -1.171211 2.0\n", | |
"1449 1.285891 -1.089945 0.054111 0.0\n", | |
"1450 1.125399 -0.746560 -1.367761 0.0\n", | |
"1451 -1.021060 -0.537769 -0.720114 1.0\n", | |
"\n", | |
"[1452 rows x 4 columns]" | |
] | |
}, | |
"execution_count": 141, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"X_test_scaled_ordinal = pd.concat([pd.DataFrame(X_test_scaled), pd.DataFrame(ordinal_test)], axis=1, ignore_index=True)\n", | |
"X_test_scaled_ordinal" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 142, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"C:\\Users\\PC\\Anaconda3\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:470: ConvergenceWarning: lbfgs failed to converge (status=1):\n", | |
"STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n", | |
"\n", | |
"Increase the number of iterations (max_iter) or scale the data as shown in:\n", | |
" https://scikit-learn.org/stable/modules/preprocessing.html\n", | |
" self.n_iter_ = _check_optimize_result(\"lbfgs\", opt_res, self.max_iter)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"0.96900826446281" | |
] | |
}, | |
"execution_count": 142, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf.fit(X_train_scaled_ordinal, y_train)\n", | |
"clf.score(X_test_scaled_ordinal, y_test)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Намалување на димензионалноста" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 143, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from sklearn.decomposition import PCA" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 147, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[-5.55037193, 0.08146778, -2.15612609, ..., 0.10952981,\n", | |
" -0.14823016, -0.24225189],\n", | |
" [-5.70672752, 0.7128134 , -2.07729412, ..., -0.65393422,\n", | |
" 0.22176974, 0.41667697],\n", | |
" [-5.81467462, 0.9692932 , -2.24083904, ..., -0.16570335,\n", | |
" 0.3395157 , 0.43102271],\n", | |
" ...,\n", | |
" [-4.2581426 , -2.64728352, -0.65068817, ..., 0.39529215,\n", | |
" 0.21925306, -0.67930651],\n", | |
" [-3.78908656, -2.76118794, -0.40946681, ..., 0.91150706,\n", | |
" 0.36955418, -0.85848417],\n", | |
" [-3.98943325, -2.05482516, -0.79010927, ..., 0.95087186,\n", | |
" 1.2749949 , 0.066923 ]])" | |
] | |
}, | |
"execution_count": 147, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pca = PCA(n_components=10)\n", | |
"ar_pca = pca.fit_transform(activity_recognition_fin_X)\n", | |
"ar_pca" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 148, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train_pca, X_test_pca, y_train_pca, y_test_pca = train_test_split(ar_pca, activity_recognition_fin_Y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 157, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.9014329135909683" | |
] | |
}, | |
"execution_count": 157, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf = MLPClassifier(random_state=0, hidden_layer_sizes=(20,), solver='adam', activation='tanh', max_iter=700)\n", | |
"\n", | |
"clf.fit(X_train_pca, y_train_pca)\n", | |
"clf.score(X_test_pca, y_test_pca)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment