forked from ymzx/pso-svm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
35 lines (31 loc) · 883 Bytes
/
test.py
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
# -*- coding: utf-8 -*-
# @Time : 2020/6/2
# @Author : JWDUAN
# @Email : 494056012@qq.com
# @File : xxx.py
# @Software: PyCharm
from sklearn.metrics import confusion_matrix
from config.config import kernel
from sklearn.svm import SVC
def confusionMatrix():
'''
理解什么是混淆矩阵
:return:
'''
y_true = [1, 1, 0, 1, 0, 0]
y_pred = [0, 0, 0, 1, 1, 1]
C = confusion_matrix(y_true, y_pred)
print(C)
def predict(data,gamma,c):
X_train, X_test, y_train, y_test = data
svclassifier = SVC(kernel=kernel, gamma=gamma, C=c)
svclassifier.fit(X_train, y_train)
y_train_pred = svclassifier.predict(X_train)
y_test_pred = svclassifier.predict(X_test)
return y_train_pred, y_test_pred
if __name__ == '__main__':
data = ''
gamma = ''
c = ''
# 补齐上面三个参数内容即可
predict(data,gamma,c)