0% found this document useful (0 votes)
12 views17 pages

PROJECT1

The project report focuses on credit card fraud detection through transaction analysis using Python and pandas. It outlines the creation of a sample dataset, the definition of thresholds for identifying fraudulent transactions, and the implementation of a function to detect fraud based on transaction amount, location, and frequency. The report concludes with a demonstration of the fraud detection process and its results.

Uploaded by

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

PROJECT1

The project report focuses on credit card fraud detection through transaction analysis using Python and pandas. It outlines the creation of a sample dataset, the definition of thresholds for identifying fraudulent transactions, and the implementation of a function to detect fraud based on transaction amount, location, and frequency. The report concludes with a demonstration of the fraud detection process and its results.

Uploaded by

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

A Project Report

On
CREDIT CARD FRAUD DETECTION
TRANSACTION
Submitted in partial fulfillment of
Diploma In Computer Engineering

Department of Computer Engineering


Government Polytechnic, Dahod
Guided by:
Mr. PARESH PATEL
Lecturer,

Computer Engineering Department


Government Polytechnic, Dahod

Submitted By:
KASHISH MHOVIA (216300307006)
KARINA SHARMA (226300307120)
PRUTHA PANCHAL (226300307078)
HEM PANCHAL (206300307097)
Government Polytechnic, Dahod
CERTIFICATE

This is to certify that Ms. KASHISH MAHOVIA Enrolment no.


216300307006, Semester 6th of Computer Engineering
Department has satisfactorily completed his work for the subject
besic information security (4360702).

Submission Date: ____________.

Signature of
Course Teacher
Government Polytechnic, Dahod
CERTIFICATE

This is to certify that Ms. KAREENA SHARMA Enrolment no.


226300307120, Semester 6th of Computer Engineering
Department has satisfactorily completed his work for the subject
besic information security (4360702).

Submission Date: ____________.

Signature of
Course Teacher
Government Polytechnic, Dahod
CERTIFICATE

This is to certify that Ms. PRUTHA PANCHAL enrolment no.


226300307078, Semester 6th of Computer Engineering
Department has satisfactorily completed his work for the
subjectbesic information security (4360702).

Submission Date: ____________.

Signature of
Course Teacher
Government Polytechnic, Dahod
CERTIFICATE

This is to certify that Mr. HEM PANCHAL enrolment no.


206300307097, Semester 6th of Computer Engineering
Department has satisfactorily completed his work for the
subjectbesic information security (4360702).

Submission Date: ____________.

Signature of
Course Teacher
Step-by-Step
Explanation
 Importing Libraries:

o import pandas as pd

o The code begins by importing the


pandas library, which is essential
for data manipulation and analysis
in Python.

 Sample Transaction Data:

data = {
'transaction_id': [1, 2, 3, 4, 5],
'amount': [100, 1500, 200, 3000,
50],
'location': ['USA', 'USA', 'Canada',
'USA', 'Canada'],
'time': ['2023-10-01 10:00', '2023-
10-01 10:05', '2023-10-01 10:10',
'2023-10-01 10:15', '2023-10-01
10:20'],
'user_id': [101, 101, 102, 101, 102]
}

transaction_id amount location time user_id


1 100 USA 2023-10-01 10:00 101
2 1500 USA 2023-10-01 10:05 101
3 200 Canada 2023-10-01 10:10 102
4 3000 USA 2023-10-01 10:15 101
5 50 Canada 2023-10-01 10:20 102

A dictionary named data is created,


containing sample transaction
information. Each key represents a
column in the dataset:
o transaction_id: Unique identifier for
each transaction.
o amount: The monetary value of the
transaction.
o location: The geographical location
where the transaction occurred.
o time: The timestamp of the
transaction.
o user_id: Identifier for the user who
made the transaction.
 CREATING A DATAFRAME:
o transactions = pd.DataFrame(data)

o The data dictionary is converted into


a pandas DataFrame
called transaction.
o This structure allows for easy
manipulation and analysis of the
transaction data.

 DEFINING THRESHOLDS FOR


FRAUD DETECTION:
amount_threshold = 2000 #
Example threshold for high transaction
amount
location_change_threshold = 10
# Example threshold for location
changes
suspicious_locations = ['USA',
'Canada'] # Example of known
locations

 Several thresholds and criteria


are defined for detecting
potential fraud:
o amount_threshold: A threshold of
2000 is set to flag transactions that
exceed this amoun as potentially
fraudulent.
o location_change_threshold: This
variable is defined but not used in the
current implementation. It could be
intended for future enhancements.
o suspicious_locations: A list of
known locations (USA and Canada) is
defined.
Transactions from locations outside
this list may be flagged

 FUNCTION TO DETECT FRAUD:


def detect_fraud(transactions):
fraud_cases = []

o A function named detect_fraud is


defined, which takes the transactions
DataFrame as input and initializes an empty
list fraud_cases to store any detected
fraud cases.

 ITERATING THROUGH
TRANSACTIONS:
o for index, row in transactions.iterrows():

o The function iterates over each


transaction in the DataFrame
using iterrows(), which returns both
the index and the row data.
 CHECKING FOR HIGH
TRANSACTION AMOUNT:
if row['amount'] > amount_threshold:
fraud_cases.append((row['transaction_
id'], 'High transaction amount'))
o For each transaction, it checks if
the amount exceeds the
defined amount_threshold. If it does,
a tuple containing
the transaction_id and the reason
('High transaction amount') is appended to
the fraud_cases list.

 CHECKING FOR UNUSUAL


LOCATIONS
if row['location'] not in
suspicious_locations:
fraud_cases.append((row['transaction_id'
], 'Unusual location'))
o The code checks if the location of the
transaction is not in
the suspicious_locations list. If it is
not, it appends a tuple
to fraud_cases indicating an 'Unusual
location'.

 CHECKING FOR MULTIPLE


TRANSACTIONS IN A SHORT TIME
FRAME
recent_transactions =
transactions[(transactions['user_id'] ==
row['user_id']) &
(transactions['time'] <
row['time'])]
if not recent_transactions.empty:
time_diff = pd.to_datetime(row['time']) -
pd.to_datetime(recent_transactions['time'].max()
)
if time_diff.total_seconds() < 500: # 5
minutes
fraud_cases.append((row['transaction_id'],
'Multiple transactions in short time'))

CREDIT CARD FRAUD


DETECTION IN
TRANSACTIONS
Code:
import pandas as pd
# Sample transaction data
data = {
'transaction_id': [1, 2, 3, 4, 5],
'amount': [100, 1500, 200, 3000, 50],
'location': ['USA', 'USA', 'Canada', 'USA',
'Canada'],
'time': ['2023-10-01 10:00', '2023-10-01
10:05', '2023-10-01 10:10', '2023-10-01 10:15',
'2023-10-01 10:20'],
'user_id': [101, 101, 102, 101, 102]
}
# Create a DataFrame
transactions = pd.DataFrame(data)
# Define thresholds for fraud detection
amount_threshold = 1000 # Example
threshold for high transaction amount
location_change_threshold = 1 # Example
threshold for location changes
suspicious_locations = ['USA', 'Canada'] #
Example of known locations
# Function to detect fraud
def detect_fraud(transactions):
fraud_cases = []
for index, row in transactions.iterrows():
# Check for high transaction amount
if row['amount'] > amount_threshold:

fraud_cases.append((row['transaction_id'],
'High transaction amount'))

# Check for unusual location (assuming


user has a known location)
if row['location'] not in
suspicious_locations:

fraud_cases.append((row['transaction_id'],
'Unusual location'))
# Check for multiple transactions in a
short time frame
recent_transactions =
transactions[(transactions['user_id'] ==
row['user_id']) &
(transactions['time']
< row['time'])]
if not recent_transactions.empty:
time_diff = pd.to_datetime(row['time'])
-
pd.to_datetime(recent_transactions['time'].max
())
if time_diff.total_seconds() < 300: # 5
minutes

fraud_cases.append((row['transaction_id'],
'Multiple transactions in short time'))
return fraud_cases
# Detect fraud in transactions
fraudulent_transactions =
detect_fraud(transactions)
# Output results
if fraudulent_transactions:
print("Fraudulent Transactions Detected:")
for transaction in fraudulent_transactions:
print(f"Transaction ID: {transaction[0]},
Reason: {transaction[1]}")
else:
print("No fraudulent transactions detected.")

PROJECT OUTPUT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy