Machine Learning Model for Fraud Detection by Muhammad Awais QuarniMachine Learning Model for Fraud Detection by Muhammad Awais Quarni

Machine Learning Model for Fraud Detection

Muhammad Awais  Quarni

Muhammad Awais Quarni

# Import necessary libraries

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, confusion_matrix

# Load the dataset
data = pd.read_csv('fraud_dataset.csv')

# Split the dataset into features and target variable
X = data.drop('fraud', axis=1)
y = data['fraud']

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create a Random Forest classifier
model = RandomForestClassifier()

# Train the model
model.fit(X_train, y_train)

# Make predictions on the test set
y_pred = model.predict(X_test)

# Evaluate the model
accuracy = accuracy_score(y_test, y_pred)
confusion_mat = confusion_matrix(y_test, y_pred)

print("Accuracy:", accuracy)
print("Confusion Matrix:")
print(confusion_mat)

Like this project

Posted Jul 21, 2023

Built a machine learning model using Python to detect fraudulent transactions in real time for a financial institution. Reduced fraud losses by 15%.