-
Notifications
You must be signed in to change notification settings - Fork 1
/
SVM.py
89 lines (40 loc) · 1.32 KB
/
SVM.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# coding: utf-8
# ## importing libraries
# In[1]:
import numpy as np
import pandas as pd
from DataPreprocessing import *
import matplotlib.pyplot as plt
#get_ipython().run_line_magic('matplotlib', 'inline')
import seaborn as sn
from sklearn.svm import SVC
# In[2]:
#defining the kernels defined in scikit-learn
kernels = ['linear', 'poly', 'rbf', 'sigmoid']
# In[3]:
# creating temporary models with all available kernels and analysing train and test scores
#print(' Kernel ' + ' Train Score ' + ' Test Score')
#for k in kernels:
# temp_svm = SVC(kernel = k)
# temp_svm.fit(x_train,y_train)
# temp_y_pred = temp_svm.predict(x_test)
# train_score=temp_svm.score(x_train,y_train)
# test_score=temp_svm.score(x_test,y_test)
# print(k,train_score,test_score)
# > Polynomial Kernel has the best Scores, Hence we decide to use Polynomial Kernel for training the model
# ### Training the model with polynomial kernel and test the model
# In[4]:
svm_poly_model = SVC(kernel = 'poly')
# In[5]:
svm_poly_model.fit(x_train, y_train)
# In[6]:
svm_poly_pred = svm_poly_model.predict(x_test)
# In[7]:
from sklearn.metrics import confusion_matrix,classification_report,accuracy_score
# In[8]:
svm_ac = accuracy_score(svm_poly_pred,y_test)
# In[9]:
svm_ac
# In[ ]:
# In[ ]: