Project - Credit Card Fraud Detection using Machine Learning

18 / 25

Applying SMOTE technique

We shall apply the SMOTE technique only on train data and keep the test data untouched so as to avoid any form of data leakage.

Note:

  • imblearn.over_sampling.SMOTE : Class to perform over-sampling using SMOTE.

  • fit_sample : This method of imblearn.over_sampling.SMOTE is used to resample the dataset.

INSTRUCTIONS
  • From imblearn.over_sampling import SMOTE.

    from imblearn.over_sampling import SMOTE
    
  • Print the number of class-wise samples before over-sampling using the value_counts method on y_train.

    print("Before over-sampling:\n", y_train['Class'].<< your code comes here >>)
    
  • Declare an instance of SMOTE as sm.

    sm = SMOTE()
    
  • Use fit_sample method of sm on X_train and y_train['Class'] and store the resampled features and labels in X_train_res and y_train_res respectively.

    X_train_res, y_train_res = sm.<< your code comes here >>(X_train, y_train['Class'])
    
  • Print the number of class-wise samples after over-sampling using the value_counts method on y_train.

    print("After over-sampling:\n", y_train_res.<< your code comes here >>)
    
Get Hint See Answer


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...