總結:不平衡數據的分類,(1)數據層面:使用過采樣是主流,過采樣通常使用smote,或者少數使用數據復制。過采樣后模型選擇RF、xgboost、神經網絡能夠取得非常不錯的效果。(2)模型層面:使用模型集成,樣本不做處理,將各個模型進行特征選擇、參數調優后進行集成,通常也能夠取得不錯的結果。(3)其他方法:偶爾可以使用異常檢測技術,主要有IsolationForest,OneClassSVM,LocalOutlierFactor,KMeans,其中IsolationForest效果最好。但是不及前兩種方法。很少使用數據欠采樣手法,因為數據無法反映整體特征而導致高誤報。
從信用卡欺詐模型看不平衡數據分類:
https://www.kaggle.com/joparga3/in-depth-skewed-data-classif-93-recall-acc-now 說明了欠采樣不會太好,整體精度難以上去 文中欠采樣思路 np.random.choice(normal_indices, number_records_fraud, replace = False) 最后精度 134/(134+11090) = 0.011
https://www.kaggle.com/vincentlugat/votingclassifier-f1-score-0-88-data-viz 直接用原始數據訓練,然后集成三個模型來做,效果也不錯 VotingClassifier (
estimators = [('xgb', xgb_cfl), ('lt', log_cfl), ('rf', rf_cfl)],
voting='soft', weights = [1, 1, 1.33]) 最后效果Precision = 0.950
Recall = 0.826
F1_score = 0.884
https://www.kaggle.com/currie32/predicting-fraud-with-tensorflow 直接用原始數據進行訓練,特征工程選擇最有用特征,然后使用神經網絡進行訓練 t-SNE畫圖 最后效果 召回率82.93% 誤報率 0.10% 也還是不錯 特征選擇使用distplot繪圖人眼看 另外提取了一些額外特征 df['V1_'] = df.V1.map(lambda x: 1 if x < -3 else 0)
https://www.kaggle.com/janiobachmann/credit-fraud-dealing-with-imbalanced-datasets 非常非常好的文章 里面將過采樣、欠采樣、不做數據處理的幾種方法都提到了,並且pca、tsne用到。其中,過采樣是+神經網絡處理,過采樣使用的注意事項也提到了,必須要先split data再過采樣。模型:undersample_model = Sequential([
Dense(n_inputs, input_shape=(n_inputs, ), activation='relu'),
Dense(32, activation='relu'),
Dense(2, activation='softmax')
])最后效果Confusion matrix, without normalization
[[56864 0]
[ 0 98]]還是非常不錯的!
https://www.kaggle.com/bonovandoo/fraud-detection-with-smote-and-xgboost-in-r 使用smote+xgboost來做,最后效果:Precision 0.999841017488076,Recall 0.995497476124312。
https://www.kaggle.com/gargmanish/how-to-handle-imbalance-data-study-in-detail 過采樣和欠采樣都討論了,其中欠采樣+RF比較好,acc和recall都是0.86。
https://www.kaggle.com/kamathhrishi/detecting-credit-card-frauds 講得比較全,Supervised Learning Algorithms(SVM、RF,注意RandomForestClassifier(max_depth=2, random_state=0) depth=2)和Anomaly Detection Algorithms,后者有One Class SVM(Acc 32%),Isolation Forest(Acc 89%還不錯)。另外使用了過采樣技術,評估隔離森林和RF,不過由於RF的depth=2,Acc和Recall是0.23、0.83。
https://www.kaggle.com/shelars1985/anomaly-detection-using-gaussian-distribution 直接使用Gaussian Distribution to detect Anamolous transactions.最終效果:Precision of around 60% with Recall of 74% 算是一個探索性的思路吧,可能不太適合實際工程項目。
https://www.kaggle.com/matheusfacure/semi-supervised-anomaly-detection-survey 探索了一些半監督的技術使用異常檢測來做,分別為(1)Gaussian Model Based,Test Recall Score: 0.793 Test Precision Score: 0.701 Test F2 Score: 0.773(2)Histogram Based,不知道是啥原理,反正最后精度不咋的(3)聚類 GaussianMixture,Test Recall Score: 0.809 Test Precision Score: 0.726 Test F2 Score: 0.791(4)聚類IsolationForest,Test Recall Score: 0.760 Test Precision Score: 0.482 Test F2 Score: 0.681(5)神經網絡,neural network named the autoencoder,Test Recall Score: 0.813 Test Precision Score: 0.294 Test F2 Score: 0.601效果也不咋的啊!
https://www.kaggle.com/rgaddati/unsupervised-fraud-detection-isolation-forest 也探索了使用異常檢測思路,主要有IsolationForest,OneClassSVM,LocalOutlierFactor,KMeans綜合看IF是效果最好的。
https://www.kaggle.com/lct14558/imbalanced-data-why-you-should-not-use-roc-curve 結論就是Handling highly imbalance classes and why Receiver Operating Characteristics Curve (ROC Curve) should not be used, and Precision/Recall curve should be preferred in highly imbalanced situations,對於不平衡數據訓練模型,最重要的指標是Precision/Recall。
https://www.kaggle.com/cherzy/visualization-on-a-2d-map-with-t-sne 使用tsne做數據可視化,非常主流的方法!比PCA用得多。
https://www.kaggle.com/dstuerzer/optimized-logistic-regression 討論了如何做LR的參數優化。
