Project - Credit Card Fraud Detection using Machine Learning

20 / 25

Training the Classification Algorithm

Let us use logistic regression for this classification problem.

INSTRUCTIONS
  • Import GridSearchCV from sklearn.model_selection.

    from sklearn.model_selection import << your code comes here >>
    
  • Import LogisticRegression from sklearn.linear_model.

    from sklearn.linear_model import << your code comes here >>
    
  • Import confusion_matrix, auc, roc_curve from sklearn.metrics.

    from sklearn.metrics import << your code comes here >>
    
  • Let us declare some parameters and their values for the grid-search.

    parameters = {"penalty": ['l1', 'l2'], 'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]}
    

    paramter C is the regularization parameter, and penalty is the norm used in the penalization.

  • Instantiate LogisticRegression() as lr.

    lr = LogisticRegression()
    
  • Pass lr, parameters,cv=5 as arguments to GridSearchCV .

    clf = GridSearchCV(lr, parameters, cv=5, verbose=5, n_jobs=3)
    
  • Fit the classifier on X_train_res and y_train_res using fit.

    k = clf.<< your code comes here >>(X_train_res, y_train_res)
    
  • Let us print the best parameters.

    print(k.best_params_)
    
Get Hint See Answer


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

Loading comments...