展开

关键词

混淆矩阵及confusion_matrix函数的使用

y_pred: 是样本预测分类结果 labels:是所给出的类别,通过这个可对类别进行选择 sample_weight : 样本权重 实现例子: from sklearn.metrics import confusion_matrix y_true=[2,1,0,1,2,0] y_pred=[2,0,0,1,2,1] C=confusion_matrix(y_true, y_pred) 运行结果: [[1 1 0] [1 1 0]

1.1K20

机器学习 - 精度评价

分类 - 混淆矩阵 Confusion Matrix sklearn.metrics.confusion_matrix from sklearn.metrics import confusion_matrix image.png C = confusion_matrix(gt_labels, pred_labels, labels=None, sample_weight=None)[source] # C gt_labels = [2, 0, 2, 2, 0, 1] pred_labels = [0, 0, 2, 2, 0, 2] confusion_matrix(gt_labels, pred_labels ) # array([[2, 0, 0], # [0, 0, 1], # [1, 0, 2]]) 示例2: from sklearn.metrics import confusion_matrix tn, fp, fn, tp = confusion_matrix([0, 1, 0, 1], [1, 1, 1, 0]).ravel() #(tn, fp, fn, tp) #(0, 2, 1, 1

52270
  • 广告
    关闭

    腾讯云+社区系列公开课上线啦!

    Vite学习指南,基于腾讯云Webify部署项目。

  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    【Python深度学习之路】-3.1性能评价指标

    2.编程实现混淆矩阵 使用sklearn.metrics模块中的confusion_matrix()函数对混淆矩阵中的数据进行观察。 confusion_matrix()函数的使用方法如下 from sklearn.metrics import confusion_matrix confmat = confusion_matrix(y_true

    7820

    混淆矩阵简介与Python实现

    Python混淆矩阵的使用 confusion_matrix函数的使用 官方文档中给出的用法是 sklearn.metrics.confusion_matrix(y_true, y_pred, labels 是样本预测分类结果 labels:是所给出的类别,通过这个可对类别进行选择 sample_weight : 样本权重 实现代码: Python from sklearn.metrics import confusion_matrix y_true = [2, 1, 0, 1, 2, 0] y_pred = [2, 0, 0, 1, 2, 1] C=confusion_matrix(y_true, y_pred) print(C "cat", "ant", "cat", "cat", "ant", "bird"] y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"] C2 = confusion_matrix

    81830

    混淆矩阵 (confusion matrix)

    confusion_matrix()用法如下: from sklearn.metrics import confusion_matrix y_true = ["cat", "ant", "cat", " cat", "ant", "bird"] y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"] confusion_matrix(y_true, y_pred

    69030

    python sklearn包——混淆矩阵、分类报告等自动生成方式

    clf_LR.predict(x_test) return clf def my_confusion_matrix(y_true, y_pred): from sklearn.metrics import confusion_matrix labels = list(set(y_true)) conf_mat = confusion_matrix(y_true, y_pred, labels = labels) print "confusion_matrix(left labels: y_true, up labels: y_pred):" print "labels\t", for i in range(len( 主要参考sklearn官网 补充拓展:[sklearn] 混淆矩阵——多分类预测结果统计 调用的函数:confusion_matrix(typeTrue, typePred) typeTrue:实际类别

    55830

    机器学习笔记之KNN分类

    = table(test_predict,test_target) dimnames(confusion_matrix) <- list(target_names,target_names) = confusion_matrix)) } #执行分类任务 result <- datingClassTest( test_data = test_data, train_data train_target = train_target, test_target = test_target ) 预测结果收集与混洗矩阵输出: result$test_data result$confusion_matrix print(classification_report(test_target,test_predict, target_names=target_names)) return test_data,confusion_matrix t0 = time.time() train_data,test_data,train_target,test_target = Data_Input() test_reslut,confusion_matrix

    51440

    Python数据相关系数矩阵和热力图轻松实现教程

    /BluesStateRelation.png') plt.show() 补充知识:python混淆矩阵(confusion_matrix)FP、FN、TP、TN、ROC,精确率(Precision) author__ = "lingjun" # welcome to attention:小白CV import seaborn as sns from sklearn.metrics import confusion_matrix , "dog", "cat", "cat", "cat", "cat"] y_pred = ["cat", "cat", "dog", "cat", "cat", "cat", "cat"] C2= confusion_matrix 最终的打印结果如下所示: [[1 2] [0 4]] [1 2 0 4] 解释下上面这几个数字的意思: C2= confusion_matrix(y_true, y_pred, labels=[“dog __author__ = "lingjun" # E-mail: 1763469890@qq.com from sklearn.metrics import roc_auc_score, confusion_matrix

    62820

    MIoU,Mean IoU,Mean Intersection over Union,均交并比

    from sklearn.metrics import confusion_matrix import numpy as np def compute_iou(y_pred, y_true): ypred is a flatten vector y_pred = y_pred.flatten() y_true = y_true.flatten() current = confusion_matrix

    27510

    用Streamlit构建机器学习应用

    import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import confusion_matrix dtc.score(X_test, y_test) st.write('Accuracy: ', acc) pred_dtc = dtc.predict(X_test) cm_dtc=confusion_matrix svm.score(X_test, y_test) st.write('Accuracy: ', acc) pred_svm = svm.predict(X_test) cm=confusion_matrix import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import confusion_matrix svm.score(X_test, y_test) st.write('Accuracy: ', acc) pred_svm = svm.predict(X_test) cm=confusion_matrix

    53930

    使用python matploblib库绘制准确率,损失率折线图

    FangSong'] #可显示中文字符 plt.rcParams['axes.unicode_minus']=False classes = ['a','b','c','d','e','f','g'] confusion_matrix (0,0,0,86,1,0,0),(0,0,0,1,94,1,0),(0,1,5,1,0,96,8),(0,0,0,4,3,0,85)],dtype=np.float64) plt.imshow(confusion_matrix in range(7)] for i in range(7)],(confusion_matrix.size,2)) for i, j in iters: plt.text(j, i, format(confusion_matrix

    1K20

    使用sklearn对多分类的每个类别进行指标评价操作

    weighted avg': {‘precision': 0.75, ‘recall': 0.7, ‘f1-score': 0.7114285714285715, ‘support': 10}} 使用confusion_matrix 方法可以输出该多分类问题的混淆矩阵,代码如下: from sklearn.metrics import confusion_matrix y_true = ['北京', '上海', '成都', '成都' '上海', '成都', '北京', '上海'] y_pred = ['北京', '上海', '成都', '上海', '成都', '成都', '上海', '成都', '北京', '上海'] print(confusion_matrix *- # author: Jclian91 # place: Daxing Beijing # time: 2019-11-14 21:52 from sklearn.metrics import confusion_matrix 北京', '上海', '成都', '上海', '成都', '成都', '上海', '成都', '北京', '上海'] classes = ['北京', '上海', '成都'] confusion = confusion_matrix

    1.4K51

    基于随机森林模型的心脏病人预测分类

    import roc_curve, auc from sklearn.metrics import classification_report from sklearn.metrics import confusion_matrix rf.predict(X_test) y_pred_quant = rf.predict_proba(X_test)[:,1] y_pred_bin = rf.predict(X_test) # 混淆矩阵 confusion_matrix = confusion_matrix(y_test,y_pred_bin) confusion_matrix # 计算sensitivity and specificity total=sum(sum (confusion_matrix)) sensitivity = confusion_matrix[0,0]/(confusion_matrix[0,0]+confusion_matrix[1,0]) specificity = confusion_matrix[1,1]/(confusion_matrix[1,1]+confusion_matrix[0,1]) [008i3skNgy1gyw1m75fwtj31c80r4wiz.jpg

    22410

    6. 逻辑回归

    I miss you,真实为:[0] 2.1 性能指标 混淆矩阵 from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt confusion_matrix = confusion_matrix(y_test, pred) plt.matshow(confusion_matrix) plt.rcParams[ sklearn.model_selection import train_test_split from sklearn.metrics import classification_report, accuracy_score, confusion_matrix X_test) print('Accuracy: %s' % accuracy_score(y_test, predictions)) print('Confusion Matrix:') print(confusion_matrix

    35320

    【算法】逐步在Python中构建Logistic回归

    训练集上拟合逻辑回归 classifier = LogisticRegression(random_state=0) classifier.fit(X_train, y_train) 预测测试集结果并创建混淆矩阵 confusion_matrix y_pred = classifier.predict(X_test) from sklearn.metrics import confusion_matrix confusion_matrix = confusion_matrix (y_test, y_pred) print(confusion_matrix) 结果告诉我们,我们有9046 + 229个正确的预测和912 + 110个不正确的预测。

    1.5K20

    模型评估指标

    1、sklearn.metrics模块中的confusion_matrix方法,可以直接求出混合矩阵: from sklearn.metrics import confusion_matrix confmat = confusion_matrix(y_true=y_test, y_pred=y_pred) print(confmat) # 混合矩阵为: [[71 1] [ 5 37]] 2、上面得到的结果展示的较简单

    61960

    爱数课实验 | 第六期-金融反欺诈案例研究

    # 输出混淆矩阵 from sklearn.metrics import classification_report,confusion_matrix confusion_matrix = confusion_matrix (y_test, y_pred_rf) print(confusion_matrix) # 绘制混淆矩阵热力图 # 创建总画布窗口 plt.figure(figsize=(8,6)) # 绘制热力图 y_train) y_pred_xgbt = xgbt.predict(x_test) # 输出混淆矩阵 from sklearn.metrics import classification_report,confusion_matrix confusion_matrix = confusion_matrix(y_test, y_pred_xgbt) print(confusion_matrix) # 绘制混淆矩阵热力图 # 创建总画布窗口 热力图的每个单元上显示数值;annot_kws:设置单元格中数值标签的其他属性; # fmt:指定单元格中数据的显示格式;cmap:于热力图的填充色,'YlGnBu_r'代表数字越大,颜色越浅 sns.heatmap(confusion_matrix

    9120

    根据已给字符数据,训练逻辑回归、随机森林、SVM,生成ROC和箱线图

    roc_curve, auc from scipy import interp import matplotlib.pyplot as plt from sklearn.metrics import confusion_matrix data = np.hstack((X,np.reshape(y,[-1, 1]))) # 画 boxplot c_boxplot(data) # 计算混淆矩阵 confusion_matrix=confusion_matrix (y_test,y_pred) print (confusion_matrix) # 显示混淆矩阵 plt.matshow(confusion_matrix) plt.title(u'混淆矩阵') plt.colorbar

    1.1K100

    Machine Learning-模型评估与调参 ——评价指标代码

    一、混淆矩阵实现 1from sklearn.metrics import confusion_matrix 2 3pipe_svc.fit(X_train, y_train) 4y_pred = pipe_svc.predict(X_test) 5confmat = confusion_matrix(y_true=y_test, y_pred=y_pred) 6print(confmat) output

    27220

    Python 操作.csv文件

    nolearn.lasagne import visualize from sklearn.metrics import classification_report from sklearn.metrics import confusion_matrix verbose=1,     ) # Train the network nn = net1.fit(X_train, y_train) preds = net1.predict(X_test) cm = confusion_matrix

    19120

    扫码关注腾讯云开发者

    领取腾讯云代金券