Skip to content

Commit 89aff73

Browse files
committed
Update all examples
1 parent e889785 commit 89aff73

14 files changed

+107
-99
lines changed

examples/exam_adaboost_classification.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Define param bounds
1818

19-
# param_grid = { ==> This is for GridSearchCV, show you how to convert to our MetaSearchCV
19+
# param_grid = { ==> This is for GridSearchCV, based on this, you can convert to our MetaSearchCV bounds
2020
# 'n_estimators': [50, 100, 200], # Number of weak learners to use
2121
# 'learning_rate': [0.01, 0.1, 0.5, 1.0], # Weight applied to each classifier at each boosting iteration
2222
# 'base_estimator__max_depth': [1, 3, 5], # Depth of the base decision tree
@@ -25,11 +25,11 @@
2525
# }
2626

2727
param_bounds = [
28-
IntegerVar(lb=20, ub=100, name="n_estimators"), # Số lượng weak learners
29-
FloatVar(lb=0.01, ub=1.0, name="learning_rate"), # Tốc độ học
30-
IntegerVar(lb=2, ub=5, name="estimator__max_depth"), # Độ sâu của cây quyết định cơ sở
31-
IntegerVar(lb=2, ub=6, name="estimator__min_samples_split"), # Số lượng mẫu tối thiểu để một node được chia
32-
IntegerVar(lb=1, ub=4, name="estimator__min_samples_leaf"), # Số lượng mẫu tối thiểu tại một node lá
28+
IntegerVar(lb=20, ub=100, name="n_estimators"),
29+
FloatVar(lb=0.01, ub=1.0, name="learning_rate"),
30+
IntegerVar(lb=2, ub=5, name="estimator__max_depth"),
31+
IntegerVar(lb=2, ub=6, name="estimator__min_samples_split"),
32+
IntegerVar(lb=1, ub=4, name="estimator__min_samples_leaf"),
3333
]
3434

3535
# Initialize and fit MetaSearchCV
@@ -43,7 +43,8 @@
4343
scoring="AS", # or any custom scoring like "F1_macro"
4444
seed=42,
4545
n_jobs=2,
46-
verbose=True
46+
verbose=True,
47+
mode='single', n_workers=None, termination=None
4748
)
4849

4950
searcher.fit(X_train, y_train)

examples/exam_adaboost_regression.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
data.X_test = scaler_X.transform(data.X_test)
2323

2424
data.y_train, scaler_y = data.scale(data.y_train, scaling_methods=("standard", "minmax"))
25-
data.y_train = data.y_train.ravel()
26-
data.y_test = scaler_y.transform(data.y_test.reshape(-1, 1)).ravel()
25+
data.y_test = scaler_y.transform(data.y_test)
2726

2827
# Define param bounds
2928

@@ -36,11 +35,11 @@
3635
# }
3736

3837
param_bounds = [
39-
IntegerVar(lb=20, ub=100, name="n_estimators"), # Số lượng weak learners
40-
FloatVar(lb=0.01, ub=1.0, name="learning_rate"), # Tốc độ học
41-
IntegerVar(lb=2, ub=5, name="estimator__max_depth"), # Độ sâu của cây quyết định cơ sở
42-
IntegerVar(lb=2, ub=6, name="estimator__min_samples_split"), # Số lượng mẫu tối thiểu để một node được chia
43-
IntegerVar(lb=1, ub=4, name="estimator__min_samples_leaf"), # Số lượng mẫu tối thiểu tại một node lá
38+
IntegerVar(lb=20, ub=100, name="n_estimators"),
39+
FloatVar(lb=0.01, ub=1.0, name="learning_rate"),
40+
IntegerVar(lb=2, ub=5, name="estimator__max_depth"),
41+
IntegerVar(lb=2, ub=6, name="estimator__min_samples_split"),
42+
IntegerVar(lb=1, ub=4, name="estimator__min_samples_leaf"),
4443
]
4544

4645
# Initialize and fit MetaSearchCV
@@ -54,7 +53,8 @@
5453
scoring="MSE", # or any custom scoring like "F1_macro"
5554
seed=42,
5655
n_jobs=2,
57-
verbose=True
56+
verbose=True,
57+
mode='single', n_workers=None, termination=None
5858
)
5959

6060
searcher.fit(data.X_train, data.y_train)

examples/exam_decision_tree_classification.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515

1616
# Define param bounds
1717

18-
# param_grid = { ==> This is for GridSearchCV, show you how to convert to our MetaSearchCV
19-
# 'criterion': ['gini', 'entropy', 'log_loss'], # Hàm đo mức độ phân tách (classification)
20-
# 'splitter': ['best', 'random'], # Cách chọn cách chia tại mỗi node
21-
# 'max_depth': [None, 5, 10, 20, 30], # Độ sâu tối đa của cây
22-
# 'min_samples_split': [2, 5, 10], # Số lượng mẫu tối thiểu để một node được chia
23-
# 'min_samples_leaf': [1, 2, 4], # Số lượng mẫu tối thiểu tại một node lá
24-
# 'max_features': [None, 'sqrt', 'log2'], # Số đặc trưng tối đa khi tìm split tốt nhất
25-
# 'max_leaf_nodes': [None, 10, 20, 50], # Giới hạn số lượng node lá
26-
# 'ccp_alpha': [0.0, 0.01, 0.05, 0.1], # Complexity parameter để cắt tỉa cây (post-pruning)
18+
# param_grid = { ==> This is for GridSearchCV, base on this, you can convert to our MetaSearchCV bounds
19+
# 'criterion': ['gini', 'entropy', 'log_loss'],
20+
# 'splitter': ['best', 'random'],
21+
# 'max_depth': [None, 5, 10, 20, 30],
22+
# 'min_samples_split': [2, 5, 10],
23+
# 'min_samples_leaf': [1, 2, 4],
24+
# 'max_features': [None, 'sqrt', 'log2'],
25+
# 'max_leaf_nodes': [None, 10, 20, 50],
26+
# 'ccp_alpha': [0.0, 0.01, 0.05, 0.1],
2727
# }
2828

2929
param_bounds = [
30-
StringVar(valid_sets=("gini", "entropy", "log_loss"), name="criterion"), # Hàm đo mức độ phân tách (classification)
31-
StringVar(valid_sets=("best", "random"), name="splitter"), # Cách chọn cách chia tại mỗi node
32-
IntegerVar(lb=2, ub=15, name="max_depth"), # Độ sâu tối đa của cây
33-
IntegerVar(lb=2, ub=10, name="min_samples_split"), # Số lượng mẫu tối thiểu để một node được chia
34-
IntegerVar(lb=1, ub=5, name="min_samples_leaf"), # Số lượng mẫu tối thiểu tại một node lá
35-
StringVar(valid_sets=("sqrt", "log2"), name="max_features"), # Số đặc trưng tối đa khi tìm split tốt nhất
36-
IntegerVar(lb=2, ub=30, name="max_leaf_nodes"), # Giới hạn số lượng node lá
37-
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"), # Complexity parameter để cắt tỉa cây (post-pruning)
30+
StringVar(valid_sets=("gini", "entropy", "log_loss"), name="criterion"),
31+
StringVar(valid_sets=("best", "random"), name="splitter"),
32+
IntegerVar(lb=2, ub=15, name="max_depth"),
33+
IntegerVar(lb=2, ub=10, name="min_samples_split"),
34+
IntegerVar(lb=1, ub=5, name="min_samples_leaf"),
35+
StringVar(valid_sets=("sqrt", "log2"), name="max_features"),
36+
IntegerVar(lb=2, ub=30, name="max_leaf_nodes"),
37+
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"),
3838
]
3939

4040
# Initialize and fit MetaSearchCV
@@ -48,7 +48,8 @@
4848
scoring="AS", # or any custom scoring like "F1_macro"
4949
seed=42,
5050
n_jobs=2,
51-
verbose=True
51+
verbose=True,
52+
mode='single', n_workers=None, termination=None
5253
)
5354

5455
searcher.fit(X_train, y_train)

examples/exam_decision_tree_regression.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,30 @@
2121
data.X_test = scaler_X.transform(data.X_test)
2222

2323
data.y_train, scaler_y = data.scale(data.y_train, scaling_methods=("standard", "minmax"))
24-
data.y_train = data.y_train.ravel()
25-
data.y_test = scaler_y.transform(data.y_test.reshape(-1, 1)).ravel()
24+
data.y_test = scaler_y.transform(data.y_test)
2625

2726
# Define param bounds
2827

29-
# param_grid = { ==> This is for GridSearchCV, show you how to convert to our MetaSearchCV
28+
# param_grid = { ==> This is for GridSearchCV, base on this, you can convert to our MetaSearchCV bounds
3029
# 'criterion': ['squared_error', 'friedman_mse', 'absolute_error', 'poisson'], # (regression)
31-
# 'splitter': ['best', 'random'], # Cách chọn cách chia tại mỗi node
32-
# 'max_depth': [None, 5, 10, 20, 30], # Độ sâu tối đa của cây
33-
# 'min_samples_split': [2, 5, 10], # Số lượng mẫu tối thiểu để một node được chia
34-
# 'min_samples_leaf': [1, 2, 4], # Số lượng mẫu tối thiểu tại một node lá
35-
# 'max_features': [None, 'sqrt', 'log2'], # Số đặc trưng tối đa khi tìm split tốt nhất
36-
# 'max_leaf_nodes': [None, 10, 20, 50], # Giới hạn số lượng node lá
37-
# 'ccp_alpha': [0.0, 0.01, 0.05, 0.1], # Complexity parameter để cắt tỉa cây (post-pruning)
30+
# 'splitter': ['best', 'random'],
31+
# 'max_depth': [None, 5, 10, 20, 30],
32+
# 'min_samples_split': [2, 5, 10],
33+
# 'min_samples_leaf': [1, 2, 4],
34+
# 'max_features': [None, 'sqrt', 'log2'],
35+
# 'max_leaf_nodes': [None, 10, 20, 50],
36+
# 'ccp_alpha': [0.0, 0.01, 0.05, 0.1],
3837
# }
3938

4039
param_bounds = [
41-
StringVar(valid_sets=("squared_error", "friedman_mse", "absolute_error", "poisson"), name="criterion"), # (regression)
42-
StringVar(valid_sets=("best", "random"), name="splitter"), # Cách chọn cách chia tại mỗi node
43-
IntegerVar(lb=2, ub=15, name="max_depth"), # Độ sâu tối đa của cây
44-
IntegerVar(lb=2, ub=10, name="min_samples_split"), # Số lượng mẫu tối thiểu để một node được chia
45-
IntegerVar(lb=1, ub=5, name="min_samples_leaf"), # Số lượng mẫu tối thiểu tại một node lá
46-
StringVar(valid_sets=("sqrt", "log2"), name="max_features"), # Số đặc trưng tối đa khi tìm split tốt nhất
47-
IntegerVar(lb=2, ub=30, name="max_leaf_nodes"), # Giới hạn số lượng node lá
48-
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"), # Complexity parameter để cắt tỉa cây (post-pruning)
40+
StringVar(valid_sets=("squared_error", "friedman_mse", "absolute_error", "poisson"), name="criterion"),
41+
StringVar(valid_sets=("best", "random"), name="splitter"),
42+
IntegerVar(lb=2, ub=15, name="max_depth"),
43+
IntegerVar(lb=2, ub=10, name="min_samples_split"),
44+
IntegerVar(lb=1, ub=5, name="min_samples_leaf"),
45+
StringVar(valid_sets=("sqrt", "log2"), name="max_features"),
46+
IntegerVar(lb=2, ub=30, name="max_leaf_nodes"),
47+
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"),
4948
]
5049

5150
# Initialize and fit MetaSearchCV
@@ -59,7 +58,8 @@
5958
scoring="MSE", # or any custom scoring like "F1_macro"
6059
seed=42,
6160
n_jobs=2,
62-
verbose=True
61+
verbose=True,
62+
mode='single', n_workers=None, termination=None
6363
)
6464

6565
searcher.fit(data.X_train, data.y_train)

examples/exam_gradient_boosting_classification.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
}
3030

3131
param_bounds = [
32-
IntegerVar(lb=50, ub=200, name="n_estimators"), # Số lượng cây trong mô hình
33-
FloatVar(lb=0.01, ub=0.2, name="learning_rate"), # Tốc độ học
34-
IntegerVar(lb=2, ub=5, name="max_depth"), # Độ sâu tối đa của cây
35-
IntegerVar(lb=2, ub=10, name="min_samples_split"), # Số lượng mẫu tối thiểu để một node được chia
36-
IntegerVar(lb=1, ub=5, name="min_samples_leaf"), # Số lượng mẫu tối thiểu tại một node lá
37-
StringVar(valid_sets=("sqrt", "log2"), name="max_features"), # Số đặc trưng tối đa khi tìm split tốt nhất
38-
FloatVar(lb=0.5, ub=1.0, name="subsample"), # Tỉ lệ mẫu được sử dụng để fit base learners
39-
StringVar(valid_sets=(("log_loss",)), name="loss"), # (classification)
40-
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"), # Tham số điều chỉnh cho pruning
32+
IntegerVar(lb=50, ub=200, name="n_estimators"),
33+
FloatVar(lb=0.01, ub=0.2, name="learning_rate"),
34+
IntegerVar(lb=2, ub=5, name="max_depth"),
35+
IntegerVar(lb=2, ub=10, name="min_samples_split"),
36+
IntegerVar(lb=1, ub=5, name="min_samples_leaf"),
37+
StringVar(valid_sets=("sqrt", "log2"), name="max_features"),
38+
FloatVar(lb=0.5, ub=1.0, name="subsample"),
39+
StringVar(valid_sets=(("log_loss",)), name="loss"),
40+
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"),
4141
]
4242

4343
# Initialize and fit MetaSearchCV
@@ -51,7 +51,8 @@
5151
scoring="AS", # or any custom scoring like "F1_macro"
5252
seed=42,
5353
n_jobs=2,
54-
verbose=True
54+
verbose=True,
55+
mode='single', n_workers=None, termination=None
5556
)
5657

5758
searcher.fit(X_train, y_train)

examples/exam_gradient_boosting_regression.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
data.X_test = scaler_X.transform(data.X_test)
2222

2323
data.y_train, scaler_y = data.scale(data.y_train, scaling_methods=("standard", "minmax"))
24-
data.y_train = data.y_train.ravel()
25-
data.y_test = scaler_y.transform(data.y_test.reshape(-1, 1)).ravel()
24+
data.y_test = scaler_y.transform(data.y_test)
2625

2726
# Define param bounds
2827

@@ -39,15 +38,15 @@
3938
# }
4039

4140
param_bounds = [
42-
IntegerVar(lb=50, ub=200, name="n_estimators"), # Số lượng cây trong mô hình
43-
FloatVar(lb=0.01, ub=0.2, name="learning_rate"), # Tốc độ học
44-
IntegerVar(lb=2, ub=5, name="max_depth"), # Độ sâu tối đa của cây
45-
IntegerVar(lb=2, ub=10, name="min_samples_split"), # Số lượng mẫu tối thiểu để một node được chia
46-
IntegerVar(lb=1, ub=5, name="min_samples_leaf"), # Số lượng mẫu tối thiểu tại một node lá
47-
StringVar(valid_sets=("sqrt", "log2"), name="max_features"), # Số đặc trưng tối đa khi tìm split tốt nhất
48-
FloatVar(lb=0.5, ub=1.0, name="subsample"), # Tỉ lệ mẫu được sử dụng để fit base learners
41+
IntegerVar(lb=50, ub=200, name="n_estimators"),
42+
FloatVar(lb=0.01, ub=0.2, name="learning_rate"),
43+
IntegerVar(lb=2, ub=5, name="max_depth"),
44+
IntegerVar(lb=2, ub=10, name="min_samples_split"),
45+
IntegerVar(lb=1, ub=5, name="min_samples_leaf"),
46+
StringVar(valid_sets=("sqrt", "log2"), name="max_features"),
47+
FloatVar(lb=0.5, ub=1.0, name="subsample"),
4948
StringVar(valid_sets=("squared_error", "absolute_error", 'huber'), name="loss"),
50-
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"), # Tham số điều chỉnh cho pruning
49+
FloatVar(lb=0.0, ub=0.1, name="ccp_alpha"),
5150
]
5251

5352
# Initialize and fit MetaSearchCV
@@ -61,7 +60,8 @@
6160
scoring="MSE", # or any custom scoring like "F1_macro"
6261
seed=42,
6362
n_jobs=2,
64-
verbose=True
63+
verbose=True,
64+
mode='single', n_workers=None, termination=None
6565
)
6666

6767
searcher.fit(data.X_train, data.y_train)

examples/exam_knn_classification.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
# Define param bounds
1717

1818
# param_grid = { ==> This is for GridSearchCV, show you how to convert to our MetaSearchCV
19-
# 'n_neighbors': [2, 3, 5, 7, 9, 11], # Số lượng hàng xóm gần nhất
20-
# 'weights': ['uniform', 'distance'], # Trọng số: đều nhau hoặc theo khoảng cách
21-
# 'algorithm': ['auto', 'ball_tree', 'kd_tree', 'brute'], # Thuật toán tìm kiếm
22-
# 'leaf_size': [10, 20, 30, 40, 50], # Kích thước node lá, ảnh hưởng đến performance
23-
# 'p': [1, 2], # Tham số cho khoảng cách Minkowski: 1 (Manhattan), 2 (Euclidean)
24-
# 'metric': ['minkowski'], # Khoảng cách sử dụng; thường dùng 'minkowski' kết hợp với p
25-
# # Có thể thêm các metric khác nếu cần như 'euclidean', 'manhattan', 'chebyshev', 'mahalanobis'
19+
# 'n_neighbors': [2, 3, 5, 7, 9, 11],
20+
# 'weights': ['uniform', 'distance'],
21+
# 'algorithm': ['auto', 'ball_tree', 'kd_tree', 'brute'],
22+
# 'leaf_size': [10, 20, 30, 40, 50],
23+
# 'p': [1, 2],
24+
# 'metric': ['minkowski'],
2625
# }
2726

2827
param_bounds = [
@@ -31,7 +30,7 @@
3130
StringVar(valid_sets=("auto", "ball_tree", "kd_tree", "brute"), name="algorithm"),
3231
IntegerVar(lb=10, ub=50, name="leaf_size"),
3332
IntegerVar(lb=1, ub=2, name="p"), # 1 (Manhattan), 2 (Euclidean)
34-
StringVar(valid_sets=("minkowski", "manhattan"), name="metric"), # Khoảng cách sử dụng; thường dùng 'minkowski' kết hợp với p
33+
StringVar(valid_sets=("minkowski", "manhattan"), name="metric"),
3534
]
3635

3736
# Initialize and fit MetaSearchCV
@@ -45,7 +44,8 @@
4544
scoring="AS", # or any custom scoring like "F1_macro"
4645
seed=42,
4746
n_jobs=2,
48-
verbose=True
47+
verbose=True,
48+
mode='single', n_workers=None, termination=None
4949
)
5050

5151
searcher.fit(X_train, y_train)

examples/exam_knn_regression.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@
2121
data.X_test = scaler_X.transform(data.X_test)
2222

2323
data.y_train, scaler_y = data.scale(data.y_train, scaling_methods=("standard", "minmax"))
24-
data.y_train = data.y_train.ravel()
25-
data.y_test = scaler_y.transform(data.y_test.reshape(-1, 1)).ravel()
24+
data.y_test = scaler_y.transform(data.y_test)
2625

2726
# Define param bounds
2827

2928
# param_grid = { ==> This is for GridSearchCV, show you how to convert to our MetaSearchCV
30-
# 'n_neighbors': [2, 3, 5, 7, 9, 11], # Số lượng hàng xóm gần nhất
31-
# 'weights': ['uniform', 'distance'], # Trọng số: đều nhau hoặc theo khoảng cách
32-
# 'algorithm': ['auto', 'ball_tree', 'kd_tree', 'brute'], # Thuật toán tìm kiếm
33-
# 'leaf_size': [10, 20, 30, 40, 50], # Kích thước node lá, ảnh hưởng đến performance
34-
# 'p': [1, 2], # Tham số cho khoảng cách Minkowski: 1 (Manhattan), 2 (Euclidean)
35-
# 'metric': ['minkowski'], # Khoảng cách sử dụng; thường dùng 'minkowski' kết hợp với p
36-
# # Có thể thêm các metric khác nếu cần như 'euclidean', 'manhattan', 'chebyshev', 'mahalanobis'
29+
# 'n_neighbors': [2, 3, 5, 7, 9, 11],
30+
# 'weights': ['uniform', 'distance'],
31+
# 'algorithm': ['auto', 'ball_tree', 'kd_tree', 'brute'],
32+
# 'leaf_size': [10, 20, 30, 40, 50],
33+
# 'p': [1, 2],
34+
# 'metric': ['minkowski'],
3735
# }
3836

3937
param_bounds = [
@@ -42,7 +40,7 @@
4240
StringVar(valid_sets=("auto", "ball_tree", "kd_tree", "brute"), name="algorithm"),
4341
IntegerVar(lb=10, ub=50, name="leaf_size"),
4442
IntegerVar(lb=1, ub=2, name="p"), # 1 (Manhattan), 2 (Euclidean)
45-
StringVar(valid_sets=("minkowski", "manhattan"), name="metric"), # Khoảng cách sử dụng; thường dùng 'minkowski' kết hợp với p
43+
StringVar(valid_sets=("minkowski", "manhattan"), name="metric"),
4644
]
4745

4846
# Initialize and fit MetaSearchCV
@@ -56,7 +54,8 @@
5654
scoring="MSE", # or any custom scoring like "F1_macro"
5755
seed=42,
5856
n_jobs=2,
59-
verbose=True
57+
verbose=True,
58+
mode='single', n_workers=None, termination=None
6059
)
6160

6261
searcher.fit(data.X_train, data.y_train)

examples/exam_mlp_classification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
scoring="AS", # or any custom scoring like "F1_macro"
5050
seed=42,
5151
n_jobs=2,
52-
verbose=True
52+
verbose=True,
53+
mode='single', n_workers=None, termination=None
5354
)
5455

5556
searcher.fit(X_train, y_train)

examples/exam_mlp_regression.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
scoring="MSE", # or any custom scoring like "F1_macro"
6060
seed=42,
6161
n_jobs=2,
62-
verbose=True
62+
verbose=True,
63+
mode='single', n_workers=None, termination=None
6364
)
6465

6566
searcher.fit(data.X_train, data.y_train)

0 commit comments

Comments
 (0)