Rakesh12345 commited on
Commit
55018bb
1 Parent(s): 51b5e18

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +152 -0
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Final_project_of_Credit_Card_Fraud_Detection(1).ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1PSHcV_bp0wcT0Kl_f2n5QwtlOZj3M5BV
8
+ """
9
+
10
+ import pandas as pd
11
+ import seaborn as sns
12
+ import matplotlib.pyplot as plt
13
+
14
+ data=pd.read_csv('/content/data4.csv')
15
+
16
+ data.head()
17
+
18
+ data.shape
19
+
20
+ data.isnull().sum().sum()
21
+
22
+ data.keys()
23
+
24
+ data.info()
25
+
26
+ data=data.drop(['Unnamed: 0','nameOrig','nameDest'],axis=1)
27
+
28
+ data.shape
29
+
30
+ data['isFraud'].value_counts()
31
+
32
+ plt.pie(data['isFraud'].value_counts(),labels=['Not_Fraud','Fraud'],autopct='%0.2f%%')
33
+ plt.show()
34
+
35
+ #sns.countplot('isFraud',data=data)
36
+ sns.countplot(data=data, x="type", hue="isFraud")
37
+ plt.show()
38
+
39
+ plt.figure(figsize=(6,8))
40
+ sns.countplot(data=data, x="isFraud", hue="type")
41
+ plt.show()
42
+
43
+ data.tail()
44
+
45
+ data['type'].value_counts()
46
+
47
+
48
+
49
+ dict1={'CASH_OUT':0,'TRANSFER':1,'PAYMENT':2,'CASH_IN':3,'DEBIT':4}
50
+
51
+ data['type']=data['type'].map(dict1)
52
+
53
+ data.head()
54
+
55
+ X=data.drop('isFraud',axis=1)
56
+
57
+ X
58
+
59
+ y=data['isFraud']
60
+
61
+ y
62
+
63
+ from sklearn.model_selection import train_test_split
64
+
65
+ X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.30,random_state=0)
66
+
67
+ print(X_train.shape)
68
+ print(X_test.shape)
69
+ print(y_train.shape)
70
+ print(y_test.shape)
71
+
72
+ from sklearn.preprocessing import StandardScaler
73
+
74
+ sc=StandardScaler()
75
+
76
+ X_train_sc=sc.fit_transform(X_train)
77
+ X_test_sc=sc.transform(X_test)
78
+
79
+ X_train_sc
80
+
81
+ X_test_sc
82
+
83
+ from sklearn.linear_model import LogisticRegression
84
+
85
+ model1=LogisticRegression()
86
+
87
+ model1.fit(X_train_sc,y_train)
88
+
89
+ y_pred1=model1.predict(X_test_sc)
90
+
91
+ from sklearn.metrics import classification_report
92
+
93
+ print(classification_report(y_test,y_pred1))
94
+
95
+ from sklearn.naive_bayes import GaussianNB
96
+
97
+ model2=GaussianNB()
98
+
99
+ model2.fit(X_train_sc,y_train)
100
+
101
+ y_pred2=model2.predict(X_test_sc)
102
+
103
+ print(classification_report(y_test,y_pred2))
104
+
105
+ from sklearn.neighbors import KNeighborsClassifier
106
+
107
+ model3=KNeighborsClassifier()
108
+
109
+ model3.fit(X_train_sc,y_train)
110
+
111
+ y_pred3=model3.predict(X_test_sc)
112
+
113
+ print(classification_report(y_test,y_pred3))
114
+
115
+ from sklearn.tree import DecisionTreeClassifier
116
+
117
+ model4=DecisionTreeClassifier()
118
+
119
+ model4.fit(X_train_sc,y_train)
120
+
121
+ y_pred4=model4.predict(X_test_sc)
122
+
123
+ print(classification_report(y_test,y_pred4))
124
+
125
+ from sklearn import tree
126
+
127
+ plt.figure(figsize=(10,10))
128
+ tree.plot_tree(model4,filled=True)
129
+ plt.show()
130
+
131
+ from sklearn.ensemble import RandomForestClassifier,AdaBoostClassifier
132
+
133
+ model5=RandomForestClassifier()
134
+
135
+ model5.fit(X_train_sc,y_train)
136
+
137
+ y_pred5=model5.predict(X_test_sc)
138
+
139
+ print(classification_report(y_test,y_pred5))
140
+
141
+ model6=AdaBoostClassifier()
142
+
143
+ model6.fit(X_train_sc,y_train)
144
+
145
+ y_pred6=model6.predict(X_test_sc)
146
+
147
+ print(classification_report(y_test,y_pred6))
148
+
149
+ model5.predict([[239,2,5178.72,400705.00,395526.28,0.00,0.00]])
150
+
151
+ model5.predict([[369,0,89596.79,89596.79,0.0,0.00,89596.79]])
152
+