1
$\begingroup$

I am using the Kaggle's credit card fraud detection dataset (https://www.kaggle.com/mlg-ulb/creditcardfraud)

In order to create a balanced datasets I was testing RandomUnderSampler() and NearMiss(). I am running a make_pipeline() from imblearn. I get very different results when I used RobustScaler() before vs after Neamiss() method. This drastic difference with LinearSVC(). Is this something wrong here, it is expected?

import pandas as pd
from sklearn import model_selection, preprocessing
from imblearn import under_sampling
from imblearn.pipeline import make_pipeline

credit = pd.read_csv() # Please use data from above link


X_train, X_test, y_train, y_test = model_selection.train_test_split(credit.drop('Class', 1), credit.Class, test_size = 0.2, random_state = 100) 
# 1) 
pipe = make_pipeline(under_sampling.NearMiss(), preprocessing.RobustScaler(), LinearSVC(dual = False))
score = model_selection.cross_val_score(pipe, X_train, y_train, cv = 3)
print(score, '\n', score.mean())

"""
 results are
[0.88720062 0.8111471  0.81310897] 
 0.8371522304707543 """

# 2) 

pipe = make_pipeline(preprocessing.RobustScaler(), under_sampling.NearMiss(), LinearSVC(dual = False))
score = model_selection.cross_val_score(pipe, X_train, y_train, cv = 3)
print(score, '\n', score.mean())

"""
results-
[0.33242044 0.46160531 0.35399221] 
 0.38267265137357126
"""

# 3)

pipe = make_pipeline(under_sampling.RandomUnderSampler(), preprocessing.RobustScaler(), LinearSVC(dual = False))
score = model_selection.cross_val_score(pipe, X_train, y_train, cv = 3)
print(score, '\n', score.mean())

 """
results-
[0.97021686 0.96007795 0.9701638 ] 
 0.966819533466512
"""
# 4) 

pipe = make_pipeline(preprocessing.RobustScaler(), under_sampling.RandomUnderSampler(), LinearSVC(dual = False))
score = model_selection.cross_val_score(pipe, X_train, y_train, cv = 3)
print(score, '\n', score.mean())
"""
results-
[0.97234987 0.96139464 0.95404751] 
 0.9625973369943192
"""
$\endgroup$
1
  • $\begingroup$ I don't know much about these methods, but make sure that the ones which reach very high performance are tested on the real original distribution. $\endgroup$
    – Erwan
    Commented Oct 14, 2020 at 23:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.