-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml.py
37 lines (26 loc) · 1.11 KB
/
ml.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
import numpy as np
import pandas as pd
import seaborn as sns
sns.set_palette('husl')
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import StratifiedGroupKFold
from sklearn.svm import SVC
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
from sklearn.metrics import ConfusionMatrixDisplay
from sklearn.tree import DecisionTreeClassifier
col_name = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
dataset = pd.read_csv('iris.csv', names = col_name)
X = dataset.drop(['class'], axis=1)
y = dataset['class']
print(f'X shape: {X.shape} | y shape: {y.shape}')
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=1)
svn = SVC() # Support Vector Classifier from Support Vector Machine
svn.fit(X_train, y_train)
predictions = svn.predict(X_test)
print(accuracy_score(y_test, predictions))
print(classification_report(y_test, predictions))
ConfusionMatrixDisplay.from_predictions(y_test, predictions)
plt.show()