forked from kmkarakaya/Deep-Learning-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myFirstModelBackUp.py
95 lines (61 loc) · 1.6 KB
/
myFirstModelBackUp.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
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
"""
MURAT KARAKAYA AKADEMİ
NASIL KODLASAM?
"""
# %%
#LOAD DATASET
from sklearn.datasets import load_iris
dataSet = load_iris()
features = dataSet.data
labels = dataSet.target
labelsNames = list(dataSet.target_names)
featureNames = dataSet.feature_names
print([labelsNames[i] for i in labels[47:52]])
print(featureNames)
# %%
# ANALYZE DATA
import pandas as pd
#print(type(features))
featuresDF= pd.DataFrame(features)
featuresDF.columns = featureNames
#print(type(featuresDF))
#print(featuresDF.describe())
print(featuresDF.info())
# %%
# VISUALIZE DATA
featuresDF.plot(x="sepal length (cm)", y= "sepal width (cm)", kind= "scatter")
# %%
# SELECT MODEL
from sklearn.neighbors import KNeighborsClassifier
clf = KNeighborsClassifier(n_neighbors=8)
# %%
# SPLIT DATASET
from sklearn.model_selection import train_test_split
X = features
y = labels
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42)
# %%
# TRAIN MODEL
clf.fit(X_train, y_train)
accuracy = clf.score(X_train, y_train)
print("accuracy on train data {:.2}%".format(accuracy))
# %%
# TEST MODEL
accuracy = clf.score(X_test,y_test)
print("accuracy on test data {:.2}%".format(accuracy))
# %%
# IMPROVE
# %%
# SAVE MODEL
from joblib import dump, load
filename="myFirstSavedModel.joblib"
dump(clf, filename)
# %%
# LOAD MODEL
clfUploaded = load(filename)
# %%
# TEST WITH UPLOADED MODEL
accuracy = clfUploaded.score(X_test,y_test)
print("accuracy on test data {:.2}%".format(accuracy))