-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodeling.py
More file actions
49 lines (26 loc) · 1.47 KB
/
modeling.py
File metadata and controls
49 lines (26 loc) · 1.47 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
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier, plot_tree
from sklearn.neighbors import KNeighborsClassifier
#this function creates a random forest model and prints train and validation accuracy
def r_forest(X_train, y_train, X_val, y_val):
rf = RandomForestClassifier(max_depth=5, random_state=42)
rf.fit(X_train, y_train)
print(f'Train Accuracy = {rf.score(X_train, y_train)}')
print(f'Validate Accuracy = {rf.score(X_val, y_val)}')
#this function creates a decision tree model and prints train and validation accuracy
def d_tree(X_train, y_train, X_val, y_val):
dt = DecisionTreeClassifier(max_depth=5, random_state=42)
dt.fit(X_train, y_train)
print(f'Train Accuracy = {dt.score(X_train, y_train)}')
print(f'Validate Accuracy = {dt.score(X_val, y_val)}')
#this function creates a K-Nearest Neighbor model and prints train and validation accuracy
def knn_m(X_train, y_train, X_val, y_val):
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(X_train, y_train)
print(f'Train Accuracy = {knn.score(X_train, y_train)}')
print(f'Validate Accuracy = {knn.score(X_val, y_val)}')
#this function prints out test accuracy of a decision tree module
def d_tree_test(X_train, y_train, X_test, y_test):
dt = DecisionTreeClassifier(max_depth=5, random_state=42)
dt.fit(X_train, y_train)
print(f'Test Accuracy = {dt.score(X_test, y_test)}')