-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (39 loc) · 1.38 KB
/
main.py
File metadata and controls
50 lines (39 loc) · 1.38 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
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
import matplotlib.pyplot as plt
kernel_df = pd.read_csv('data.csv')
DATA_SIZE = len(kernel_df)
def select_kernel(X, Y):
kernels = np.zeros((len(X), len(Y)))
for i, idx_X in enumerate(X):
for j, idx_Y in enumerate(Y):
kernels[i, j] = K[idx_X, idx_Y]
return kernels
y = kernel_df['target'].values
X_train, X_test, y_train, y_test = train_test_split(np.arange(DATA_SIZE),y[:DATA_SIZE], test_size=0.3)
#Const
K = pd.read_csv('const_weight_kernels.csv').to_numpy()
const_clf = svm.SVC(kernel=select_kernel, probability=False)
#Bound
K = pd.read_csv('bound_weight_kernels.csv').to_numpy()
bound_clf = svm.SVC(kernel=select_kernel, probability=False)
def experiment(clf, kernel_weight):
print('Peso ' + kernel_weight)
clf.fit(X_train.reshape(-1,1), y_train)
pred = clf.predict(X_test.reshape(-1,1))
#Métricas
#Acurácia
print('Acurácia:', accuracy_score(y_test, pred))
#Precision Score
print('Precisão:', precision_score(y_test, pred))
#Recall Score
print('Recall:', recall_score(y_test, pred))
#F1 Score
print('F1:', f1_score(y_test, pred))
#Const
experiment(const_clf, 'Constante')
#Bound
experiment(bound_clf, 'Bound')