This repository was archived by the owner on Mar 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull-code.py
More file actions
97 lines (57 loc) · 1.66 KB
/
full-code.py
File metadata and controls
97 lines (57 loc) · 1.66 KB
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
96
97
# %%
# LOAD DATASET
from sklearn.datasets import load_iris
dataSet = load_iris()
features = dataSet.data
labels = dataSet.target
labelsNames = list(dataSet.target_names)
featuresNames = dataSet.feature_names
print([labelsNames[i] for i in labels[47:52]])
print(featuresNames)
# %%
# ANALAYZE DATA
import pandas as pd
print(type(features))
featuresDF= pd.DataFrame(features)
featuresDF.columns = featuresNames
print(type(featuresDF))
print(featuresDF.describe())
print(featuresDF.info())
# %%
# VISUALIZE DATA
featuresDF.plot(kind= "bar")
# %%
# SELECT MODEL
from sklearn.neighbors import KNeighborsClassifier
clf = KNeighborsClassifier(n_neighbors=8)
# %%
# SPLIT DATASET
import numpy as np
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)
print(X_test[:3])
# &&
# TRAIN MODEL
#neigh = KNeighborsClassifier()(n_neighbors=3)
clf.fit(X_train, y_train)
accuarcy = clf.score(X_train,y_train)
print("accuarcy on train data {:.2}%".format(accuarcy))
# %%
# TEST MODEL
accuarcy = clf.score(X_test,y_test)
print("accuarcy on test data {:.2}%".format(accuarcy))
# %%
# SAVE MODEL
from joblib import dump, load
filename = "myFirstSavedModel.joblib"
dump(clf, filename)
## %%
## LOAD MODEL
clfUploaded = load(filename)
# %%
# TEST WITH UPLOADED MODEL
accuarcy = clfUploaded.score(X_test,y_test)
print("accuarcy on test data {:.2}%".format(accuarcy))