forked from RRdmlearning/Machine-Learning-From-Scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgbdt_classifier_example.py
40 lines (27 loc) · 936 Bytes
/
gbdt_classifier_example.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
from __future__ import division, print_function
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
# Import helper functions
from utils import train_test_split, accuracy_score
from utils.loss_functions import CrossEntropy
from utils import Plot
from gradient_boosting_decision_tree.gbdt_model import GBDTClassifier
def main():
print ("-- Gradient Boosting Classification --")
data = datasets.load_iris()
X = data.data
y = data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4)
print(y_train)
clf = GBDTClassifier()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print ("Accuracy:", accuracy)
Plot().plot_in_2d(X_test, y_pred,
title="Gradient Boosting",
accuracy=accuracy,
legend_labels=data.target_names)
if __name__ == "__main__":
main()