模型評估:不平衡分類模型

用 Python 練習機器學習面試題

Lisa Stuart

Data Scientist

類別不平衡

  • 類別型目標變數
    • 各類別樣本數大致相當
    • 差異過大 → 結果易誤導

不平衡 vs 平衡類別

用 Python 練習機器學習面試題

混淆矩陣

混淆矩陣

1 https://scaryscientist.blogspot.com/2016/03/confusion-matrix.html
用 Python 練習機器學習面試題

效能指標

效能指標

1 https://scaryscientist.blogspot.com/2016/03/confusion-matrix.html
用 Python 練習機器學習面試題

由矩陣推得的指標

效能指標

1 https://scaryscientist.blogspot.com/2016/03/confusion-matrix.html
用 Python 練習機器學習面試題

重採樣技巧

  • 少數類別過度抽樣(oversample)
  • 多數類別欠度抽樣(undersample)
  • 注意:先切分訓練/測試集,再重採樣!

重採樣技巧

1 https://www.svds.com/learning-imbalanced-classes/
用 Python 練習機器學習面試題

函式

Function 傳回
sklearn.linear_model.LogisticRegression 邏輯斯回歸
sklearn.metrics.confusion_matrix(y_test,y_pred) 混淆矩陣
sklearn.metrics.precision_score(y_test,y_pred) 精確率
sklearn.metrics.recall_score(y_test,y_pred) 召回率
sklearn.metrics.f1_score(y_test,y_pred) F1 分數
sklearn.utils.resample(deny, n_samples=len(approve)) 重採樣
用 Python 練習機器學習面試題

一起來練習吧!

用 Python 練習機器學習面試題

Preparing Video For Download...