6
6
from xgboost import XGBClassifier
7
7
8
8
9
- def data_handling (data : list ) -> tuple [list ,list ,list ]:
9
+ def data_handling (data : list ) -> tuple [list , list , list ]:
10
10
# Split dataset into train and test data
11
- x = (data ["data" ],data ["target" ],data [' target_names' ]) # data is features
11
+ x = (data ["data" ], data ["target" ], data [" target_names" ]) # data is features
12
12
return x
13
13
14
14
15
- def xgboost (features : list , target : list ,test_features : list ,test_targets : list ,namesofflowers : list ) -> None :
15
+ def xgboost (
16
+ features : list ,
17
+ target : list ,
18
+ test_features : list ,
19
+ test_targets : list ,
20
+ namesofflowers : list ,
21
+ ) -> None :
16
22
classifier = XGBClassifier ()
17
23
classifier .fit (features , target )
18
24
# Display Confusion Matrix of Classifier
@@ -28,6 +34,7 @@ def xgboost(features: list, target: list,test_features: list,test_targets: list,
28
34
plt .title ("Normalized Confusion Matrix - IRIS Dataset" )
29
35
plt .show ()
30
36
37
+
31
38
def main () -> None :
32
39
33
40
"""
@@ -38,14 +45,16 @@ def main() -> None:
38
45
39
46
# Load Iris dataset
40
47
iris = load_iris ()
41
-
48
+
42
49
features , target , names = data_handling (iris )
43
-
50
+
44
51
x_train , x_test , y_train , y_test = train_test_split (
45
- features , target , test_size = 0.25 )
52
+ features , target , test_size = 0.25
53
+ )
46
54
47
55
# XGBoost Classifier
48
- xgboost (x_train , y_train ,x_test ,y_test ,names )
56
+ xgboost (x_train , y_train , x_test , y_test , names )
57
+
49
58
50
59
if __name__ == "__main__" :
51
60
main ()
0 commit comments