-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCreditCard_ML.py
62 lines (43 loc) · 1.72 KB
/
CreditCard_ML.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn.metrics import f1_score, accuracy_score, recall_score
from sklearn import svm
from sklearn.ensemble import RandomForestClassifier
#A macro-average will compute the metric independently for each class
# and then take the average
#a micro-average will aggregate the contributions of all classes to compute
# the average metric.
data = pd.read_csv('creditcard.csv', skiprows=[0], header=None)
X = data.iloc[:, 0:30]
y = data.iloc[:, -1]
X_train,X_test,y_train,y_test = train_test_split(X, y, test_size=0.2, shuffle= False)
logreg= LogisticRegression()
logreg.fit(X_train, y_train)
predLogreg = logreg.predict(X_test)
print("-------------------------LOGISTIC REGRESSION-------------------------------------------")
print("Accuracy")
print(accuracy_score(y_test,predLogreg))
print("F1 score")
print(f1_score(y_test, predLogreg, average='macro'))
print("Recall")
print(recall_score(y_test, predLogreg, average='macro'))
# svc = svm.SVC()
# svc.fit(X_train, y_train)
# predSvc = svc.predict(X_test)
#
# print("-------------------------SVM-------------------------------------------")
# print("Accuracy")
# print(accuracy_score(y_test,predSvc))
# print("F1 score")
# print(f1_score(y_test, predSvc, average='macro'))
rcf = RandomForestClassifier( random_state=0)
rcf.fit(X_train, y_train)
predRFC = rcf.predict(X_test)
print("-------------------------Random Forest Classifier-------------------------------------------")
print("Accuracy")
print(accuracy_score(y_test,predRFC))
print("F1 score")
print(f1_score(y_test, predRFC, average='macro'))
print("Recall")
print(recall_score(y_test, predRFC, average='macro'))