相關的變數
加入模型的前 10 個變數如下:
['max_gift', 'number_gift', 'time_since_last_gift', 'mean_gift', 'income_high', 'age', 'country_USA', 'gender_F', 'income_low', 'country_UK']
如你所見,min_gift 並未被加入。這是否代表它是個不好的變數?你可以把它作為單一變數放入模型並計算 AUC,來測試它的表現。min_gift 的 AUC 和 income_high 的 AUC 相比如何?為此,你可以使用函式 auc():
auc(variables, target, basetable)
有時一個好的變數之所以沒有被加入,是因為它和模型中已存在的某個變數高度相關。你可以透過計算這些變數之間的相關係數來測試:
import numpy
numpy.corrcoef(basetable["variable_1"],basetable["variable_2"])[0,1]
本練習屬於課程
Python 預測分析入門
練習說明
- 僅使用變數
min_gift計算模型的 AUC。 - 僅使用變數
income_high計算模型的 AUC。 - 計算變數
min_gift與mean_gift之間的相關係數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Calculate the AUC of the model using min_gift only
auc_min_gift = auc([____], ["target"], ____)
print(round(auc_min_gift,2))
# Calculate the AUC of the model using income_high only
auc_income_high = ____([____], [____], ____)
print(round(auc_income_high,2))
# Calculate the correlation between min_gift and mean_gift
correlation = np.corrcoef(basetable["____"], basetable["____"])[0,1]
print(round(correlation,2))