-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsvm_iris.py
40 lines (31 loc) · 872 Bytes
/
svm_iris.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
#!/usr/bin/python3
from sklearn.datasets import load_iris
from sklearn.svm import SVC
import numpy as np
import matplotlib.pyplot as plt
iris=load_iris()
# visualizing between sepal and target
# taking only two features
two_sepal=iris.data[:,:2]
# loading target
target=iris.target
svmclf=SVC()
trained_svm=svmclf.fit(two_sepal,target)
# by default kernel is rbf
trained_svm.predict()
#making data available into two units
"""
plt.scatter(two_sepal[:,0],two_sepal[:,1],c=target,cmap=plt.cm.coolwarm)
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
plt.title('Sepal Title')
plt.show()
# now plotting for petal length & petal width
#taking last two features
two_petal=iris.data[:,2:]
plt.scatter(two_petal[:,0],two_sepal[:,1],c=target,cmap=plt.cm.coolwarm)
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.title('petal Title')
plt.show()
"""