forked from DeepSleepUCDenver/sleep_models
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvm.py
More file actions
61 lines (48 loc) · 1.21 KB
/
svm.py
File metadata and controls
61 lines (48 loc) · 1.21 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
48
49
50
51
52
53
54
55
56
57
58
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
from sklearn import preprocessing
from sklearn import svm
from sklearn.semi_supervised import label_propagation
data = pd.read_feather('./feature_stage_data.ftr')
X = data[data.columns[3:]]
y = data['stage']
X = X.values
X = preprocessing.normalize(X)
#X = preprocessing.scale(X)
y = y.values
#y = pd.get_dummies(y)
#y = y.loc[:,1]
clf = svm.SVC()
clf.fit(X, y)
clf.score(X, y)
yp = clf.predict(X)
accuracy_score(y, [3 for i in range(len(y))])
data = pd.read_feather('./feature_stage_data.ftr')
data = pd.concat([data.iloc[:,3:], data.iloc[:,1]], axis=1)
dfs = [x for _, x in data.groupby(data.stage)]
len(dfs)
smpl = pd.DataFrame(columns=data.columns)
for df in dfs:
s = df.sample(n=100, random_state=74)
smpl = pd.concat([smpl, s], axis=0)
smpl.stage
smpl.shape
X = smpl[data.columns[:21]]
y = smpl['stage']
#X = pd.to_numeric(X)
X = X.values
#X = preprocessing.normalize(X)
X = preprocessing.scale(X)
y = pd.to_numeric(y)
y = y.values
clf = svm.SVC()
clf.fit(X, y)
clf.score(X, y)
yp = clf.predict(X)
yp == 3
for i in yp:
if i != 3:
print(i)
accuracy_score(y, yp)
accuracy_score(y, [3 for i in range(len(y))])