-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetecting.py
More file actions
50 lines (41 loc) · 1.41 KB
/
Copy pathdetecting.py
File metadata and controls
50 lines (41 loc) · 1.41 KB
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
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
# Load the data set
data = pd.read_csv('dataset.csv')
# Create a dictionary to map the values of 'type'
type_mapping = {
'CASH_OUT': 1, 'PAYMENT': 2,
'CASH_IN': 3, 'TRANSFER': 4,
'DEBIT': 5
}
# Create a dictionary to map the values of 'isFraud'
fraud_mapping = {
0: 'Not Fraud', 1: 'Fraud'
}
# Map the values of 'type' and 'isFraud'
data['type'] = data['type'].map(type_mapping)
data['isFraud'] = data['isFraud'].map(fraud_mapping)
# Create the input (x) and output (y) variables
x = data[['type', 'amount', 'oldbalanceOrg', 'newbalanceOrig']].values
y = data['isFraud'].values
# Split the data set into training and testing
xtrain, xtest, ytrain, ytest = train_test_split(
x,
y,
test_size=0.10,
random_state=42
)
# Create and train the decision tree model
model = DecisionTreeClassifier()
model.fit(xtrain, ytrain)
# Calculate the accuracy of the model on the test set
accuracy = accuracy_score(ytest, model.predict(xtest))
print(f'Accuracy: {accuracy}')
# Make a prediction with new data
# PS: You can replace this data with your own personal data
features = np.array([[4, 9000.60, 9000.60, 0.0]])
print('-------------------- Printed results --------------------')
print(model.predict(features))