forked from serengil/chefboost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDispatcher.py
100 lines (68 loc) · 2.81 KB
/
Dispatcher.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import Chefboost as chef
import pandas as pd
import numpy as np
#------------------------------------
#gradient boosting regression tree
config = {'enableGBM': True, 'epochs': 7, 'learning_rate': 1}
df = pd.read_csv("dataset/golf4.txt")
model = chef.fit(df.copy(), config)
chef.save_model(model)
prediction = chef.predict(model, ['Sunny',85,85,'Weak'])
print("Prediction: ",prediction)
restored_model = chef.load_model("model.pkl")
prediction = chef.predict(restored_model, ['Sunny',85,85,'Weak'])
print("Prediction: ",prediction)
#------------------------------------
#gradient boosting classification
config = {'algorithm': 'ID3', 'enableGBM': True, 'epochs': 5, 'learning_rate': 1}
model = chef.fit(pd.read_csv("dataset/iris.data", names=["Sepal length","Sepal width","Petal length","Petal width","Decision"]), config)
test_set = [7.0,3.2,4.7,1.4]
prediction = chef.predict(model, test_set)
print(prediction)
#------------------------------------
#regular decision tree
config = {'algorithm': 'C4.5'}
model = chef.fit(pd.read_csv("dataset/golf2.txt"), config)
prediction = chef.predict(model, ['Sunny',85,85,'Weak'])
#prediction = model[0].findDecision(['Sunny',85,85,'Weak'])
print(prediction)
#------------------------------------
#regular decision tree
config = {'algorithm': 'ID3'}
model = chef.fit(pd.read_csv("dataset/golf2.txt"), config)
prediction = chef.predict(model, ['Sunny',85,85,'Weak'])
#prediction = model[0].findDecision(['Sunny',85,85,'Weak'])
print(prediction)
#------------------------------------
#regular decision tree
config = {'algorithm': 'CART'}
model = chef.fit(pd.read_csv("dataset/golf.txt"), config)
prediction = chef.predict(model, ['Sunny','Hot','High','Weak'])
print(prediction)
#------------------------------------
#regular decision tree
config = {'algorithm': 'ID3'}
model = chef.fit(pd.read_csv("dataset/golf.txt"), config)
prediction = chef.predict(model, ['Sunny', 'Hot', 'High', 'Weak'])
print(prediction)
#------------------------------------
#regular regression tree
config = {'algorithm': 'Regression'}
model = chef.fit(pd.read_csv("dataset/golf3.txt"), config)
prediction = chef.predict(model, ['Sunny', 'Hot', 'High', 'Weak'])
print(prediction)
#---------------------------------
#adaboost
config = {'enableAdaboost': True, 'num_of_weak_classifier': 4}
model = chef.fit(pd.read_csv("dataset/adaboost.txt"), config)
prediction = chef.predict(model, [4, 3.5])
print(prediction)
#------------------------------------
#random forest - classification
config = {'algorithm': 'ID3', 'enableRandomForest': True, 'num_of_trees': 5,}
model = chef.fit(pd.read_csv("dataset/car.data"), config)
prediction = chef.predict(model, ['vhigh','vhigh',2,'2','small','low'])
print(prediction)
prediction = chef.predict(model, ['high','high',4,'more','big','high'])
print(prediction)
#------------------------------------