generated from cafechungkhoan/chu_gia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Support Vector Machine.py
47 lines (43 loc) · 1.39 KB
/
Support Vector Machine.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
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
df = pd.DataFrame(iris.data,columns=iris.feature_names)
df.head()
df['target'] = iris.target
df.head()
df[df.target==1].head()
df[df.target==2].head()
df['flower_name'] =df.target.apply(lambda x: iris.target_names[x])
df.head()
#--------- QUY ĐỊNH VỊ TRÍ PHÂN LỚP ---------------------------
#df[45:55]
df0 = df[:50]
df1 = df[50:100]
df2 = df[100:]
import matplotlib.pyplot as plt
plt.xlabel('Sepal Length')
plt.ylabel('Sepal Width')
plt.scatter(df0['sepal length (cm)'],
df0['sepal width (cm)'],
color="green",marker='+')
plt.scatter(df1['sepal length (cm)'],
df1['sepal width (cm)'],
color="blue",marker='.')
plt.xlabel('Petal Length')
plt.ylabel('Petal Width')
plt.scatter(df0['petal length (cm)'],
df0['petal width (cm)'],
color="green",marker='+')
plt.scatter(df1['petal length (cm)'],
df1['petal width (cm)'],
color="blue",marker='.')
from sklearn.model_selection import train_test_split
X = df.drop(['target','flower_name'], axis='columns')
y = df.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
len(X_train)
len(X_test)
from sklearn.svm import SVC
model = SVC()
model.fit(X_train, y_train)
model.score(X_test, y_test)