...
 
Commits (2)
......@@ -71,7 +71,7 @@
"for window_length in range(5,40,5):\n",
" \n",
" for n_clusters in range(5,30, 3):\n",
" X_train, X_test = codebook(window_length, n_clusters)\n",
" X_train, X_test = codebook_approach(window_length, n_clusters)\n",
" best_params = select_rfc_params(X_train, y_train, 10)\n",
" #RFC classifier\n",
" score = rfc(X_train, y_train, X_test, y_test, best_params)\n",
......
......@@ -69,7 +69,7 @@
"outputs": [],
"source": [
"#codebook approach\n",
"X_train, X_test = codebook(20, 10)\n",
"X_train, X_test = codebook_approach(20, 10)\n",
"#hyperparameter optimization\n",
"best_params = select_rfc_params(X_train, y_train, 10)"
]
......
......@@ -66,7 +66,7 @@
"outputs": [],
"source": [
"#codebook approach\n",
"X_train, X_test = codebook(20, 10)\n",
"X_train, X_test = codebook_approach(20, 10)\n",
"#hyperparameter optimization\n",
"best_params = select_svc_params(X_train, y_train, 10)\n",
"#SVM classifier\n",
......
......@@ -74,13 +74,13 @@
" score = run_svc(X_train, y_train, X_test, y_test)\n",
" p = [window_length, n_clusters, score]\n",
" \n",
" with open('paramTuningSVM.txt', 'a') as file: # save output in file \n",
" s = ['[', ']', ',']\n",
" p = str(list(p))\n",
" for e in s:\n",
" p = p.replace(e, '')\n",
" file.write(p)\n",
" file.write('\\n') \n",
" with open('paramTuningSVM.txt', 'a') as file: # save output in file \n",
" s = ['[', ']', ',']\n",
" p = str(list(p))\n",
" for e in s:\n",
" p = p.replace(e, '')\n",
" file.write(p)\n",
" file.write('\\n') \n",
"print('FINISH.')\n",
" \n",
" \n",
......
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
......@@ -52,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -64,14 +64,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_search.py:814: DeprecationWarning: The default of the `iid` parameter will change from True to False in version 0.22 and will be removed in 0.24. This will change numeric results when test-set sizes are unequal.\n",
" DeprecationWarning)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"FINISH.\n"
]
}
],
"source": [
"for window_length in range(5,40,5):\n",
" \n",
" for n_clusters in range(5,30, 3):\n",
" X_train, X_test = codebook(window_length, n_clusters)\n",
" X_train, X_test = codebook_approach(window_length, n_clusters)\n",
" best_params = select_rfc_params(X_train, y_train, 10)\n",
" #RFC classifier\n",
" score = rfc(X_train, y_train, X_test, y_test, best_params)\n",
......
......@@ -69,7 +69,7 @@
"outputs": [],
"source": [
"#codebook approach\n",
"X_train, X_test = codebook(20, 10)\n",
"X_train, X_test = codebook_approach(20, 10)\n",
"#hyperparameter optimization\n",
"best_params = select_rfc_params(X_train, y_train, 10)"
]
......
......@@ -66,7 +66,7 @@
"outputs": [],
"source": [
"#codebook approach\n",
"X_train, X_test = codebook(20, 10)\n",
"X_train, X_test = codebook_approach(20, 10)\n",
"#hyperparameter optimization\n",
"best_params = select_svc_params(X_train, y_train, 10)\n",
"#SVM classifier\n",
......
......@@ -2,24 +2,9 @@
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "OSError",
"evalue": "../../data/total_acc_x_train.txt not found.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-bd65c874ab08>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;31m#Load train data\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0macc_x\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloadtxt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'../../data/total_acc_x_train.txt'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0macc_y\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloadtxt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'../../data/total_acc_y_train.txt'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0macc_z\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloadtxt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'../../data/total_acc_z_train.txt'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/numpy/lib/npyio.py\u001b[0m in \u001b[0;36mloadtxt\u001b[0;34m(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows)\u001b[0m\n\u001b[1;32m 966\u001b[0m \u001b[0mfname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos_fspath\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 967\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0m_is_string_like\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 968\u001b[0;31m \u001b[0mfh\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_datasource\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'rt'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 969\u001b[0m \u001b[0mfencoding\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfh\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'encoding'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'latin1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 970\u001b[0m \u001b[0mfh\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0miter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/numpy/lib/_datasource.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(path, mode, destpath, encoding, newline)\u001b[0m\n\u001b[1;32m 267\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 268\u001b[0m \u001b[0mds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDataSource\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdestpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 269\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnewline\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnewline\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 270\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 271\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/numpy/lib/_datasource.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, path, mode, encoding, newline)\u001b[0m\n\u001b[1;32m 621\u001b[0m encoding=encoding, newline=newline)\n\u001b[1;32m 622\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 623\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mIOError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"%s not found.\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 624\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 625\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mOSError\u001b[0m: ../../data/total_acc_x_train.txt not found."
]
}
],
"outputs": [],
"source": [
"import sys\n",
"import numpy as np\n",
......@@ -64,10 +49,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def extract_subsequence_with_window_step(X, window_length, overlap_length):\n",
" \"\"\"Extract Subsequences for X\n",
"\n",
" Args:\n",
" X: input data\n",
" window_length\n",
" overlap_length\n",
" Returns:\n",
" windows\n",
" \"\"\"\n",
" windows = []\n",
" X_length = len(X)\n",
" i = 0\n",
" window_max_index = X_length - window_length + 1\n",
" \n",
" while i < window_max_index:\n",
" w = X[i:i+window_length]\n",
" windows.append(w)\n",
" i += overlap_length\n",
" return windows\n",
"\n",
"#Sliding Window Approach\n",
"def sliding_window_approach(X, window_length, overlap_length):\n",
" \"\"\"Sliding Window for X\n",
......@@ -179,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......
5 5 0.8411944350186631
5 8 0.8578215134034611
5 11 0.8764845605700713
5 14 0.8737699355276553
5 17 0.8808958262639973
5 20 0.8825924669155073
5 23 0.8903970139124533
5 26 0.8863250763488293
5 29 0.8795385137427892
10 5 0.8669833729216152
10 8 0.8717339667458432
10 11 0.8808958262639973
10 14 0.8778418730912793
10 17 0.8676620291822192
10 20 0.8795385137427892
10 23 0.8730912792670512
10 26 0.8737699355276553
10 29 0.8747879199185612
15 5 0.8646080760095012
15 8 0.8785205293518833
15 11 0.8754665761791652
15 14 0.8717339667458432
15 17 0.8887003732609433
15 20 0.8785205293518833
15 23 0.8907363420427553
15 26 0.8873430607397353
15 29 0.8927723108245673
20 5 0.8198167628096369
20 8 0.8795385137427892
20 11 0.8669833729216152
20 14 0.8890397013912453
20 17 0.8788598574821853
20 20 0.8730912792670512
20 23 0.8758059043094673
20 26 0.8836104513064132
20 29 0.8832711231761113
25 5 0.8306752629793009
25 8 0.8663047166610112
25 11 0.850356294536817
25 14 0.9043094672548354
25 17 0.8931116389548693
25 20 0.8897183576518494
25 23 0.8934509670851714
25 26 0.8832711231761113
25 29 0.8788598574821853
30 5 0.825585341024771
30 8 0.8622327790973872
30 11 0.8791991856124872
30 14 0.8934509670851714
30 17 0.8890397013912453
30 20 0.8992195453003053
30 23 0.8948082796063793
30 26 0.9012555140821175
30 29 0.8863250763488293
35 5 0.8435697319307771
35 8 0.8432304038004751
35 11 0.8727519511367492
35 14 0.8554462164913471
35 17 0.8788598574821853
35 20 0.8829317950458093
35 23 0.8890397013912453
35 26 0.8836104513064132
35 29 0.8747879199185612
5 5 0.829317950458093
5 8 0.8761452324397693
5 11 0.8897183576518494
5 14 0.8764845605700713
5 17 0.8734306073973532
5 20 0.9019341703427214
5 23 0.8812351543942993
5 26 0.8866644044791313
5 29 0.8876823888700374
10 5 0.8456057007125891
10 8 0.8551068883610451
10 11 0.8683406854428232
10 14 0.8873430607397353
10 17 0.8741092636579573
10 20 0.8982015609093994
10 23 0.8802171700033933
10 26 0.8873430607397353
10 29 0.8812351543942993
15 5 0.839497794367153
15 8 0.8489989820156091
15 11 0.850356294536817
15 14 0.8724126230064473
15 17 0.8686800135731252
15 20 0.8727519511367492
15 23 0.8758059043094673
15 26 0.8958262639972854
15 29 0.8863250763488293
20 5 0.7919918561248728
20 8 0.8473023413640991
20 11 0.8571428571428571
20 14 0.8873430607397353
20 17 0.8608754665761792
20 20 0.8710553104852392
20 23 0.8832711231761113
20 26 0.8914149983033594
20 29 0.8819138106549033
25 5 0.7919918561248728
25 8 0.8489989820156091
25 11 0.8656260604004072
25 14 0.8988802171700034
25 17 0.8700373260943333
25 20 0.8781812012215813
25 23 0.8961655921275874
25 26 0.8951476077366813
25 29 0.9029521547336274
30 5 0.8008143875127248
30 8 0.8673227010519172
30 11 0.8785205293518833
30 14 0.8897183576518494
30 17 0.8775025449609772
30 20 0.8968442483881914
30 23 0.8978622327790974
30 26 0.8859857482185273
30 29 0.8856464200882254
35 5 0.8099762470308789
35 8 0.8469630132337971
35 11 0.8646080760095012
35 14 0.8805564981336953
35 17 0.8907363420427553
35 20 0.8591788259246692
35 23 0.8849677638276213
35 26 0.8713946386155412
35 29 0.8802171700033933
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
......@@ -50,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
......@@ -62,25 +62,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"FINISH.\n"
]
}
],
"source": [
"for window_length in range(5,40,5):\n",
" for n_clusters in range(5,30, 3): \n",
" X_train, X_test = codebook(window_length, n_clusters)\n",
" X_train, X_test = codebook_approach(window_length, n_clusters)\n",
" best_params = select_svc_params(X_train, y_train, 10)\n",
" #SVM classifier\n",
" score = run_svc(X_train, y_train, X_test, y_test)\n",
" p = [window_length, n_clusters, score]\n",
" \n",
" with open('paramTuningSVM.txt', 'a') as file: # save output in file \n",
" s = ['[', ']', ',']\n",
" p = str(list(p))\n",
" for e in s:\n",
" p = p.replace(e, '')\n",
" file.write(p)\n",
" file.write('\\n') \n",
" with open('paramTuningSVM.txt', 'a') as file: # save output in file \n",
" s = ['[', ']', ',']\n",
" p = str(list(p))\n",
" for e in s:\n",
" p = p.replace(e, '')\n",
" file.write(p)\n",
" file.write('\\n') \n",
"print('FINISH.')\n",
" \n",
" \n",
......