-
Notifications
You must be signed in to change notification settings - Fork 1
/
comparison_tree.py
50 lines (40 loc) · 1.08 KB
/
comparison_tree.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
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
import pandas as pd
import numpy as np
import time
import pprint
from data_importation import importation
from print_time import print_time
########################
### Data Importation ###
########################
path = 'data/data.txt'
X,y = importation(path)
X_train, X_test, y_train, y_test = train_test_split(X, y,test_size = 0.25, random_state = 4)
######################
### Model Training ###
######################
print("Training...")
tree = DecisionTreeClassifier(max_depth = 10, min_samples_leaf = 4)
start = time.time()
tree.fit(X_train, y_train)
end = time.time()
print("Training time:")
print_time(start,end)
#####################
### Model Testing ###
#####################
print("Testing...")
start = time.time()
y_pred = tree.predict(X_test)
end = time.time()
print("Testing time:")
print_time(start,end)
################
### Accuracy ###
################
score = accuracy_score(y_test, y_pred)
print("Accuracy score:")
print(score)