0% found this document useful (0 votes)
9 views2 pages

6th Exp

The document outlines a program to implement a naïve Bayesian classifier for credit card analysis using Python. It includes steps for loading data, selecting features, splitting the dataset, training the model, and computing accuracy. The program achieves an accuracy of 100% on the test data set.

Uploaded by

suriyasri2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

6th Exp

The document outlines a program to implement a naïve Bayesian classifier for credit card analysis using Python. It includes steps for loading data, selecting features, splitting the dataset, training the model, and computing accuracy. The program achieves an accuracy of 100% on the test data set.

Uploaded by

suriyasri2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Write a program to implement the naïve Bayesian classifier for credit card

analysis and compute the accuracy with a few test data sets.

Aim:

To write the program to implement the naïve Bayesian classifier for credit card
analysis and compute the accuracy with a few test data sets.

Program:

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score

# Load dataset from CSV


df = pd.read_csv('credit_card_data.csv') # Ensure the CSV file is in the working directory

# Selecting features and target variable


X = df[['Transaction Amount', 'Transaction Frequency']]
y = df['Fraudulent']

# Split into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Train Naïve Bayes classifier


model = GaussianNB()
model.fit(X_train, y_train)

# Predict on test data


y_pred = model.predict(X_test)
# Compute accuracy
accuracy = accuracy_score(y_test, y_pred)
print(f'Accuracy of Naïve Bayes classifier: {accuracy * 100:.2f}%')

Output:

Accuracy of Naïve Bayes classifier: 100.00%

You might also like