Skip to content

Fraud Detection

Industry Department Role
Retail & Online Finance Business executive

Processed Dataset

Data

The datasets contains transactions made by credit cards in September 2013 by european cardholders. This dataset presents transactions that occurred in two days, where we have 492 frauds out of 284,807 transactions. The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions. The goal is to identify fraudulent credit card transactions. Feature 'Class' is the response variable and it takes value 1 in case of fraud and 0 otherwise.

Click to expand Features Informations: * Time Number of seconds elapsed between this transaction and the first transaction in the dataset * V1may be result of a PCA Dimensionality reduction to protect user identities and sensitive features(v1-v28) * V2 * V3 * V4 * V5 * V6 * V7 * V8 * V9 * V10 * V11 * V12 * V13 * V14 * V15 * V16 * V17 * V18 * V19 * V20 * V21 * V22 * V23 * V24 * V25 * V26 * V27 * V28abc * AmountTransaction amount * Class1 for fraudulent transactions, 0 otherwise

MindsDB Code example

import mindsdb
import pandas as pd
from sklearn.metrics import balanced_accuracy_score

def run():

    mdb = mindsdb.Predictor(name='cc_fraud')

    mdb.learn(from_data='processed_data/train.csv', to_predict='Class')

    predictions = mdb.predict(when_data='processed_data/test.csv')

    pred_val = [int(x['Class']) for x in predictions]
    real_val = [int(x) for x in list(pd.read_csv('processed_data/test.csv'))['Class'])]

    accuracy = balanced_accuracy_score(real_val, pred_val)

    #show additional info for each transaction row
    additional_info = [x.explanation for x in predictions]

    return {
        'accuracy': accuracy,
        'backend': backend,
        'additional info': additional_info
    }

# Run as main
if __name__ == '__main__':
    print(run())

Mindsdb accuracy

Accuraccy Backend Last run MindsDB Version Latest Version
0.921724518459069 Lightwood 16 April 2020 MindsDB PyPi Version
Click to expand MindsDB's explanation for each row:
{
    'accuracy': 0.921724518459069,
    'backend': 'lightwood',
    'additional info': [{
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9957,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9956,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9958,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9956,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9954,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9953,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9957,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9955,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9957,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9955,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9958,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9918,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }, {
                'Class': {
                    'predicted_value': '0',
                    'confidence': 0.9959,
                    'explanation': {
                        'prediction_quality': 'very confident',
                        'important_missing_information': []
                    },
                    'prediction_quality': 'very confident',
                    'important_missing_information': []
                }
            }
    ]
}