π kNN?
- μ€μκ° μμΈ‘μ μν νμ΅μ΄ νμνμ§ μλ€.
- κ³ μ°¨μ λ°μ΄ν°μλ μ ν©νμ§ μλ€.
π μ€μ΅
- μ€μκ° μμΈ‘μ μν νμ΅μ΄ νμνμ§ μλ€.
from sklearn.datasets import load_iris
iris = load_iris()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target,
test_size=0.2, random_state=13,
stratify=iris.target)
π»fit κ³Όμ μ΄ νμ
from sklearn.neighbors import KNeighborsClassifier
# n_neighbor -> λͺ κ°κΉμ§ κ°κΉμ΄ μ§μ μ μ°Ύμ κ²μ΄λ?
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(X_train, y_train)
π»μμΈ‘ κ²°κ³Ό νμΈ ν΄λ³΄κΈ°
from sklearn.metrics import accuracy_score
pred = knn.predict(X_test)
print(accuracy_score(y_test, pred))
>>>>
0.9666666666666667
from sklearn.metrics import classification_report, confusion_matrix
print(confusion_matrix(y_test, pred))
>>>>
[[10 0 0]
[ 0 9 1]
[ 0 0 10]]
π»classfication_report
print(classification_report(y_test, pred))
>>>>
precision recall f1-score support
0 1.00 1.00 1.00 10
1 1.00 0.90 0.95 10
2 0.91 1.00 0.95 10
accuracy 0.97 30
macro avg 0.97 0.97 0.97 30
weighted avg 0.97 0.97 0.97 30
'Study_note(zb_data) > Machine Learning' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
μ€ν°λλ ΈνΈ (credit card data 2) (0) | 2023.10.02 |
---|---|
μ€ν°λλ ΈνΈ (credit card data 1) (0) | 2023.10.02 |
μ€ν°λλ ΈνΈ (Boosting Algorithm) (1) | 2023.10.02 |
μ€ν°λλ ΈνΈ (HAR λ°μ΄ν° λ€λ€λ³΄κΈ°) (0) | 2023.09.30 |
μ€ν°λλ ΈνΈ (μμλΈ κΈ°λ²) (0) | 2023.09.30 |