12
12
array([0, 1])
13
13
"""
14
14
15
+ from typing import Any
16
+
15
17
import numpy as np
16
- from typing import Any , Dict , List
17
18
18
19
19
20
class AdaBoost :
@@ -23,8 +24,8 @@ def __init__(self, n_estimators: int = 50) -> None:
23
24
n_estimators: Number of boosting rounds.
24
25
"""
25
26
self .n_estimators : int = n_estimators
26
- self .alphas : List [float ] = [] # Weights for each weak learner
27
- self .models : List [ Dict [str , Any ]] = [] # List of weak learners (stumps)
27
+ self .alphas : list [float ] = [] # Weights for each weak learner
28
+ self .models : list [ dict [str , Any ]] = [] # List of weak learners (stumps)
28
29
29
30
def fit (self , feature_matrix : np .ndarray , target : np .ndarray ) -> None :
30
31
"""Fit AdaBoost model.
@@ -77,11 +78,11 @@ def _build_stump(
77
78
feature_matrix : np .ndarray ,
78
79
target_signed : np .ndarray ,
79
80
sample_weights : np .ndarray ,
80
- ) -> Dict [str , Any ]:
81
+ ) -> dict [str , Any ]:
81
82
"""Find the best decision stump for current weights."""
82
83
n_samples , n_features = feature_matrix .shape
83
84
min_error = float ("inf" )
84
- best_stump : Dict [str , Any ] = {}
85
+ best_stump : dict [str , Any ] = {}
85
86
for feature in range (n_features ):
86
87
thresholds = np .unique (feature_matrix [:, feature ])
87
88
for threshold in thresholds :
0 commit comments