開始使用免費開始

分類器比較

可以在不同的分類器上套用 ROI 架構,觀察較高的 precision 與 recall 如何帶來更高的 ROI。請注意,你先前建立的基準分類器,因為設計上真陽性 tp 與假陽性 fp 都為 0,所以總報酬與成本皆為 0。本練習中,你將使用 ROI 架構比較邏輯迴歸與決策樹分類器。

工作空間中已提供 X_trainy_trainX_testy_test,以及將 pandas 載入為 pdnumpy 載入為 npsklearn.linear_model 中的 LogisticRegression() 也可使用。

本練習屬於課程

用 Python 透過機器學習預測 CTR

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create and fit classifier
clf = ____
y_pred = clf.____(X_train, y_train).____(X_test) 

# Calculate total return, total spent, and ROI 
r, cost = 0.2, 0.05
tn, fp, fn, tp = ____(y_test, y_pred).____
total_return = ____ * r
total_spent = (____ + ____) * cost 
roi = total_return / total_spent
print("Total return: %s, Total spent: %s, ROI: %s" %(total_return, total_spent, roi))
編輯並執行程式碼