-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknn_sklearn.py
51 lines (41 loc) · 1.5 KB
/
knn_sklearn.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
# -*- coding: utf-8 -*-
"""KNN_sklearn.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1V_uOfAXuM-KPT8i8aSZgg9kq8WaRIsl5
"""
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neighbors import KNeighborsRegressor
import_dataset_iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(
import_dataset_iris.data,
import_dataset_iris.target,
test_size=0.15,
train_size=0.70,
shuffle=True,
stratify=import_dataset_iris.target,
random_state=0,
)
X_train, X_val, y_train, y_val = train_test_split(
import_dataset_iris.data,
import_dataset_iris.target,
test_size=0.15,
train_size=0.70,
shuffle=True,
stratify=import_dataset_iris.target,
random_state=0,
)
KNN_Classification = KNeighborsClassifier()
KNN_Classification.fit(X_train, y_train)
KNN_Regression = KNeighborsRegressor()
KNN_Regression.fit(X_train, y_train)
print("KNN_Classification")
print("Accuracy of Train_set", KNN_Classification.score(X_train, y_train))
print("Accuracy of Test_set", KNN_Classification.score(X_test, y_test))
print("Accuracy of Val_set", KNN_Classification.score(X_val, y_val))
print("KNN_Regression")
print("Accuracy of Train_set", KNN_Regression.score(X_train, y_train))
print("Accuracy of Test_set", KNN_Regression.score(X_test, y_test))
print("Accuracy of Val_set", KNN_Regression.score(X_val, y_val))