-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml_model.py
More file actions
47 lines (34 loc) · 1.1 KB
/
Copy pathml_model.py
File metadata and controls
47 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Packages
import pandas as pd
import numpy as np
import pickle
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
# Import dataset
data = pd.read_csv('fitness_poses_csvs_out_basic.csv', header=None)
# Prepare data
# Define the classes
class0 = 'squat_down'
class1 = 'squat_up'
data.columns = [str(col) for col in data.columns]
data.drop(['0'], axis=1)
def newtarget(row):
if row['1'] == class0:
return 0
elif row['1'] == class1:
return 1
data['1'] = data.apply(newtarget, axis=1)
X = data.drop(['0','1'], axis=1)
y = data['1']
X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=True, test_size=0.2, random_state=1)
# Initialize the model and set the hyperparameters
knn = KNeighborsClassifier(n_neighbors=5, weights='distance')
# Train
knn.fit(X_train, y_train)
## Score -- DEBUGGING PURPOSES
print("Test data accuracy was", knn.score(X_test, y_test))
print("Train data accuracy was", knn.score(X_train, y_train))
#Save the model
pkl_file = 'repcountsquat.p'
with open(pkl_file, 'wb') as file:
pickle.dump(knn, file)