-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
38 lines (30 loc) · 1.12 KB
/
utils.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
import pandas as pd
import csv
from datetime import datetime
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import accuracy_score, confusion_matrix
def calculate_accuracy(y_test, y_pred):
return accuracy_score(y_pred,y_test)
def calculate_matrix_confusion(y_test, y_pred):
return confusion_matrix(y_test, y_pred)
def create_train_test_database(path):
dataset = pd.read_csv(path)
columns = list(dataset.columns)
scaler = MinMaxScaler()
dataset[columns] = scaler.fit_transform(dataset)
X_train = dataset.loc[dataset['target'] == 1]
X_train = X_train.iloc[:,1:]
X_train = X_train.to_numpy()
X_test = dataset.loc[dataset['target'] == 0]
X_test = X_test.iloc[:,1:]
X_test = X_test.to_numpy()
return columns, X_train, X_test
def create_csv_file(columns, frauds, not_frauds):
now = datetime.now()
with open('./database/final_classification_{}.csv'.format(now), 'w', newline='') as file:
writer = csv.writer(file)
new_columns = ['distance'] + columns
rows = []
rows.append(new_columns)
rows = rows + frauds + not_frauds
writer.writerows(rows)