Hướng dẫn what is roc curve used in python? - đường cong roc được sử dụng trong python là gì?
Ghi chú Show Nhấn vào đây để tải xuống mã ví dụ đầy đủ hoặc để chạy ví dụ này trong trình duyệt của bạn thông qua Binderhere to download the full example code or to run this example in your browser via Binder Ví dụ về số liệu đặc tính hoạt động của máy thu (ROC) để đánh giá chất lượng đầu ra của trình phân loại. Các đường cong ROC thường có tốc độ dương thực trên trục Y và tốc độ dương giả trên trục X. Điều này có nghĩa là góc trên cùng bên trái của cốt truyện là điểm lý tưởng của người Viking - tỷ lệ dương tính giả là 0 và tỷ lệ dương thực sự của một. Điều này không thực tế lắm, nhưng nó có nghĩa là một khu vực lớn hơn dưới đường cong (AUC) thường tốt hơn. Độ dốc của các đường cong ROC cũng rất quan trọng, vì nó là lý tưởng để tối đa hóa tốc độ dương thực sự trong khi giảm thiểu tỷ lệ dương tính giả. Các đường cong ROC thường được sử dụng trong phân loại nhị phân để nghiên cứu đầu ra của một phân loại. Để mở rộng khu vực đường cong ROC và ROC để phân loại đa nhãn, cần phải binarize đầu ra. Một đường cong ROC có thể được vẽ trên mỗi nhãn, nhưng người ta cũng có thể vẽ đường cong ROC bằng cách xem xét từng phần tử của ma trận chỉ báo nhãn là dự đoán nhị phân (trung bình vi mô). Một biện pháp đánh giá khác để phân loại đa nhãn là trung bình vĩ mô, cho trọng lượng tương đương với việc phân loại của từng nhãn. import numpy as np import matplotlib.pyplot as plt from itertools import cycle from sklearn import svm, datasets from sklearn.metrics import roc_curve, auc from sklearn.model_selection import train_test_split from sklearn.preprocessing import label_binarize from sklearn.multiclass import OneVsRestClassifier from sklearn.metrics import roc_auc_score # Import some data to play with iris = datasets.load_iris() X = iris.data y = iris.target # Binarize the output y = label_binarize(y, classes=[0, 1, 2]) n_classes = y.shape[1] # Add noisy features to make the problem harder random_state = np.random.RandomState(0) n_samples, n_features = X.shape X = np.c_[X, random_state.randn(n_samples, 200 * n_features)] # shuffle and split training and test sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0) # Learn to predict each class against the other classifier = OneVsRestClassifier( svm.SVC(kernel="linear", probability=True, random_state=random_state) ) y_score = classifier.fit(X_train, y_train).decision_function(X_test) # Compute ROC curve and ROC area for each class fpr = dict() tpr = dict() roc_auc = dict() for i in range(n_classes): fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i]) roc_auc[i] = auc(fpr[i], tpr[i]) # Compute micro-average ROC curve and ROC area fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel()) roc_auc["micro"] = auc(fpr["micro"], tpr["micro"]) Biểu đồ của một đường cong ROC cho một lớp cụ thể plt.figure() lw = 2 plt.plot( fpr[2], tpr[2], color="darkorange", lw=lw, label="ROC curve (area = %0.2f)" % roc_auc[2], ) plt.plot([0, 1], [0, 1], color="navy", lw=lw, linestyle="--") plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel("False Positive Rate") plt.ylabel("True Positive Rate") plt.title("Receiver operating characteristic example") plt.legend(loc="lower right") plt.show() Cấu trúc đường cong ROC cho vấn đề đa lớpTính toán đường cong ROC trung bình vĩ mô và khu vực ROC # First aggregate all false positive rates all_fpr = np.unique(np.concatenate([fpr[i] for i in range(n_classes)])) # Then interpolate all ROC curves at this points mean_tpr = np.zeros_like(all_fpr) for i in range(n_classes): mean_tpr += np.interp(all_fpr, fpr[i], tpr[i]) # Finally average it and compute AUC mean_tpr /= n_classes fpr["macro"] = all_fpr tpr["macro"] = mean_tpr roc_auc["macro"] = auc(fpr["macro"], tpr["macro"]) # Plot all ROC curves plt.figure() plt.plot( fpr["micro"], tpr["micro"], label="micro-average ROC curve (area = {0:0.2f})".format(roc_auc["micro"]), color="deeppink", linestyle=":", linewidth=4, ) plt.plot( fpr["macro"], tpr["macro"], label="macro-average ROC curve (area = {0:0.2f})".format(roc_auc["macro"]), color="navy", linestyle=":", linewidth=4, ) colors = cycle(["aqua", "darkorange", "cornflowerblue"]) for i, color in zip(range(n_classes), colors): plt.plot( fpr[i], tpr[i], color=color, lw=lw, label="ROC curve of class {0} (area = {1:0.2f})".format(i, roc_auc[i]), ) plt.plot([0, 1], [0, 1], "k--", lw=lw) plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel("False Positive Rate") plt.ylabel("True Positive Rate") plt.title("Some extension of Receiver operating characteristic to multiclass") plt.legend(loc="lower right") plt.show() Khu vực theo ROC cho vấn đề đa lớpHàm y_prob = classifier.predict_proba(X_test) macro_roc_auc_ovo = roc_auc_score(y_test, y_prob, multi_class="ovo", average="macro") weighted_roc_auc_ovo = roc_auc_score( y_test, y_prob, multi_class="ovo", average="weighted" ) macro_roc_auc_ovr = roc_auc_score(y_test, y_prob, multi_class="ovr", average="macro") weighted_roc_auc_ovr = roc_auc_score( y_test, y_prob, multi_class="ovr", average="weighted" ) print( "One-vs-One ROC AUC scores:\n{:.6f} (macro),\n{:.6f} " "(weighted by prevalence)".format(macro_roc_auc_ovo, weighted_roc_auc_ovo) ) print( "One-vs-Rest ROC AUC scores:\n{:.6f} (macro),\n{:.6f} " "(weighted by prevalence)".format(macro_roc_auc_ovr, weighted_roc_auc_ovr) ) One-vs-One ROC AUC scores: 0.698586 (macro), 0.665839 (weighted by prevalence) One-vs-Rest ROC AUC scores: 0.698586 (macro), 0.665839 (weighted by prevalence) Tổng thời gian chạy của tập lệnh: (0 phút 0.190 giây) ( 0 minutes 0.190 seconds) Phòng trưng bày được tạo ra bởi Sphinx-Gallery Mục đích của đường cong ROC là gì?Một đường cong ROC (đường cong đặc tính vận hành máy thu) là một biểu đồ cho thấy hiệu suất của mô hình phân loại ở tất cả các ngưỡng phân loại. Đường cong này vẽ hai tham số: Tỷ lệ dương thực sự. Tỷ lệ dương tính giả.showing the performance of a classification model at all classification thresholds. This curve plots two parameters: True Positive Rate. False Positive Rate.
Làm thế nào để bạn sử dụng ROC trong Python?Làm thế nào để vẽ một đường cong ROC trong Python (từng bước).. Bước 1: Nhập các gói cần thiết.Đầu tiên, chúng tôi sẽ nhập các gói cần thiết để thực hiện hồi quy logistic trong Python: nhập pandas dưới dạng nhập khẩu PD NUMPY dưới dạng NP từ Sklearn..... Bước 2: Phù hợp với mô hình hồi quy logistic..... Bước 3: Vẽ đường cong ROC..... Bước 4: Tính AUC .. Bạn có thể làm gì với một đường cong ROC?Các đường cong ROC thường được sử dụng để hiển thị theo cách đồ họa kết nối/đánh đổi giữa độ nhạy và độ đặc hiệu lâm sàng cho mọi lần cắt có thể có thể cho xét nghiệm hoặc kết hợp các xét nghiệm.Ngoài ra, khu vực dưới đường cong ROC đưa ra một ý tưởng về lợi ích của việc sử dụng (các) bài kiểm tra được đề cập.to show in a graphical way the connection/trade-off between clinical sensitivity and specificity for every possible cut-off for a test or a combination of tests. In addition the area under the ROC curve gives an idea about the benefit of using the test(s) in question.
AUC Roc Curve Python là gì?Một số liệu phổ biến khác là AUC, khu vực dưới đường cong đặc tính vận hành máy thu (ROC).Đường cong đặc trưng hoạt động của Reciever biểu thị tốc độ dương (TP) thực sự so với tỷ lệ dương tính giả (FP) ở các ngưỡng phân loại khác nhau.area under the receiver operating characteristic (ROC) curve. The Reciever operating characteristic curve plots the true positive (TP) rate versus the false positive (FP) rate at different classification thresholds. |