码迷,mamicode.com
首页 > 其他好文 > 详细

sklearn.metrics中的评估方法

时间:2020-02-13 17:14:17      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:dig   learn   conf   rom   epo   imp   model   表格   metrics   

1.confusion_matrix

  • 利用混淆矩阵进行评估
  • 混淆矩阵说白了就是一张表格

复现代码

# Import necessary modules
from sklearn.metrics import classification_report

from sklearn.metrics import confusion_matrix

# Create training and test set
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.4,random_state=42)

# Instantiate a k-NN classifier: knn
knn = KNeighborsClassifier(6)

# Fit the classifier to the training data
knn.fit(X_train,y_train)

# Predict the labels of the test data: y_pred
y_pred = knn.predict(X_test)

# Generate the confusion matrix and classification report
print(confusion_matrix(y_test,y_pred))
print(classification_report(y_test,y_pred))

accuracy_score()

分类准确率分数

  • 分类准确率分数是指所有分类正确的百分比。分类准确率这一衡量分类器的标准比较容易理解,但是它不能告诉你响应值的潜在分布,并且它也不能告诉你分类器犯错的类型
# Import necessary modules
from sklearn.neighbors import KNeighborsClassifier 
from sklearn.model_selection import train_test_split

# Create feature and target arrays
X = digits.data
y = digits.target

# Split into training and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=42, stratify=y)

# Create a k-NN classifier with 7 neighbors: knn
knn = KNeighborsClassifier(n_neighbors=7)

# Fit the classifier to the training data
knn.fit(X_train, y_train)
y_pred=knn.predict(X_test)
# Print the accuracy
print(accuracy_score(y_test, y_pred))

#0.89996709

sklearn.metrics中的评估方法

标签:dig   learn   conf   rom   epo   imp   model   表格   metrics   

原文地址:https://www.cnblogs.com/gaowenxingxing/p/12303974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!