Làm cách nào để tìm điểm roc auc của tôi trong python?

Có thể họ đã nói với bạn rằng Diện tích dưới đường cong ROC không thể được tính cho biến mục tiêu liên tục. Vâng, họ đã sai. Đây là cách để làm điều đó trong Python

[Hình của tác giả]

Bạn làm việc với tư cách là nhà khoa học dữ liệu cho một công ty đấu giá và sếp của bạn yêu cầu bạn xây dựng một mô hình để dự đoán giá búa [i. e. giá bán cuối cùng] của các mặt hàng được bán. Một mô hình như vậy sẽ phục vụ hai mục đích

  1. đặt giá thầu mở có ý nghĩa cho từng mặt hàng;
  2. đặt các mặt hàng đắt nhất vào các khoảng thời gian định kỳ trong cuộc đấu giá. Bằng cách này, bạn sẽ giữ được sự chú ý của khán giả

Vì bạn muốn dự đoán một giá trị điểm [bằng đô la], nên bạn quyết định sử dụng mô hình hồi quy [ví dụ:

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
7]. Bây giờ, làm thế nào để bạn đánh giá hiệu suất của mô hình của bạn?

Hãy xem hộp công cụ số liệu của Scikit cho các mô hình hồi quy

Số liệu hồi quy Scikit-learning [Link]

Tất cả các số liệu này tìm cách định lượng mức độ dự đoán của mô hình so với các giá trị thực tế. Trên thực tế, nếu bạn nhìn vào công thức của họ, bạn sẽ luôn tìm thấy đại lượng này

Sự khác biệt giữa giá trị thực tế và giá trị được dự đoán bởi mô hình. [Hình của tác giả]

Nói cách khác, những số liệu này rất phù hợp để đánh giá khả năng tiến gần đến giá thực [mục tiêu thứ nhất]. Nhưng chúng vô dụng khi đánh giá mục tiêu thứ 2, đó là khả năng xếp hạng các mặt hàng từ đắt nhất đến rẻ nhất

Muốn có một ví dụ?

y_true = [1000.0, 2000.0, 3000.0, 4000.0, 5000.0]
y_pred = [1100.0, 1300.0, 4000.0, 4800.0, 5200.0]

đồ họa,

So sánh giá trị thực và giá trị dự đoán trong bài toán hồi quy. [Hình của tác giả]

Nếu chúng tôi lấy

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
8, chúng tôi nhận được 560 đô la, điều này có lẽ không tốt lắm. Tuy nhiên, bảng xếp hạng là hoàn hảo. Điều này có nghĩa là mô hình hoàn toàn có khả năng nhận ra mặt hàng nào sẽ được bán đấu giá với giá cao hơn

Đây là một thông tin rất quan trọng về mô hình của chúng tôi, mà chúng tôi sẽ không cảm nhận được từ các số liệu hồi quy khác. Nhưng làm thế nào chúng ta có thể đo lường khả năng xếp hạng của một mô hình hồi quy?

Số liệu phổ biến nhất để đánh giá khả năng xếp hạng của một mô hình dự đoán là

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9. Vì vậy, hãy thử tính toán nó với dữ liệu của chúng tôi…

[Hình của tác giả]

chúng tôi nhận được một lỗi

Điều này xảy ra vì ________ 19 chỉ hoạt động với các mô hình phân loại, một lớp so với phần còn lại [“ovr”] hoặc một so với một [“ovo”]. Scikit-learning hy vọng sẽ tìm thấy các lớp rời rạc thành

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
1 và
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
2, trong khi chúng tôi chuyển các giá trị liên tục

Vì lý do này, chúng ta cần mở rộng khái niệm

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
3 sang các bài toán hồi quy. Chúng tôi sẽ gọi một số liệu như vậy là
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0. Trong đoạn tiếp theo, chúng ta sẽ hiểu làm thế nào để tính toán nó

Đang tìm kiếm “regression_roc_auc_score”

Theo trực giác,

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0 sẽ có các thuộc tính sau

  • Chính xác như
    from sklearn.datasets import fetch_california_housing
    from sklearn.model_selection import train_test_split
    X, y = fetch_california_housing[return_X_y = True, as_frame = True]
    y *= 100000
    X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
    9, nó phải được giới hạn giữa 0 [xếp hạng tồi tệ nhất có thể] và 1 [xếp hạng tốt nhất có thể], với 0. 5 biểu thị xếp hạng ngẫu nhiên
  • Khi biến mục tiêu là nhị phân,
    from sklearn.datasets import fetch_california_housing
    from sklearn.model_selection import train_test_split
    X, y = fetch_california_housing[return_X_y = True, as_frame = True]
    y *= 100000
    X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
    0 phải cho kết quả giống như của
    from sklearn.datasets import fetch_california_housing
    from sklearn.model_selection import train_test_split
    X, y = fetch_california_housing[return_X_y = True, as_frame = True]
    y *= 100000
    X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
    9 [theo cách này, số liệu này sẽ là tổng quát của
    from sklearn.datasets import fetch_california_housing
    from sklearn.model_selection import train_test_split
    X, y = fetch_california_housing[return_X_y = True, as_frame = True]
    y *= 100000
    X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
    9]

Bây giờ, làm thế nào để có được số liệu chúng tôi đang tìm kiếm?

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9 được định nghĩa là khu vực bên dưới đường cong ROC, là đường cong có Tỷ lệ dương tính giả trên trục x và Tỷ lệ dương tính thật trên trục y ở tất cả các ngưỡng phân loại. Nhưng không thể tính FPR và TPR cho các phương pháp hồi quy, vì vậy chúng tôi không thể đi theo con đường này

May mắn cho chúng ta, có một định nghĩa thay thế. Trên thực tế, theo Wikipedia,

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9 trùng khớp với “xác suất mà một bộ phân loại sẽ xếp hạng một trường hợp tích cực được chọn ngẫu nhiên cao hơn một trường hợp tiêu cực được chọn ngẫu nhiên”

Nói cách khác, nếu chúng ta lấy hai quan sát a và b bất kỳ sao cho a > b, thì

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
3 bằng với xác suất mà mô hình của chúng ta thực sự xếp hạng a cao hơn b

Định nghĩa này hữu ích hơn nhiều đối với chúng tôi, bởi vì nó cũng có ý nghĩa đối với hồi quy [thực tế a và b có thể không bị giới hạn ở 0 hoặc 1, chúng có thể nhận bất kỳ giá trị liên tục nào];

Hơn nữa, tính toán

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9 bây giờ dễ dàng hơn nhiều. Trên thực tế, nó rút gọn lại để xem xét từng cặp mục có thể có a và b, sao cho a > b, và đếm xem giá trị mà mô hình của chúng ta dự đoán cho a thực tế cao hơn bao nhiêu lần so với giá trị được dự đoán cho b [các mối quan hệ cuối cùng sẽ là . Sau đó,
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9 chỉ đơn giản là số lần thành công chia cho tổng số cặp

Trong Python, đây sẽ là

Mã Python cho ngây thơ_roc_auc_score. [Mã của tác giả]

Để đảm bảo rằng định nghĩa do Wikipedia cung cấp là đáng tin cậy, hãy so sánh hàm

from sklearn.dummy import DummyRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, median_absolute_error, roc_auc_score, r2_score, explained_variance_score
modelnames = [
‘DummyRegressor[]’,
‘KNeighborsRegressor[]’,
‘LinearRegression[]’,
‘SVR[]’,
‘MLPRegressor[hidden_layer_sizes = [16, 16]]’,
‘DecisionTreeRegressor[]’,
‘GradientBoostingRegressor[]’,
‘XGBRegressor[]’,
‘CatBoostRegressor[]’
]
metricnames = [
‘mean_absolute_error’,
‘median_absolute_error’,
‘r2_score’,
‘explained_variance_score’,
‘regression_roc_auc_score’
]
metrics = pd.DataFrame[index = modelnames, columns = metricnames]for modelname in modelnames:
model = eval[modelname]
pred_test = model.fit[X_train, y_train].predict[X_test]
for metricname in metricnames:
metrics.loc[modelname, metricname] = eval[f'{metricname}[y_test, pred_test]']
1 của chúng ta với kết quả của Scikit-learning

[Hình của tác giả]

Tuyệt quá

Như đã nói ở trên— không giống như

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9 của Scikit-learn— phiên bản này cũng hoạt động với các biến mục tiêu liên tục. Thử một lần đi

[Hình của tác giả]

Đầu ra là chính xác những gì chúng tôi mong đợi. Xếp hạng là hoàn hảo và do đó

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
9 bằng 1

Từ ngây thơ đến bootstrap

Mọi thứ trông tuyệt vời, nhưng cách triển khai ở trên hơi ngây thơ. Trên thực tế,

from sklearn.dummy import DummyRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, median_absolute_error, roc_auc_score, r2_score, explained_variance_score
modelnames = [
‘DummyRegressor[]’,
‘KNeighborsRegressor[]’,
‘LinearRegression[]’,
‘SVR[]’,
‘MLPRegressor[hidden_layer_sizes = [16, 16]]’,
‘DecisionTreeRegressor[]’,
‘GradientBoostingRegressor[]’,
‘XGBRegressor[]’,
‘CatBoostRegressor[]’
]
metricnames = [
‘mean_absolute_error’,
‘median_absolute_error’,
‘r2_score’,
‘explained_variance_score’,
‘regression_roc_auc_score’
]
metrics = pd.DataFrame[index = modelnames, columns = metricnames]for modelname in modelnames:
model = eval[modelname]
pred_test = model.fit[X_train, y_train].predict[X_test]
for metricname in metricnames:
metrics.loc[modelname, metricname] = eval[f'{metricname}[y_test, pred_test]']
1 đánh giá mọi cặp quan sát có thể. Do đó, nó yêu cầu các lần lặp O[n²] [trong đó n là số lượng mẫu] và nó sẽ không sử dụng được ngay khi n trở nên lớn hơn một chút

Tuy nhiên, nếu chúng tôi không yêu cầu câu trả lời “chính xác”, chúng tôi có thể có được một xấp xỉ tốt thông qua bootstrapping. Thay vì đánh giá từng cặp duy nhất có thể [có nghĩa là không ít hơn n*[n+1]/2 cặp], chúng ta có thể sử dụng một số cặp được chọn ngẫu nhiên

Điều này sẽ dịch sang mã Python sau

Mã Python cho hồi quy_roc_auc_score. [Mã của tác giả]

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0 có 3 tham số.
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
1,
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
2 và
from sklearn.dummy import DummyRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, median_absolute_error, roc_auc_score, r2_score, explained_variance_score
modelnames = [
‘DummyRegressor[]’,
‘KNeighborsRegressor[]’,
‘LinearRegression[]’,
‘SVR[]’,
‘MLPRegressor[hidden_layer_sizes = [16, 16]]’,
‘DecisionTreeRegressor[]’,
‘GradientBoostingRegressor[]’,
‘XGBRegressor[]’,
‘CatBoostRegressor[]’
]
metricnames = [
‘mean_absolute_error’,
‘median_absolute_error’,
‘r2_score’,
‘explained_variance_score’,
‘regression_roc_auc_score’
]
metrics = pd.DataFrame[index = modelnames, columns = metricnames]for modelname in modelnames:
model = eval[modelname]
pred_test = model.fit[X_train, y_train].predict[X_test]
for metricname in metricnames:
metrics.loc[modelname, metricname] = eval[f'{metricname}[y_test, pred_test]']
8. Nếu
from sklearn.dummy import DummyRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, median_absolute_error, roc_auc_score, r2_score, explained_variance_score
modelnames = [
‘DummyRegressor[]’,
‘KNeighborsRegressor[]’,
‘LinearRegression[]’,
‘SVR[]’,
‘MLPRegressor[hidden_layer_sizes = [16, 16]]’,
‘DecisionTreeRegressor[]’,
‘GradientBoostingRegressor[]’,
‘XGBRegressor[]’,
‘CatBoostRegressor[]’
]
metricnames = [
‘mean_absolute_error’,
‘median_absolute_error’,
‘r2_score’,
‘explained_variance_score’,
‘regression_roc_auc_score’
]
metrics = pd.DataFrame[index = modelnames, columns = metricnames]for modelname in modelnames:
model = eval[modelname]
pred_test = model.fit[X_train, y_train].predict[X_test]
for metricname in metricnames:
metrics.loc[modelname, metricname] = eval[f'{metricname}[y_test, pred_test]']
8 là số nguyên, nó được dùng làm số cặp ngẫu nhiên cần xét [nghiệm gần đúng]. Tuy nhiên, bạn cũng có thể tính điểm “chính xác” [i. e. tất cả các cặp có thể], bằng cách chuyển chuỗi
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
70 đến
from sklearn.dummy import DummyRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, median_absolute_error, roc_auc_score, r2_score, explained_variance_score
modelnames = [
‘DummyRegressor[]’,
‘KNeighborsRegressor[]’,
‘LinearRegression[]’,
‘SVR[]’,
‘MLPRegressor[hidden_layer_sizes = [16, 16]]’,
‘DecisionTreeRegressor[]’,
‘GradientBoostingRegressor[]’,
‘XGBRegressor[]’,
‘CatBoostRegressor[]’
]
metricnames = [
‘mean_absolute_error’,
‘median_absolute_error’,
‘r2_score’,
‘explained_variance_score’,
‘regression_roc_auc_score’
]
metrics = pd.DataFrame[index = modelnames, columns = metricnames]for modelname in modelnames:
model = eval[modelname]
pred_test = model.fit[X_train, y_train].predict[X_test]
for metricname in metricnames:
metrics.loc[modelname, metricname] = eval[f'{metricname}[y_test, pred_test]']
8

Cho tôi xem một số dữ liệu thực tế

Bạn có tò mò muốn xem kết quả của hàm

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0 trên tập dữ liệu thực không? . Nhà ở California từ StatLib [dữ liệu có thể được nhập trực tiếp từ Scikit-learning, theo Giấy phép BSD]

Biến mục tiêu là giá trị nhà trung bình cho các quận của California. Bộ dữ liệu được tạo thành từ 20.640 mẫu và 8 tính năng được quan sát

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]

Bây giờ, hãy thử nhiều mô hình khác nhau trên tập huấn luyện và sau đó tính toán một số số liệu [bao gồm cả

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0, được xác định trong đoạn trước] trên tập kiểm tra

from sklearn.dummy import DummyRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
from xgboost import XGBRegressor
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, median_absolute_error, roc_auc_score, r2_score, explained_variance_score
modelnames = [
‘DummyRegressor[]’,
‘KNeighborsRegressor[]’,
‘LinearRegression[]’,
‘SVR[]’,
‘MLPRegressor[hidden_layer_sizes = [16, 16]]’,
‘DecisionTreeRegressor[]’,
‘GradientBoostingRegressor[]’,
‘XGBRegressor[]’,
‘CatBoostRegressor[]’
]
metricnames = [
‘mean_absolute_error’,
‘median_absolute_error’,
‘r2_score’,
‘explained_variance_score’,
‘regression_roc_auc_score’
]
metrics = pd.DataFrame[index = modelnames, columns = metricnames]for modelname in modelnames:
model = eval[modelname]
pred_test = model.fit[X_train, y_train].predict[X_test]
for metricname in metricnames:
metrics.loc[modelname, metricname] = eval[f'{metricname}[y_test, pred_test]']

Biểu đồ sau đây so sánh

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0 với
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
75 cho tất cả các mô hình được đào tạo

So sánh hồi quy_roc_auc_score và mean_absolute_error cho các mô hình khác nhau. [Hình của tác giả]

Như chúng ta có thể dự kiến, hai số liệu có mối tương quan nghịch. Tất nhiên, một

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
75 thấp hơn có xu hướng được liên kết với một
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0 cao hơn

Số liệu thứ hai cung cấp kiến ​​thức bổ sung về hiệu suất của mô hình. sau khi tính toán

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing[return_X_y = True, as_frame = True]
y *= 100000
X_train, X_test, y_train, y_test = train_test_split[X, y, test_size = 0.33, random_state = 4321]
0, chúng ta có thể nói rằng xác suất mà Catboost ước tính giá trị cao hơn cho a so với b, với điều kiện là a > b, là gần 90%

Cảm ơn bạn đã đọc. Tôi hy vọng bạn thích bài viết này

Tôi đánh giá cao phản hồi và phê bình mang tính xây dựng. Nếu bạn muốn trao đổi về bài viết này hoặc các chủ đề liên quan khác, bạn có thể nhắn tin cho tôi theo địa chỉ liên hệ Linkedin của tôi

Làm cách nào để tính điểm AUC ROC trong Python?

Cách tính AUC [Diện tích dưới đường cong] bằng Python .
Bước 1. Gói nhập khẩu. Đầu tiên, chúng ta sẽ nhập các gói cần thiết để thực hiện hồi quy logistic trong Python. nhập gấu trúc dưới dạng pd nhập 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. Tính AUC

Làm cách nào để tính điểm AUC trong Python mà không cần sklearn?

Tính toán chỉ số hiệu suất bằng Python thuần túy mà không cần scikit-learning .
Tính toán ma trận nhầm lẫn
Tính điểm F1
Tính toán Điểm AUC, chúng ta cần tính toán các ngưỡng khác nhau và với mỗi ngưỡng tính toán tpr, fpr rồi sử dụng. lưu ý 1. trong dữ liệu này, chúng ta có thể thấy số điểm tích cực >> số điểm tiêu cực

Điểm ROC được tính như thế nào?

Đường cong ROC được tạo bằng cách tính toán và vẽ biểu đồ tỷ lệ dương tính thực so với tỷ lệ dương tính giả cho một bộ phân loại duy nhất ở nhiều ngưỡng khác nhau . Ví dụ: trong hồi quy logistic, ngưỡng sẽ là xác suất dự đoán của một quan sát thuộc lớp tích cực.

Làm cách nào để vẽ đường cong ROC bằng Python?

Tạo một vấn đề phân loại n lớp ngẫu nhiên. .
Chia mảng hoặc ma trận thành các chuỗi ngẫu nhiên, sử dụng phương thức train_test_split[]
Khớp mô hình SVM theo dữ liệu huấn luyện đã cho, sử dụng phương thức fit[]
Vẽ đường cong đặc tính hoạt động của máy thu [ROC], sử dụng phương thức plot_roc_curve[]
Để hiển thị hình, sử dụng plt

Chủ Đề