Fraud Detection in Python
Charlotte Werger
Data Scientist


from imblearn.over_sampling import RandomOverSamplermethod = RandomOverSampler() X_resampled, y_resampled = method.fit_resample(X, y)compare_plots(X_resampled, y_resampled, X, y)


from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression# Define resampling method and split into train and test method = SMOTE() X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8, random_state=0)# Apply resampling to the training data only X_resampled, y_resampled = method.fit_resample(X_train, y_train)# Continue fitting the model and obtain predictions model = LogisticRegression() model.fit(X_resampled, y_resampled)# Get your performance metrics predicted = model.predict(X_test) print (classification_report(y_test, predicted))
Fraud Detection in Python