File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ """xgboostclassifier.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1UlMmSrfKLuRW9LPCz6BvDDJMPgPhO-yu
8
+ """
9
+
10
+ # XGBoost Classifier Example
11
+ from matplotlib import pyplot as plt
12
+ from sklearn .datasets import load_iris
13
+ from xgboost import XGBClassifier
14
+ from sklearn .metrics import plot_confusion_matrix
15
+ from sklearn .model_selection import train_test_split
16
+
17
+
18
+ def main ():
19
+
20
+ """
21
+ The Url for the algorithm
22
+ https://xgboost.readthedocs.io/en/stable/
23
+ Iris type dataset is used to demonstrate algorithm.
24
+ """
25
+
26
+ # Load Iris dataset
27
+ iris = load_iris ()
28
+
29
+ # Split dataset into train and test data
30
+ x = iris ["data" ] # features
31
+ y = iris ["target" ]
32
+ x_train , x_test , y_train , y_test = train_test_split (
33
+ x , y , test_size = 0.3 , random_state = 1
34
+ )
35
+
36
+ # XGBoost Classifier
37
+ xgb = XGBClassifier ()
38
+ xgb .fit (x_train , y_train )
39
+
40
+ # Display Confusion Matrix of Classifier
41
+ plot_confusion_matrix (
42
+ xgb ,
43
+ x_test ,
44
+ y_test ,
45
+ display_labels = iris ["target_names" ],
46
+ cmap = "Blues" ,
47
+ normalize = "true" ,
48
+ )
49
+ plt .title ("Normalized Confusion Matrix - IRIS Dataset" )
50
+ plt .show ()
51
+
52
+
53
+ if __name__ == "__main__" :
54
+ main ()
You can’t perform that action at this time.
0 commit comments