Hướng dẫn how do you plot confusion matrix with labels in python? - làm thế nào để bạn vẽ ma trận nhầm lẫn với các nhãn trong python?
Show Sử dụng https://gist.github.com/hitvoice/36CF44689065CA9B927431546381A3F7 Lưu ý rằng nếu bạn sử dụng Không dùng nữa: Hàm Âm mưu ma trận nhầm lẫn.
Đọc thêm trong Hướng dẫn sử dụng.User Guide. Tham số: Phiên bản của EDOPATORESTimator:estimatorestimator instancePhân loại được trang bị hoặc được trang bị Giá trị đầu vào. Y_TrueArray giống như hình dạng (n_samples,)array-like of shape (n_samples,)Giá trị mục tiêu. LabelsArray giống như hình dạng (n_ classes,), mặc định = không cóarray-like of shape (n_classes,), default=NoneDanh sách các nhãn để lập chỉ mục ma trận. Điều này có thể được sử dụng để sắp xếp lại hoặc chọn một tập hợp con của nhãn. Nếu >>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import plot_confusion_matrix >>> from sklearn.model_selection import train_test_split >>> from sklearn.svm import SVC >>> X, y = make_classification(random_state=0) >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, random_state=0) >>> clf = SVC(random_state=0) >>> clf.fit(X_train, y_train) SVC(random_state=0) >>> plot_confusion_matrix(clf, X_test, y_test) >>> plt.show()0 được sử dụng theo thứ tự được sắp xếp.sample_weightarray giống như hình dạng (n_samples,), mặc định = không cóarray-like of shape (n_samples,), default=None Trọng lượng mẫu. Bình thường hóa {’true{‘true’, ‘pred’, ‘all’}, default=NoneĐể bình thường hóa hiển thị số đếm trong ma trận: display_labelsarray giống như hình dạng (n_ classes,), mặc định = khôngarray-like of shape (n_classes,), default=None Tên mục tiêu được sử dụng để vẽ đồ thị. Theo mặc định, >>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import plot_confusion_matrix >>> from sklearn.model_selection import train_test_split >>> from sklearn.svm import SVC >>> X, y = make_classification(random_state=0) >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, random_state=0) >>> clf = SVC(random_state=0) >>> clf.fit(X_train, y_train) SVC(random_state=0) >>> plot_confusion_matrix(clf, X_test, y_test) >>> plt.show()5 sẽ được sử dụng nếu được xác định, nếu không các nhãn duy nhất của y_true và >>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import plot_confusion_matrix >>> from sklearn.model_selection import train_test_split >>> from sklearn.svm import SVC >>> X, y = make_classification(random_state=0) >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, random_state=0) >>> clf = SVC(random_state=0) >>> clf.fit(X_train, y_train) SVC(random_state=0) >>> plot_confusion_matrix(clf, X_test, y_test) >>> plt.show()0 sẽ được sử dụng.bao gồm_valuesbool, mặc định = truebool, default=True Bao gồm các giá trị trong ma trận nhầm lẫn. Xoay của nhãn XTICK. value_formatstr, mặc định = khôngstr, default=NoneĐịnh dạng đặc tả cho các giá trị trong ma trận nhầm lẫn. Nếu Colormap được công nhận bởi matplotlib. AXMATPLOTLIB AXES, DEFAULT = Không cómatplotlib Axes, default=NoneTrục đối tượng để vẽ trên. Nếu Có hay không thêm một colorbar vào cốt truyện. Mới trong phiên bản 0.24. Returns:displayrocket_r 0:displayrocket_r 0Đối tượng lưu trữ các giá trị tính toán. Ví dụ >>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import plot_confusion_matrix >>> from sklearn.model_selection import train_test_split >>> from sklearn.svm import SVC >>> X, y = make_classification(random_state=0) >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, random_state=0) >>> clf = SVC(random_state=0) >>> clf.fit(X_train, y_train) SVC(random_state=0) >>> plot_confusion_matrix(clf, X_test, y_test) >>> plt.show() Làm thế nào để bạn vẽ nhãn cho ma trận nhầm lẫn?Tóm tắt: Cách tốt nhất để vẽ một ma trận nhầm lẫn với các nhãn, là sử dụng đối tượng InfusionMatrixDisplay từ mô -đun sklearn.metrics. Một cách đơn giản và thanh lịch khác là sử dụng Seaborn. hàm nhiệt ().use the ConfusionMatrixDisplay object from the sklearn. metrics module. Another simple and elegant way is to use the seaborn. heatmap() function.
Làm cách nào để tìm nhãn cho ma trận nhầm lẫn trong Python?@Revolucionformonica Khi bạn nhận được sự bối rối_matrix, các nhãn đánh dấu trục X là nhãn 1, 0 và y trục là 0, 1 (theo giá trị trục tăng).Nếu trình phân loại là CLF, bạn có thể nhận được thứ tự lớp bằng CLF.the X axis tick labels are 1, 0 and Y axis tick labels are 0, 1 (in the axis values increasing order). If the classifier is clf , you can get the class order by clf.
Làm thế nào để bạn vẽ một ma trận nhầm lẫn cho một mô hình trong Python?Ma trận nhầm lẫn sơ đồ cho các lớp nhị phân với nhãn bạn cần tạo danh sách các nhãn và chuyển đổi nó thành một mảng bằng NP.Phương pháp Asarray () có hình 2,2.Sau đó, mảng nhãn này phải được chuyển đến Annot thuộc tính.Điều này sẽ vạch ra ma trận nhầm lẫn với chú thích nhãn.create a list of the labels and convert it into an array using the np. asarray() method with shape 2,2 . Then, this array of labels must be passed to the attribute annot . This will plot the confusion matrix with the labels annotation.
Làm thế nào để bạn vẽ một ma trận nhầm lẫn trong Python bằng cách sử dụng Seaborn?Hiển thị ma trận nhầm lẫn bằng cách sử dụng Seaborn để hoàn thành nhiệm vụ này, bạn sẽ cần thêm hai thành phần sau vào mã: Nhập Seaborn dưới dạng SN.Sn.HeatMap (Confusion_Matrix, Annot = true)import seaborn as sn. sn. heatmap(confusion_matrix, annot=True) |