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

Divya Report (2) Desktop Final Edit 2

The document is an internship report submitted by P. Divya for the Advanced Python program completed at Pantech E-Learning, Chennai, from September 12 to October 21, 2022. It includes sections on the organization, learning objectives, weekly activities, and a detailed introduction to Python programming, covering data types, operators, and libraries like NumPy and Pandas. The report also acknowledges the support received from various individuals and outlines the structure of the report with an index.

Uploaded by

Arshiya Nousheen
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 views40 pages

Divya Report (2) Desktop Final Edit 2

The document is an internship report submitted by P. Divya for the Advanced Python program completed at Pantech E-Learning, Chennai, from September 12 to October 21, 2022. It includes sections on the organization, learning objectives, weekly activities, and a detailed introduction to Python programming, covering data types, operators, and libraries like NumPy and Pandas. The report also acknowledges the support received from various individuals and outlines the structure of the report with an index.

Uploaded by

Arshiya Nousheen
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/ 40

Internship Report on

ADVANCED PYTHON
is submitted in partial fulfillment of the requirement (III B.Tech Summer Break) for the award
of the Degree of Bachelor of Technology

to

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR,


ANANTHAPURAMU
by

P.DIVYA
(19711A0488)

Internship carried out at


PANTECH E-LEARNING , CHENNAI
(Duration: 12TH SEPTEMBER, 2022 to 21ST OCTOBER, 2022
(Based certificate)

Department of Electronics and Communication Engineering

2022-2023
Department of Electronics and Communication Engineering

CERTIFICATE

This is to certify that the “Internship Report” is submitted by P.DIVYA

(19711A0488) during academic year 2022-2023, in partial fulfillment of the

requirements for the award of degree of Bachelor of Technology in Department of

Electronics and Communication Engineering, at Pantech e-learning , Chennai.

Internship Coordinator Head of the Department


Dr.K.S.Sagar Reddy Dr. K. Murali, M.Tech, Ph.D
Professor , Dept of ECE Professor & HOD Dept of ECE

Signature of the Examiners

1.

2.
DECLARATION

I hereby declare that the internship entitled ADVANCED PYTHON has been
done by me and has submitted to NARAYANA ENGINEERING COLLEGE,
NELLORE as a part of partial fulfillment of the requirements for the award of degree
of Bachelor of Technology in Department of Electronics and Communication
Engineering.

I also declare that this internship report has not submitted to any other institute
or university and not copied from any other sources.

P.DIVYA
(19711A0488 )

Place: NELLORE
Date:
CERTIFICATION
ACKNOWLEDGEMENT

I am extremely thankful to Dr. P. NARAYANA, the Founder Chairman of


Narayana Group for his good initiation starting technical institution in Nellore. I also
extremely thankful to Mr R Sambasiva Rao, B.Tech, Registrar, Narayana Engineering
College, Nellore.

I am highly indebted to director Dr. A. V. S Prasad, Ph.D, Director, Narayana


Engineering & Pharmacy Colleges, Principal Dr. G. Srinivasulu Reddy, M.Tech.,
Ph.D., Narayana Engineering College, Nellore for provided to accomplish this
internship.

I would like to thank my Head of the Department Dr. K. Murali M.Tech, Ph.D,
Professor & HOD, Department of Electronics and Communication Engineering, Narayana
Engineering College, Nellore for his constructive criticism throughout my internship.

I would like to thank Dr. K. S. Sagar Reddy, Professor, Internship Coordinator,


Department of ECE for their support and advices to get his guidance, constant
assistance, support, endurance and constructive for the betterment of the internship.

I would like to thank the CEO of PANTECH E-LEARNING, CHENNAI for


giving me the opportunity to do an internship within the organization through virtual
mode. I also would like all the people that worked along with me in PANTECH E-
LEARNING, CHENNAI with their patience and openness they created an enjoyable
working environment. It is indeed with a great sense of pleasure and immense sense of
gratitude that I acknowledge the help of these individuals.

I am extremely greatfull to my department staff members and friends who helped


me in successful completion of this internship.

P. DIVYA
(19711A0488)
ABSTRACT

A contemporary, simple-to-learn object-oriented programming language is


Python. Its built-in data types are strong, and its control mechanisms are simple to use. Python is an
interpreted language, thus it is best to just look at and describe interactive sessions when reviewing
it. Due of the numerous standard libraries that come with it and its ability to interact with other
languages and utilize their capabilities, it is employed in a wide range of applications. Python can
be used for data collection, web scraping, and scripting. There are libraries that make it simple to
share academic code projects in Python, and it is well-liked in the scientific community for
scientific computing. Python interacts with the internet since it is a web programming language. It
is adept at sending and receiving.

Keywords: - Web Programming, Interpreted Language, Object-Oriented Programming Language.

I
Organization Information / Industry Profile

 Pan Tech e- Learning is one of the growing IT services companies. Pan Tech e-
Learning started in 17 February, 2021 as Proprietor Entity with a vision of providing
web services and hosting servers at affordable cost.
 PANTECH ELEARNING PRIVATE LIMITED is classified as Non-govt company
and is registered at Registrar of Companies located in ROC-CHENNAI.
 As regarding the financial status on the time of registration of PANTECH
ELEARNING PRIVATE LIMITED Company its authorized share capital is Rs.
1500000 and its paid-up capital is Rs. 100000.
 We provide complete end-to-end outsourcing solutions for various industries. We
have a comprehensive set of solutions for the Educational Institutes, banking, finance,
insurance, manufacturing, retail & distribution and contracting sectors.
 The company has operations and a customer base spanning across 8 countries
including software.

II
Learning Objectives / Internship Objectives

 Internships are generally thought of to be reserved for college students looking to gain
experience in a particular field. However, a wide array of people can benefit from
Training Internships in order to receive real world experience and develop their skills.
 An objective for this position should emphasize the skills you already possess in the area
and your interest in learning more
 Internships are utilized in a number of different career fields, including architecture,
engineering, healthcare, economics, advertising and many more.
 Some internship is used to allow individuals to perform scientific research while others
are specifically designed to allow people to gain first-hand experience working.
 Utilizing internships is a great way to build your resume and develop skills that can be
emphasized in your resume for future jobs. When you are applying for a Training
Internship, make sure to highlight any special skills or talents that can make you stand
apart from the rest of the applicants so that you have an improved chance of landing the
position.

III
Weekly Overview of Internship Activities

SUMMARY OF THE TOPIC/MODULE


WEEK DATE DAY
COMPLETED
12-09-2022
Monday Introduction to Python Programming
13-09-2022
Tuesday Data Types and Operators
1st WEEK

14-09-2022Wednesday Looping Operations


15-09-2022 Thursday Functions
16-09-2022Friday OOPS’s and Classes
17-09-2022Saturday Decorators, Generators, Iterators

SUMMARY OF THE TOPIC/MODULE


WEEK DATE DAY
COMPLETED
19-09-2022Monday NumPy Tutorial
20-09-2022Tuesday NumPy Array Correction
2nd WEEK

21-09-2022Wednesday NumPy Indexing


22-09-2022Thursday Basic Slicing and Advanced Indexing in NumPy Python
23-09-2022Friday NumPy Datatype Objects
24-09-2022Saturday NumPy String Operations

IV
SUMMARY OF THE TOPIC/MODULE
WEEK DATE DAY
COMPLETED
26-09-2022 Monday Pandas Tutorial
28-09-2022 Wednesday Introduction to Pandas in Python
3rd WEEK

29-09-2022 Thursday Holiday


30-09-2022 Friday Pandas Data frames, Creating a Pandas data frame
01-10-2022 Saturday Pandas Series
03-10-2022 Monday Creating a Pandas Series

SUMMARY OF THE TOPIC/MODULE


WEEK DATE DAY
COMPLETED
03-10-2022Monday Sample Project
06-10-2022Thursday Discussion about Prediction Systems
4th WEEK

10-10-2022Monday Sample Project


13-10-2022Thursday Assigning Project
14-10-2022Monday Implementation of Project
15-10-2022Tuesday Project Presentation
21-10-2022Friday Submission of Project abstract & Presentation

V
INDEX

CHAPTER NAMES PAGE NO


ABSTRACT I
Organization Information II
Benefits to the Company / Institute Through Your Report III
Learning Objectives / Internship Objectives III
Weekly Overview of Internship Activities IV
Index IX
List of Figures VIII
List of Tables IX
1. INTRODUCTION 1 – 10
1.1. Introduction to python programming 1
1.2. Data types and operators 2
1.2.1 Arithmetic operators 3
1.2.2 Comparison operators 4
1.2.3 Assignment operators 5
1.2.4 Bitwise operators 5
1.2.5 Logical operators 6
1.3. Loops 7
1.3.1 For Loop 7
1.3.2 While Loop 7
1.4. Functions 8
1.5. OOPS and Classes 8
1.6. Exceptional Handling 9
1.7. File Handling 9
2. METHODOLOGY 11_14
2.1. NumPy Library in Python 11
2.1.1 Data types in NumPy 12
2.2. Pandas Introduction 12

VI
2.3. Detection of Credit Card Fraud 14

3. STEPS FOR EXECUTING THE PROJECT 16


4. RESULTS AND DISCUSSION 22
5. CONCLUSION 24
6. FUTURE SCOPE 25
7. REFERENCES 26

VII
List of Figures

NAME PAGE NO
Figure 3.1. Block Diagram of the Project 16
Figure 3.2. Pie Chart of genuine and fraud cases 22
Figure 3.3. ROC Curve Analysis 23

VIII
List of Tables

NAME PAGE NO
Table 1.1 Arithmetic Operators 3
Table 1.2 Comparison Operators 4
Table 1.3 Assignment Operators 5
Table 1.4 Bitwise Operators 6
Table 1.5 Logical Operators 7

IX
CHAPTER-1
INTRODUCTION

1.1 INTRODUCTION TO PYTHON PROGRAMMING

A well-liked programming language is Python. In 1991, Guido van Rossum produced it,
and it became available.

Purpose :

 web development (server-side),


 software development,
 mathematics,
 system scripting.
 Web applications can be developed on a server using Python.
 Workflows can be made with Python and other technologies.
 Database systems are connectable with Python. Files can also be read and
changed by it.
 Big data management and advanced mathematical operations can both be done
with Python.
 Python can be used to produce software that is ready for production or for rapid
prototyping.

Uses of Python:

 Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
 Python has a simple syntax similar to the English language.
 Python has syntax that allows developers to write programs with fewer lines
than some other programming languages.
 Python operates on an interpreter system, allowing for the immediate execution
of written code. As a result, prototyping can proceed quickly.
 Python can be used in a functional, object-oriented, or procedural manner.

Dept. of ECE Narayana Engineering College, Nellore


1.2 DATATYPES AND OPERATORS

DATATYPES

The concept of data type is crucial in programming. Different forms of data


can be stored in variables, and different types can perform various functions.

Python has the following data types built-in by default, in these categories:

Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: Dict

Set Types: set, frozen set

Boolean Type: bool

Binary Types: bytes, byte array, memory view

None Type: None Type

Getting the Data Type

You can get the data type of any object by using the type() function:

Example: Print the type of variable x

x=5
print(type(x))

OPERATORS

Python language supports the following types of operators.

 Arithmetic Operators
 Comparison (Relational) Operators
 Assignment Operators
 Logical Operators
 Bitwise Operators

Dept. of ECE Narayana Engineering College, Nellore


1.2.1 Python Arithmetic Operators
Assume variable a holds 10 and variable b holds 20, then

Operator Description Example

+ Addition Adds values on either side of the operator. a+b=


30

- Subtraction Subtracts right hand operand from left hand operand. a–b=-
10

* Multiplies values on either side of the operator a*b=


Multiplication 200

/ Division Divides left hand operand by right hand operand b/a=2

% Modulus Divides left hand operand by right hand operand and returns b%a=
remainder 0

** Exponent Performs exponential (power) calculation on operators a**b =10


to the
power 20

// Floor Division - The division of operands where the result is 9//2 = 4


the quotient in which the digits after the decimal point are and
removed. But if one of the operands is negative, the result is 9.0//2.0
floored, i.e., rounded away from zero (towards negative = 4.0, -
infinity) − 11//3 = -
4, -
11.0//3 =
-4.0

1.2.2 Python Comparison Operators


These operatorsTABLE 1.1ARITHMETIC
evaluate the relationshipOPERATORS
between the values on either side
of them by comparing them. Relational operators is another name for them.
Assume variable a holds 10 and variable b holds 20, then

Operator Description Example

== If the values of two operands are equal, then the condition (a == b)

Dept. of ECE Narayana Engineering College, Nellore


becomes true. is not
true.

!= If values of two operands are not equal, then condition (a != b)


becomes true. is true.

<> If values of two operands are not equal, then condition (a <> b)
becomes true. is true.
This is
similar
to !=
operator.

> If the value of left operand is greater than the value of right (a > b) is
operand, then condition becomes true. not true.

< If the value of left operand is less than the value of right (a < b) is
operand, then condition becomes true. true.

>= If the value of left operand is greater than or equal to the (a >= b)
value of right operand, then condition becomes true. is not
true.

<= If the value of left operand is less than or equal to the value (a <= b)
of right operand, then condition becomes true. is true.

TABLE 1.2 COMPARISION OPERATORS

1.2.3 Python Assignment Operators


Assume variable a holds 10 and variable b holds 20, then −

Operator Description Example

= Assigns values from right side operands to left side c=a+b


operand assigns
value of a
+ b into c

+= Add AND It adds right operand to the left operand and assign c += a is
the result to left operand equivalent
to c = c +
a

-= Subtract It subtracts right operand from the left operand and c -= a is


AND assign the result to left operand equivalent
to c = c -
a

Dept. of ECE Narayana Engineering College, Nellore


*= Multiply It multiplies right operand with the left operand and c *= a is
AND assign the result to left operand equivalent
to c = c *
a

/= Divide It divides left operand with the right operand and c /= a is


AND assign the result to left operand equivalent
to c = c /
a

%= Modulus It takes modulus using two operands and assign the c %= a is


AND result to left operand equivalent
to c = c %
a

**= Exponent Performs exponential (power) calculation on c **= a is


AND operators and assign value to the left operand equivalent
to c = c
** a

//= Floor It performs floor division on operators and assign c //= a is


Division value to the left operand equivalent
to c = c //
a

TABLE 1.3 ASSIGNMENT OPERATORS

1.2.4 Python Bitwise Operators


There are following Bitwise operators supported by Python language.

Operator Description Example

& Binary AND Operator copies a bit to the result if it exists in (a & b)
both operands (means
0000 1100)

| Binary OR It copies a bit if it exists in either operand. (a | b) = 61


(means
0011 1101)

^ Binary XOR It copies the bit if it is set in one operand but (a ^ b) = 49


not both. (means
0011 0001)

Dept. of ECE Narayana Engineering College, Nellore


~ Binary Ones
Complement (~a ) = -61
(means
1100 0011
in 2's
It is unary and has the effect of 'flipping' bits. complement
form due to
a signed
binary
number.

<< Binary Left The left operands value is moved left by the a << 2 =
Shift number of bits specified by the right operand. 240 (means
1111 0000)

>> Binary Right The left operands value is moved right by the a >> 2 = 15
Shift number of bits specified by the right operand. (means
0000 1111)

TABLE 1.4 BITWISE OPERATORS

1.2.5 Python Logical Operators


There are following logical operators supported by Python language.
Assume variable a holds 10 and variable b holds 20 then

Operator Description Example

and Logical If both the operands are true then condition becomes (a and b)
AND true. is true.

or Logical OR If any of the two operands are non-zero then condition (a or b)


becomes true. is true.

not Logical Used to reverse the logical state of its operand. Not(a
NOT and b) is
false.

TABLE 1.5 LOGICAL OPERATORS

1.3 LOOPS

Loops are a crucial part of programming and are found in practically all programming
languages (Python, C, R, Visual Basic etc.). It is employed to repeatedly do one or
more actions up until a specified condition is met. It's primarily employed to automate
Dept. of ECE Narayana Engineering College, Nellore
routine tasks.

1.3.1 For Loop Python - Syntax and Examples


Like R and C programming language, you can use for loop in Python. It is
one of the most commonly used loop method to automate the repetitive tasks.

Suppose you are asked to print sequence of numbers from 1 to 9, increment by 2.


for i in range (1,10,2):
print(i)
Output
12345
range (1,10,2) means starts from 1 and ends with 9 (excluding 10), increment by 2.

1.3.2 While Loop

Code is constantly run through a while loop until a condition is met. And the
line in the programme that comes just after the loop is run when the condition changes
to false.
Program to print numbers from 1 to 5:
i=1
while (i<6):
print(i)
i+=1
output:
1
2
3
4
5

1.4 FUNCTIONS

A function is a section of code that only executes when called. You can supply
parameters—data—to a function. As a result, a function may return data.

Dept. of ECE Narayana Engineering College, Nellore


Creating a Function

In Python a function is defined using the def keyword:

Example:

def my_function ():


print ("Hello from a function")

Calling a Function

To call a function, use the function name followed by parenthesis:

Example:

def my_function ():


print ("Hello from a function")
my_function ()

1.5 OOPS AND CLASSES

Python is a computer language that emphasises objects. In Python, almost


everything is an object with properties and functions.

A Class is like an object constructor, or a "blueprint" for creating objects.

Create a Class

To create a class, use the keyword class:

Example

Create a class named MyClass, with a property named x:

class MyClass:
x=5

Create Object

Now we can use the class named MyClass to create objects:

Example

Create an object named p1, and print the value of x:

Dept. of ECE Narayana Engineering College, Nellore


p1 = MyClass ()
print (p1.x)

1.6 EXCEPTION HANDLING

An event that occurs during the execution of a programme and


obstructs the regular flow of the program's instructions is an exception. A Python script
typically raises an exception when it comes into a scenario that it cannot handle. A
Python object that describes an error is called an exception.

Syntax
Here is simple syntax of try....except...else blocks –
try:
You do your operations here;
except Exception I:
If there is Exception I, then execute this block.
except Exception II:
If there is Exception I, then execute this block.
else:
If there is no Exception then execute this block.

1.7 FILE HANDLING

File handling is an important part of any web application. Python has several
functions for creating, reading, updating, and deleting files.

There are four different methods (modes) for opening a file:

“r” – Read – Default value. Opens a file for reading, error if the file does not exist

“a” – Append – Opens a file for appending, creates the file if it does not exist

“w” – Write – Opens a file for writing, creates the file if it does not exist

“x”- Create - Creates the specified file, returns an error if the file exists
Dept. of ECE Narayana Engineering College, Nellore
“t” - Text - Default value. Text mode

“b” – Binary- Binary mode (e.g. Images)

Syntax

To open a file for reading it is enough to specify the name of the file:

f = open("demofile.txt")

The code above is the same as:

f = open ("demofile.txt", "rt")

Because "r" for read, and "t" for text are the default values, you do not need to
specify them.

CHAPTER-2
METHODOLOGY

2.1 NUMPY LIBRARY IN PYTHON

The Python package NumPy is used to manipulate arrays. Additionally, it has matrices,
Fourier transform, and functions for working in the area of linear algebra. In the year
2005, Travis Oliphant developed NumPy. You can use it for free because it is an open-
source project. Numerical Python is referred to as NumPy.

Create a NumPy ndarray Object

Dept. of ECE Narayana Engineering College, Nellore


NumPy is used to work with arrays. The array object in NumPy is
called ndarray.

We can create a NumPy ndarray object by using the array() function.

Example :

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr)

print(type(arr))

To create an ndarray, we can pass a list, tuple or any array-like object into
the array() method, and it will be converted into an ndarray:

Example:

Use a tuple to create a NumPy array:

import numpy as np

arr = np.array((1, 2, 3, 4, 5))

print(arr)
2.1.1 Data Types in NumPy

NumPy has some extra data types, and refer to data types with one
character, like i for integers, u for unsigned integers etc.

Below is a list of all data types in NumPy and the characters used to represent them.

 i - integer
 b - boolean
 u - unsigned integer
 f - float
 c - complex float
 m - timedelta
 M - datetime
 O - object

Dept. of ECE Narayana Engineering College, Nellore


 S - string
 U - unicode string
 V - fixed chunk of memory for other type (void )

2.2 PANDAS INTRODUCTION

Python's Pandas package is used to manipulate data sets. It offers tools for data
exploration, cleaning, analysis, and manipulation.

With the aid of Pandas, we can examine large data sets and draw conclusions based on
statistical principles. Pandas can organise disorganised data sets, making them readable
and useful. In data science, relevant data is crucial.

Pandas are also able to delete rows that are not relevant, or contains wrong values, like
empty or NULL values. This is called cleaning the data.

Installation of Pandas

If you have Python and PIP already installed on a system, then installation
of Pandas is very easy.

Install it using this command:

C:\Users\Your Name>pip install pandas

Import Pandas

Once Pandas is installed, import it in your applications by adding


the import keyword:

import pandas

Now Pandas is imported and ready to use.

Example:

import pandas

mydataset = { 'cars': ["BMW", "Volvo", "Ford"], 'passings': [3, 7, 2]}

Dept. of ECE Narayana Engineering College, Nellore


myvar = pandas.DataFrame(mydataset)
print(myvar)

Pandas as pd

Pandas is usually imported under the pd alias. Create an alias with the as keyword
while importing:

import pandas as pd

Now the Pandas package can be referred to as pd instead of pandas.

Example:

import pandas as pd

mydataset = { 'cars': ["BMW", "Volvo", "Ford"], 'passings': [3, 7, 2]}


myvar = pd.DataFrame(mydataset)
print(myvar)

Checking Pandas Version

The version string is stored under __version__ attribute.

Example:

import pandas as pd

print(pd.__version__)

2.3 DETECTION OF CREDIT CARD FRAUD

When the world was under lockdown and movement was restricted to an
absolute emergency- millions were introduced to the world of online shopping. The
convenience of online shopping helped e-commerce platforms record historic sales.
While that happened, it is no surprise that the rate of online financial fraud also
increased incredibly. Online fraud cases using credit and debit cards saw a historic

Dept. of ECE Narayana Engineering College, Nellore


upsurge of 225 percent during the COVID-19 pandemic in 2020 as compared to 2019.
As per the NCRB report, the tally of credit and debit card fraud stood at 1194 in 2020
compared to 367 in 2019.

There are several categories of credit card fraud that are prevalent in today’s time

 Lost/Stolen cards: People steal credit cards from the mail and use them
illegally on behalf of the owner. The process of blocking credit cards that have
been stolen and re-issuing them is a hassle for both customers and credit card
companies.

 Card Abuse: The customer buys goods and items on the credit card but has no
intention to pay back the amount charged by the bank for the same. These
customers stop answering the calls as the deadline to settle the dues approaches.

 Identity Theft: The customers apply illegitimate information, and they might
even steal the details of a genuine customer to apply for a credit card and then
misuse it. In such cases, even card blocking can not stop the credit card from
falling into the wrong hands.

 Merchant Abuse: Some merchants show illegal transactions (that never


occurred) for money laundering. For performing these illicit transactions, legal
Dept. of ECE Narayana Engineering College, Nellore
information of genuine credit card users is stolen to generate replicas of the
cards and use it for illegal work.

CHAPTER-3
STEPS FOR EXECUTING THE PROJECT

1. Introduction.
2. Credit Card Fraud Detection Dataset.
3. Data Exploration and Visualization.
4. Data Preparation.
5. Building and Training the Model.
6. Undersampling. NearMiss Methods.
7. Oversampling with SMOTE.
8. Appendix: Outlier Detection and Removal.

Dept. of ECE Narayana Engineering College, Nellore


Fig 3.1 Block diagram of the project

$ pip install sklearn==0.24.2 imbalanced-learn numpy pandas matplotlib seaborn

# Importing modules

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import seaborn as sns


from matplotlib import gridspec

#read the dataset

dataset = pd.read_csv("creditcard.csv")

# read the first 5 and last 5 rows of the data


dataset.head().append(dataset.tail())

Dept. of ECE Narayana Engineering College, Nellore


# check for relative proportion

print("Fraudulent Cases: " + str(len(dataset[dataset["Class"] == 1])))

print("Valid Transactions: " + str(len(dataset[dataset["Class"] == 0])))

print("Proportion of Fraudulent Cases: " + str(len(dataset[dataset["Class"] == 1])/


dataset.shape[0]))

# To see how small are the number of Fraud transactions

data_p = dataset.copy()

data_p[" "] = np.where(data_p["Class"] == 1 , "Fraud", "Genuine")

# plot a pie chart


data_p[" "].value_counts().plot(kind="pie")

Fraudulent Cases: 492

Valid Transactions: 284315


Proportion of Fraudulent Cases: 0.001727485630620034

# plot the named features

f, axes = plt.subplots(1, 2, figsize=(18,4), sharex = True)

amount_value = dataset['Amount'].values # values

time_value = dataset['Time'].values # values

sns.distplot(amount_value, hist=False, color="m", kde_kws={"shade": True},


ax=axes[0]).set_title('Distribution of Amount')

sns.distplot(time_value, hist=False, color="m", kde_kws={"shade": True},


ax=axes[1]).set_title('Distribution of Time')
plt.show()

print("Average Amount in a Fraudulent Transaction: " + str(dataset[dataset["Class"] ==


1]["Amount"].mean()))
print("Average Amount in a Valid Transaction: " + str(dataset[dataset["Class"] == 0]
["Amount"].mean()))

print("Summary of the feature - Amount" + "\n-------------------------------")


print(dataset["Amount"].describe())
Dept. of ECE Narayana Engineering College, Nellore
Name: Amount, dtype: float64

# Reorder the columns Amount, Time then the rest

data_plot = dataset.copy()

amount = data_plot['Amount']

data_plot.drop(labels=['Amount'], axis=1, inplace = True)

data_plot.insert(0, 'Amount', amount)

# Plot the distributions of the features

columns = data_plot.iloc[:,0:30].columns

plt.figure(figsize=(12,30*4))

grids = gridspec.GridSpec(30, 1)

for grid, index in enumerate(data_plot[columns]):

ax = plt.subplot(grids[grid])

sns.distplot(data_plot[index][data_plot.Class == 1], hist=False, kde_kws={"shade":


True}, bins=50)

sns.distplot(data_plot[index][data_plot.Class == 0], hist=False, kde_kws={"shade":


True}, bins=50)

ax.set_xlabel("")

ax.set_title("Distribution of Column: " + str(index))


plt.show()

# check for null values

dataset.isnull().shape[0]

print("Non-missing values: " + str(dataset.isnull().shape[0]))


print("Missing values: " + str(dataset.shape[0] - dataset.isnull().shape[0]))

from sklearn.preprocessing import RobustScaler

scaler = RobustScaler().fit(dataset[["Time", "Amount"]])

dataset[["Time", "Amount"]] = scaler.transform(dataset[["Time", "Amount"]])

Dept. of ECE Narayana Engineering College, Nellore


dataset.head().append(dataset.tail())

# Separate response and features Undersampling before cross validation will lead to
overfiting

y = dataset["Class"] # target

X = dataset.iloc[:,0:30]

# Use SKLEARN for the split

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(

X, y, test_size = 0.2, random_state = 42)


X_train.shape, X_test.shape, y_train.shape, y_test.shape
((227845, 30), (56962, 30), (227845,), (56962,))

# Create the cross validation framework

from sklearn.model_selection import StratifiedKFold

from sklearn.model_selection import GridSearchCV, cross_val_score,


RandomizedSearchCV
kf = StratifiedKFold(n_splits=5, random_state = None, shuffle = False)

# Import the imbalance Learn module

from imblearn.pipeline import make_pipeline ## Create a Pipeline using the provided


estimators .

from imblearn.under_sampling import NearMiss ## perform Under-sampling based on


NearMiss methods.

from imblearn.over_sampling import SMOTE ## PerformOver-sampling class that


uses SMOTE.

# import the metrics

from sklearn.metrics import roc_curve, roc_auc_score, accuracy_score, recall_score,


precision_score, f1_score

# Import the classifiers

from sklearn.linear_model import LogisticRegression


Dept. of ECE Narayana Engineering College, Nellore
from sklearn.svm import SVC

from sklearn.neighbors import KNeighborsClassifier

from sklearn.tree import DecisionTreeClassifier


from sklearn.ensemble import RandomForestClassifier

# Fit and predict

rfc = RandomForestClassifier()

rfc.fit(X_train, y_train)

y_pred = rfc.predict(X_test)

# For the performance let's use some metrics from SKLEARN module

from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score

print("The accuracy is", accuracy_score(y_test, y_pred))

print("The precision is", precision_score(y_test, y_pred))

print("The recall is", recall_score(y_test, y_pred))


print("The F1 score is", f1_score(y_test, y_pred))

Dept. of ECE Narayana Engineering College, Nellore


CHAPTER-4
RESULTS AND DISCUSSION

Fraudulent Cases: 492


Valid Transactions: 284315
Proportion of Fraudulent Cases: 0.001727485630620034

Fig. 3.2 Pie chart of genuine and fraud cases

Average Amount in a Fraudulent Transaction: 122.21132113821133


Average Amount in a Valid Transaction: 88.29102242225574

Dept. of ECE Narayana Engineering College, Nellore


Summary of the feature - Amount
-------------------------------
count 284807.000000
mean 88.349619
std 250.120109
min 0.000000
25% 5.600000
50% 22.000000
75% 77.165000
Name: Amount, dtype: float64
Non-missing values: 284807
Missing values: 0
((227845, 30), (56962, 30), (227845,), (56962,))
The accuracy is 0.9996137776061234
The precision is 0.975
The recall is 0.7959183673469388
The F1 score is 0.8764044943820225

Dept. of ECE Narayana Engineering College, Nellore


Fig 3.3 ROC Curve Analysis

CHAPTER-5
CONCLUSION

Since the entire dataset


consists of only two days’
transaction

A business can suffer sudden, significant damages from only one fraud attack, not just

financially. Fraudulent attacks can harm a company's reputation irreparably, lose

customers, and possibly have legal repercussions. According to the proverb, prevention
Dept. of ECE Narayana Engineering College, Nellore
is always preferable to treatment.

Since the entire dataset


consists of only two days’
transaction
CHAPTER-6

Dept. of ECE Narayana Engineering College, Nellore


FUTURE SCOPE

Businesses should have at least some fraud detection procedures in place,


especially those that are most susceptible to financial fraud. Banks, credit card
companies, insurance companies, and enterprises that handle sizable internet
transactions are a few examples. Any firm is susceptible to fraud, but those with high
transaction volumes, high transaction values, or contactless business models are more
vulnerable.

CHAPTER-7
REFERENCES
[1] “Credit Card Fraud Detection: A Novel Approach Using Aggregation Strategy and
Feedback Mechanism.” IEEE Internet of Things Journal 5

Dept. of ECE Narayana Engineering College, Nellore


[2]Credit Card Fraud Detection using Deep Learning based on Auto-Encoder and
Restricted Boltzmann Machine. International Journal of Advanced Computer Science
and Applications.

[3] “Supervised Machine Learning Algorithms for Credit Card Fraudulent Transaction
Detection: A Comparative Study.”

[4]“Credit Card Fraud Detection Using AdaBoost and Majority Voting.” IEEE Access.

[5]Roy, Abhimanyu, et al. “Deep Learning Detecting Fraud in Credit Card


Transactions.” Systems and Information Engineering Design Symposium (SIEDS)

[6]Xuan, Shiyang, et al. “Random Forest for Credit Card Fraud Detection.” 2018 IEEE
15th International Conference on Networking, Sensing and Control (ICNSC).

[7]Awoyemi, John O., et al. “Credit Card Fraud Detection Using Machine Learning
Techniques: A Comparative Analysis.”
“Plastic C

Dept. of ECE Narayana Engineering College, Nellore

You might also like