Hướng dẫn smooth roc curve python - con trăn đường cong roc mịn

Bạn đang sử dụng các dự đoán ngưỡng để tạo đường cong ROC. Thay vào đó, bạn nên sử dụng các giá trị tin cậy ban đầu, nếu không bạn sẽ chỉ nhận được 1 điểm trung gian trên đường cong.

Dưới đây là một số dữ liệu ví dụ và đường cong ROC bạn sẽ nhận được.

y_test: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, ...
y_predicted: [1, 0.405, 0.601, 0.579, 0.03, 0.98, 0.06, 0.242, 0.379, 0.09, ...
y_predicted_thresholded: [1, 0, 1, 1, 0, 1, 0, 0, 0, 0, ...

Hướng dẫn smooth roc curve python - con trăn đường cong roc mịn

Tôi biết câu hỏi là hai năm tuổi và câu trả lời kỹ thuật đã được đưa ra trong các bình luận, nhưng một câu trả lời công phu hơn có thể giúp những người khác vẫn phải vật lộn với các khái niệm.

Đường cong ROC của OP sai vì anh ta đã sử dụng các giá trị dự đoán của các mô hình của mình thay vì xác suất.

Điều đó có nghĩa là gì?

Khi một mô hình được đào tạo, nó sẽ học được các mối quan hệ giữa các biến đầu vào và biến đầu ra. Đối với mỗi quan sát, mô hình được hiển thị, mô hình tìm hiểu mức độ có thể là một quan sát nhất định thuộc về một lớp nhất định. Khi mô hình được trình bày với dữ liệu thử nghiệm, nó sẽ đoán cho mỗi quan sát chưa từng thấy nó có thể thuộc về một lớp nhất định.

Làm thế nào để mô hình biết nếu một quan sát thuộc về một lớp? Trong quá trình thử nghiệm, mô hình nhận được một quan sát mà nó ước tính xác suất 51% thuộc về lớp X. Làm thế nào để đưa ra quyết định gắn nhãn là thuộc lớp X hay không? Nhà nghiên cứu sẽ đặt một ngưỡng nói với mô hình rằng tất cả các quan sát với xác suất dưới 50% phải được phân loại là y và tất cả những người trên phải được phân loại là X. Đôi khi nhà nghiên cứu muốn đặt ra một quy tắc chặt chẽ hơn vì họ quan tâm hơn đến chính xác Dự đoán một lớp nhất định như X thay vì cố gắng dự đoán tất cả chúng là tốt. During testing the model receives an observation for which it estimates a probability of 51% of belonging to Class X. How does take the decision to label as belonging to Class X or not? The researcher will set a threshold telling the model that all observations with a probability under 50% must be classified as Y and all those above must be classified as X. Sometimes the researcher wants to set a stricter rule because they're more interested in correctly predicting a given class like X rather than trying to predict all of them as well.

Vì vậy, mô hình được đào tạo của bạn đã ước tính xác suất cho từng quan sát của bạn, nhưng cuối cùng ngưỡng sẽ quyết định trong lớp quan sát của bạn sẽ được phân loại.

Vì sao vấn đề này?

Đường cong được tạo ra bởi ROC biểu thị một điểm cho từng tỷ lệ dương thực sự và tỷ lệ dương tính giả của mô hình của bạn ở các mức ngưỡng khác nhau. Điều này giúp nhà nghiên cứu thấy sự đánh đổi giữa FPR và TPR cho tất cả các cấp ngưỡng.

Vì vậy, khi bạn vượt qua các giá trị dự đoán thay vì xác suất dự đoán cho ROC của bạn, bạn sẽ chỉ có một điểm vì các giá trị này được tính toán bằng một ngưỡng cụ thể. Bởi vì điểm đó là TPR và FPR của mô hình của bạn cho một mức ngưỡng cụ thể.

Những gì bạn cần làm là sử dụng xác suất thay thế và để ngưỡng khác nhau.

Chạy mô hình của bạn như vậy:

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)

Khi tạo ma trận nhầm lẫn của bạn, bạn sẽ sử dụng các giá trị của mô hình của bạn

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'

Khi tạo đường cong ROC của bạn, bạn sẽ sử dụng xác suất

import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")

Smooth: Smooth một đường cong ROC: Smooth a ROC curve

Mô tả đối số sử dụng đối số Chi tiết Lỗi giá trị Tài liệu tham khảo Xem thêm ví dụ

Xem Nguồn: R/Smooth.R

Hàm này làm mịn một đường cong ROC của dự đoán số. Theo mặc định, việc làm mịn nhị phân được thực hiện, nhưng mật độ hoặc làm mịn tùy chỉnh được hỗ trợ.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

smooth(...)
## Default S3 method:
smooth(...)
## S3 method for class 'roc'
smooth(roc,
method=c("binormal", "density", "fitdistr", "logcondens",
"logcondens.smooth"), n=512, bw = "nrd0", density=NULL,
density.controls=density, density.cases=density,
start=NULL, start.controls=start, start.cases=start, 
reuse.auc=TRUE, reuse.ci=FALSE, ...)
## S3 method for class 'smooth.roc'
smooth(smooth.roc, ...)

roc, smooth.roc

Một đối tượng ROC ROC từ chức năng

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
0 hoặc đối tượng mịn.

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
2

Bin Binormal, mật độ, mật độ, Fit FitDistr ,, Logcondens ,,

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
3

Số lượng các điểm cách đều nhau trong đó đường cong được làm mịn sẽ được tính toán.

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
4

Nếu

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
5 và
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
6 và
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
7 không được cung cấp,
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
4 được chuyển sang
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 để xác định băng thông của mật độ có thể là một chuỗi ký tự ( Tên khớp với một hàm có tiền tố với BW BW. Được hỗ trợ) hoặc giá trị số, như được mô tả trong
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9. Mặc định là NRD0.

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
1

Nếu

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
5, giá trị số của mật độ (qua trục y) hoặc hàm trả về mật độ (chẳng hạn như
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9. Nếu
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
4, đối số
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
5 cho
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6. Thay vào đó, được sử dụng, nếu không
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 sẽ được truyền đến cả
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
6 và
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
7.

import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
2

Nếu

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
4, tùy chọn
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
4 đối số cho.
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
5 và
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
6 cho phép chỉ định các phân phối khác nhau cho các điều khiển và trường hợp.

import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
7

Nếu

import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
8 (mặc định cho việc tái sử dụng.AUC) và các đối tượng ROC ROC có chứa các trường AUC AUC hoặc hoặc CI CI, hãy sử dụng lại các thông số kỹ thuật này để tái tạo
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
9 hoặc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
0 trên đường cong ROC được làm mịn với các tham số ban đầu. Nếu
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
1, đối tượng được trả về sẽ không chứa các trường AUC AUC hoặc CI CI. Hiện tại không thể xác định lại các tùy chọn
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
9 và
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
0: Bạn cần gọi
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
9 hoặc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
0 sau đó cho điều đó.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
6

Các đối số tiếp theo được truyền cho hoặc từ các phương pháp khác, và đặc biệt là

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 (chỉ
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
8,
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
9 và
smooth(...)
## Default S3 method:
smooth(...)
## S3 method for class 'roc'
smooth(roc,
method=c("binormal", "density", "fitdistr", "logcondens",
"logcondens.smooth"), n=512, bw = "nrd0", density=NULL,
density.controls=density, density.cases=density,
start=NULL, start.controls=start, start.cases=start, 
reuse.auc=TRUE, reuse.ci=FALSE, ...)
## S3 method for class 'smooth.roc'
smooth(smooth.roc, ...)
0, cộng với
smooth(...)
## Default S3 method:
smooth(...)
## S3 method for class 'roc'
smooth(roc,
method=c("binormal", "density", "fitdistr", "logcondens",
"logcondens.smooth"), n=512, bw = "nrd0", density=NULL,
density.controls=density, density.cases=density,
start=NULL, start.controls=start, start.cases=start, 
reuse.auc=TRUE, reuse.ci=FALSE, ...)
## S3 method for class 'smooth.roc'
smooth(smooth.roc, ...)
1 để tương thích với S+) và
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6.

Nếu

smooth(...)
## Default S3 method:
smooth(...)
## S3 method for class 'roc'
smooth(roc,
method=c("binormal", "density", "fitdistr", "logcondens",
"logcondens.smooth"), n=512, bw = "nrd0", density=NULL,
density.controls=density, density.cases=density,
start=NULL, start.controls=start, start.cases=start, 
reuse.auc=TRUE, reuse.ci=FALSE, ...)
## S3 method for class 'smooth.roc'
smooth(smooth.roc, ...)
3, một mô hình tuyến tính được trang bị cho các lượng tử của độ nhạy và độ đặc hiệu. Độ nhạy và độ đặc hiệu được làm mịn sau đó được tạo ra từ mô hình này trên
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
3 điểm. Cách tiếp cận đơn giản này đã được tìm thấy để hoạt động tốt cho hầu hết các đường cong ROC, nhưng nó có thể tạo ra các mịn trong một số tình huống (xem trong Hanley (1988)).

Với

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
5, hàm
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 được sử dụng để tạo ra mật độ hạt nhân mịn của các quan sát điều khiển và trường hợp như được mô tả bởi Zhou et al. (1997), trừ khi
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
6 hoặc
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
7 được cung cấp trực tiếp.
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
4 có thể được đưa ra để chỉ định băng thông để sử dụng với
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9. Nó có thể là một giá trị số hoặc một chuỗi ký tự (Hồi NRD0 ,, NRD ,, UCV ,, Trong trường hợp chuỗi ký tự, toàn bộ dữ liệu dự đoán được sử dụng để xác định giá trị số sẽ sử dụng trên cả hai điều khiển và trường hợp. Tùy thuộc vào dữ liệu của bạn, có thể là một ý tưởng tốt để chỉ định đối số
smooth(...)
## Default S3 method:
smooth(...)
## S3 method for class 'roc'
smooth(roc,
method=c("binormal", "density", "fitdistr", "logcondens",
"logcondens.smooth"), n=512, bw = "nrd0", density=NULL,
density.controls=density, density.cases=density,
start=NULL, start.controls=start, start.cases=start, 
reuse.auc=TRUE, reuse.ci=FALSE, ...)
## S3 method for class 'smooth.roc'
smooth(smooth.roc, ...)
0 cho
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9. Theo mặc định, người Gaussian, được sử dụng, nhưng Epanechnikov ,, hình chữ nhật, hình chữ nhật, hình tam giác, hình tam giác, Bi Weight ,, Cos Cosine và và Opt Optcosine được hỗ trợ. Vì tất cả các hạt nhân là đối xứng, nó có thể giúp bình thường hóa dữ liệu trước tiên (nghĩa là trước khi gọi ____10), ví dụ với chuẩn hóa lượng tử hóa:

Ngoài ra,

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 có thể là một hàm phải trả về một vectơ số có mật độ trên trục Y hoặc một danh sách với một mục y y như hàm
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9. Nó phải chấp nhận đầu vào sau:

Điều quan trọng là phải tôn vinh

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
3,
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
7 và
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
8 để có mật độ được đánh giá trên cùng một điểm đối với các điều khiển và trường hợp. Không làm như vậy và trở lại mật độ có độ dài khác nhau sẽ tạo ra lỗi. Đó cũng là một ý tưởng tốt để sử dụng một tham số làm mịn không đổi (chẳng hạn như
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
4), đặc biệt là khi các điều khiển và trường hợp có số lượng quan sát khác nhau, để tránh tạo ra mật độ mượt mà hơn hoặc khó khăn hơn.

Nếu

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
4, hàm
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6 từ gói khối được sử dụng để phù hợp với các tham số cho hàm mật độ
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 với các tham số bắt đầu tùy chọn
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
4. Hàm mật độ được trang bị riêng biệt trong điều khiển (
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
6,
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
5) và quan sát trường hợp (
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
7,
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
6).
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 có thể là một trong các giá trị ký tự được phép bởi
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6 hoặc hàm mật độ (chẳng hạn như
Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
0,
Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
1, ...).MASS package is employed to fit parameters for the density function
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 with optionnal start parameters
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
4. The density function are fitted separately in control (
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
6,
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
5) and case observations (
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
7,
import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
6).
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 can be one of the character values allowed by
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6 or a density function (such as
Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
0,
Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
1, ...).

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
2 và
Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
3 Sử dụng gói logcondens để tạo ra ước tính mật độ log-concave không được làm mịn hoặc làm mịn (tương ứng) của điều khiển và quan sát trường hợp với hàm logconroc.logcondens package to generate a non smoothed or smoothed (respectively) log-concave density estimate of of the control and case observation with the logConROC function.

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
4 buộc sử dụng hàm
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
1 trong gói thống kê, do đó mã khác dựa vào
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
1 sẽ tiếp tục hoạt động bình thường.stats package, so that other code relying on
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
1 should continue to function normally.

Các đường cong ROC được làm mịn có thể được truyền lại để làm mịn trở lại. Trong trường hợp này, việc làm mịn không được áp dụng lại trên đường cong ROC được làm mịn nhưng đối tượng ROC ROC ban đầu sẽ được sử dụng lại.

Lưu ý rằng một đường cong

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
7 không có ngưỡng.

Một danh sách các lớp học mịn.

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
8

Các độ nhạy được làm mịn xác định đường cong ROC.

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
9

Các đặc tính làm mịn xác định đường cong ROC.

roc, smooth.roc0

Nếu độ nhạy, độ đặc hiệu và AUC được báo cáo theo phần trăm, như được định nghĩa trong đối số.

roc, smooth.roc1

hướng so sánh, như được định nghĩa trong đối số.

roc, smooth.roc2

làm thế nào các chức năng được gọi. Xem roc, smooth.roc3 để biết thêm chi tiết.

roc, smooth.roc4

Một danh sách các đối số được sử dụng cho việc làm mịn. Sẽ phục vụ để áp dụng làm mịn một lần nữa trong các hoạt động bootstrap tiếp theo.

import scikitplot as skplt
plot = skplt.metrics.plot_roc(y_test, knn_y_proba)
plt.title("ROC Curves - K-Nearest Neighbors")
9

Nếu đường cong ROC ban đầu chứa AUC, nó sẽ được tính toán lại trên ROC được làm mịn.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
0

Nếu đường cong ROC ban đầu chứa CI, nó sẽ được tính toán lại trên ROC được làm mịn.

roc, smooth.roc7

Chỉ với

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
4: kết quả của hàm
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6 của khối lượng cho các điều khiển và trường hợp, với một mục bổ sung của Densfun Densfun cho biết hàm mật độ, nếu có thể là ký tự.MASS's
from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6 function for controls and cases, with an additional “densfun” item indicating the density function, if possible as character.

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
00

chỉ với

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
2 và
Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)
3: kết quả của chức năng LogConroc của LogCondens.logcondens's logConROC function.

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
03

chỉ với

smooth(...)
## Default S3 method:
smooth(...)
## S3 method for class 'roc'
smooth(roc,
method=c("binormal", "density", "fitdistr", "logcondens",
"logcondens.smooth"), n=512, bw = "nrd0", density=NULL,
density.controls=density, density.cases=density,
start=NULL, start.controls=start, start.cases=start, 
reuse.auc=TRUE, reuse.ci=FALSE, ...)
## S3 method for class 'smooth.roc'
smooth(smooth.roc, ...)
3: mô hình tuyến tính từ
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
05 được sử dụng để làm mịn đường cong ROC.

Thuộc tính

Ngoài ra, đối tượng

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
0 ban đầu được lưu trữ dưới dạng thuộc tính ROC ROC.

Thông báo Chức năng 'mật độ' phải trả về một vectơ số hoặc một danh sách có mục 'y'. sẽ được hiển thị nếu hàm

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 không trả về đầu ra hợp lệ. Thông điệp chiều dài của 'mật độ.controls' và 'mật độ.case' khác nhau. sẽ được hiển thị nếu giá trị trả về khác nhau về chiều dài.

Làm mịn nhị phân không thể làm mịn đường cong ROC được xác định chỉ bằng một điểm. Bất kỳ nỗ lực nào như vậy sẽ thất bại với lỗi đường cong ROC không thể vượt qua (không đủ điểm).

Nếu đường cong ROC mịn được tạo bởi

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
0 với các đối số số
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
6 và
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
7, nó không thể được làm mịn và lỗi không thể làm mịn một đường cong ROC được tạo trực tiếp với mật độ số 'và' mật độ.case '. được sản xuất.

Phương pháp làm mịn

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6 và
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
9 yêu cầu số
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
13. Nếu đường cong ROC thành mịn được tạo ra với một yếu tố được đặt hàng, chỉ có thể làm mịn nhị phân có thể được áp dụng và thông điệp các đường cong ROC của các dự đoán theo thứ tự chỉ có thể được làm mịn khi làm mịn nhị phân. được hiển thị khác.

Các phương thức

from mlxtend.plotting import plot_confusion_matrix
fig, ax = plot_confusion_matrix(conf_mat=confusion_matrix(y_test,knn_y_model),
                                show_absolute=True,show_normed=True,colorbar=True)
plt.title("Confusion matrix - KNN")
plt.ylabel('True label')
plt.xlabel('Predicted label'
6,
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
00 và
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
16 yêu cầu các gói bổ sung. Nếu không có sẵn, thông báo sau sẽ được hiển thị với lệnh bắt buộc để cài đặt gói: Gói gói? Không có sẵn, được yêu cầu với Phương thức = '?'. Vui lòng cài đặt nó với 'install.packages ("?")'. "

James E. Hanley (1988) Sự mạnh mẽ của các giả định của Bin Binormal được sử dụng trong các đường cong ROC phù hợp. Ra quyết định y tế 8, 197 Từ203.8, 197–203.

Lutz Duembgen, Kaspar Rufibach (2011) Logcondens: Các tính toán liên quan đến ước tính mật độ log-concave đơn biến. Tạp chí phần mềm thống kê, 39, 1 trận28. URL: jstatsoft.org/v39/i06.39, 1–28. URL: jstatsoft.org/v39/i06.

Xavier Robin, Natacha Turck, Alexandre Hainard, et al. . BMC Bioinformatics, 7, 77. doi: doi: 10.1186/1471-2105-12-77.7, 77. DOI: doi: 10.1186/1471-2105-12-77.

Kaspar Rufibach (2011) Một công cụ ước tính đường cong ROC trơn tru dựa trên ước tính mật độ log-concave. Tạp chí quốc tế về sinh học, 8, được chấp nhận. Doi: doi: 10.1515/1557-4679.1378. ARXIV: 1103.1787.8, accepted. DOI: doi: 10.1515/1557-4679.1378. arXiv: 1103.1787.

William N. Venables, Brian D. Ripley (2002). Thống kê ứng dụng hiện đại với Siêu. New York, Springer. Sách Google.

Kelly H. Zou, W. J. Hall và David E. Shapiro (1997) Các đường cong đặc tính hoạt động của máy thu không tham số mịn (ROC) cho các xét nghiệm chẩn đoán liên tục. Thống kê trong Y học 18, 2143 Từ2156. Doi: doi: 10.1002/(sici) 1097-0258 (19971015) 16: 193.0.co; 2-3.18, 2143–2156. DOI: doi: 10.1002/(SICI)1097-0258(19971015)16:19<2143::AID-SIM655>3.0.CO;2-3.

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn_model = knn.fit(X_train,y_train)
#Use the values for your confusion matrix
knn_y_model = knn_model.predict(X=X_test)
# Use the probabilities for your ROC and Precision-recall curves
knn_y_proba = knn_model.predict_proba(X=X_test)
0

Các gói cran Mass và logcondens được sử dụng trong chức năng này.MASS and logcondens employed in this function.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

data(aSAH)

##  Basic example
rocobj <- roc(aSAH$outcome, aSAH$s100b)
smooth(rocobj)
# or directly with roc()
roc(aSAH$outcome, aSAH$s100b, smooth=TRUE)

# plotting
plot(rocobj)
rs <- smooth(rocobj, method="binormal")
plot(rs, add=TRUE, col="green")
rs2 <- smooth(rocobj, method="density")
plot(rs2, add=TRUE, col="blue")
rs3 <- smooth(rocobj, method="fitdistr", density="lognormal")
plot(rs3, add=TRUE, col="magenta")
if (requireNamespace("logcondens")) {
rs4 <- smooth(rocobj, method="logcondens")
plot(rs4, add=TRUE, col="brown")
rs5 <- smooth(rocobj, method="logcondens.smooth")
plot(rs5, add=TRUE, col="orange")
}
legend("bottomright", legend=c("Empirical", "Binormal", "Density", "Log-normal",
                               "Log-concave density", "Smoothed log-concave density"),
       col=c("black", "green", "blue", "magenta", "brown", "orange"), lwd=2)

## Advanced smoothing

# if we know the distributions are normal with sd=0.1 and an unknown mean:
smooth(rocobj, method="fitdistr", density=dnorm, start=list(mean=1), sd=.1)
# different distibutions for controls and cases:
smooth(rocobj, method="fitdistr", density.controls="normal", density.cases="lognormal")

# with densities
bw <- bw.nrd0(rocobj$predictor)
density.controls <- density(rocobj$controls, from=min(rocobj$predictor) - 3 * bw,
                            to=max(rocobj$predictor) + 3*bw, bw=bw, kernel="gaussian")
density.cases <- density(rocobj$cases, from=min(rocobj$predictor) - 3 * bw,
                            to=max(rocobj$predictor) + 3*bw, bw=bw, kernel="gaussian")
smooth(rocobj, method="density", density.controls=density.controls$y, 
       density.cases=density.cases$y)
# which is roughly what is done by a simple:
smooth(rocobj, method="density")

## Not run: 
## Smoothing artificial ROC curves

rand.unif <- runif(1000, -1, 1)
rand.exp <- rexp(1000)
rand.norm <- 
rnorm(1000)

# two normals
roc.norm <- roc(controls=rnorm(1000), cases=rnorm(1000)+1, plot=TRUE)
plot(smooth(roc.norm), col="green", lwd=1, add=TRUE)
plot(smooth(roc.norm, method="density"), col="red", lwd=1, add=TRUE)
plot(smooth(roc.norm, method="fitdistr"), col="blue", lwd=1, add=TRUE)
if (requireNamespace("logcondens")) {
plot(smooth(roc.norm, method="logcondens"), col="brown", lwd=1, add=TRUE)
plot(smooth(roc.norm, method="logcondens.smooth"), col="orange", lwd=1, add=TRUE)
}
legend("bottomright", legend=c("empirical", "binormal", "density", "fitdistr",
                               "logcondens", "logcondens.smooth"), 
       col=c(par("fg"), "green", "red", "blue", "brown", "orange"), lwd=c(2, 1, 1, 1))
       
# deviation from the normality
roc.norm.exp <- roc(controls=rnorm(1000), cases=rexp(1000), plot=TRUE)
plot(smooth(roc.norm.exp), col="green", lwd=1, add=TRUE)
plot(smooth(roc.norm.exp, method="density"), col="red", lwd=1, add=TRUE)
# Wrong fitdistr: normality assumed by default
plot(smooth(roc.norm.exp, method="fitdistr"), col="blue", lwd=1, add=TRUE)
# Correct fitdistr
plot(smooth(roc.norm.exp, method="fitdistr", density.controls="normal",
            density.cases="exponential"), col="purple", lwd=1, add=TRUE)
if (requireNamespace("logcondens")) {
plot(smooth(roc.norm.exp, method="logcondens"), col="brown", lwd=1, add=TRUE)
plot(smooth(roc.norm.exp, method="logcondens.smooth"), col="orange", lwd=1, add=TRUE)
}
legend("bottomright", legend=c("empirical", "binormal", "density",
                               "wrong fitdistr", "correct fitdistr",
                               "logcondens", "logcondens.smooth"),
       col=c(par("fg"), "green", "red", "blue", "purple", "brown", "orange"), lwd=c(2, 1, 1, 1, 1))

# large deviation from the normality
roc.unif.exp <- roc(controls=runif(1000, 2, 3), cases=rexp(1000)+2, plot=TRUE)
plot(smooth(roc.unif.exp), col="green", lwd=1, add=TRUE)
plot(smooth(roc.unif.exp, method="density"), col="red", lwd=1, add=TRUE)
plot(smooth(roc.unif.exp, method="density", bw="ucv"), col="magenta", lwd=1, add=TRUE)
# Wrong fitdistr: normality assumed by default (uniform distributions not handled)
plot(smooth(roc.unif.exp, method="fitdistr"), col="blue", lwd=1, add=TRUE)
if (requireNamespace("logcondens")) {
plot(smooth(roc.unif.exp, method="logcondens"), col="brown", lwd=1, add=TRUE)
plot(smooth(roc.unif.exp, method="logcondens.smooth"), col="orange", lwd=1, add=TRUE)
}
legend("bottomright", legend=c("empirical", "binormal", "density",
                               "density ucv", "wrong fitdistr",
                               "logcondens", "logcondens.smooth"),
       col=c(par("fg"), "green", "red", "magenta", "blue", "brown", "orange"), lwd=c(2, 1, 1, 1, 1))

## End(Not run)

# 2 uniform distributions with a custom density function
unif.density <- function(x, n, from, to, bw, kernel, ...) {
  smooth.x <- seq(from=from, to=to, length.out=n)
  smooth.y <- dunif(smooth.x, min=min(x), max=max(x))
  return(smooth.y)
}
roc.unif <- roc(controls=runif(1000, -1, 1), cases=runif(1000, 0, 2), plot=TRUE)
s <- smooth(roc.unif, method="density", density=unif.density)
plot(roc.unif)
plot(s, add=TRUE, col="grey")

## Not run: 
# you can bootstrap a ROC curve smoothed with a density function:
ci(s, boot.n=100)

## End(Not run)

Type 'citation("pROC")' for a citation.

Attaching package:pROCThe following objects are masked frompackage:stats:

    cov, smooth, var

Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
smooth.roc(roc = rocobj)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Setting levels: control = Good, case = Poor
Setting direction: controls < cases

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b,     smooth = TRUE)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal 
Area under the curve: 0.74
Loading required namespace: MASS
Loading required namespace: logcondens

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density = dnorm,     start = list(mean = 1), sd = 0.1)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.9474
Warning messages:
1: In stats::optim(x = c(0.13, 0.14, 0.1, 0.04, 0.47, 0.18, 0.1, 0.1,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly
2: In stats::optim(x = c(0.13, 0.1, 0.16, 0.12, 0.44, 0.71, 0.49, 0.07,  :
  one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly

Call:
smooth.roc(roc = rocobj, method = "fitdistr", density.controls = "normal",     density.cases = "lognormal")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: fitdistr 
Area under the curve: 0.6546

Call:
smooth.roc(roc = rocobj, method = "density", density.controls = density.controls$y,     density.cases = density.cases$y)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244

Call:
smooth.roc(roc = rocobj, method = "density")

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: density (bandwidth: nrd0; adjust: 1)
Area under the curve: 0.7244
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
95% CI: 0.874-0.8774 (100 stratified bootstrap replicates)

Tài liệu Proc được xây dựng vào ngày 5 tháng 9 năm 2021, 5:34 chiều