0
# Default Estimators and Hyperparameter Suggestions
1
2
Enhanced versions of popular machine learning estimators with optimized hyperparameters and intelligent hyperparameter suggestion functions. The default module provides pre-tuned estimators and utilities for automatic hyperparameter configuration.
3
4
## Capabilities
5
6
### Enhanced Estimators
7
8
Pre-configured versions of popular scikit-learn estimators with optimized hyperparameters based on FLAML's research and extensive testing.
9
10
```python { .api }
11
class ExtraTreesClassifier:
12
"""Enhanced ExtraTreesClassifier with optimized hyperparameters."""
13
def __init__(self, n_estimators=100, **kwargs): ...
14
def fit(self, X, y, **kwargs): ...
15
def predict(self, X): ...
16
def predict_proba(self, X): ...
17
18
class ExtraTreesRegressor:
19
"""Enhanced ExtraTreesRegressor with optimized hyperparameters."""
20
def __init__(self, n_estimators=100, **kwargs): ...
21
def fit(self, X, y, **kwargs): ...
22
def predict(self, X): ...
23
24
class LGBMClassifier:
25
"""Enhanced LightGBM classifier with optimized hyperparameters."""
26
def __init__(self, n_estimators=100, **kwargs): ...
27
def fit(self, X, y, **kwargs): ...
28
def predict(self, X): ...
29
def predict_proba(self, X): ...
30
31
class LGBMRegressor:
32
"""Enhanced LightGBM regressor with optimized hyperparameters."""
33
def __init__(self, n_estimators=100, **kwargs): ...
34
def fit(self, X, y, **kwargs): ...
35
def predict(self, X): ...
36
37
class RandomForestClassifier:
38
"""Enhanced RandomForest classifier with optimized hyperparameters."""
39
def __init__(self, n_estimators=100, **kwargs): ...
40
def fit(self, X, y, **kwargs): ...
41
def predict(self, X): ...
42
def predict_proba(self, X): ...
43
44
class RandomForestRegressor:
45
"""Enhanced RandomForest regressor with optimized hyperparameters."""
46
def __init__(self, n_estimators=100, **kwargs): ...
47
def fit(self, X, y, **kwargs): ...
48
def predict(self, X): ...
49
50
class XGBClassifier:
51
"""Enhanced XGBoost classifier with optimized hyperparameters."""
52
def __init__(self, n_estimators=100, **kwargs): ...
53
def fit(self, X, y, **kwargs): ...
54
def predict(self, X): ...
55
def predict_proba(self, X): ...
56
57
class XGBRegressor:
58
"""Enhanced XGBoost regressor with optimized hyperparameters."""
59
def __init__(self, n_estimators=100, **kwargs): ...
60
def fit(self, X, y, **kwargs): ...
61
def predict(self, X): ...
62
```
63
64
### Estimator Enhancement
65
66
Function for enhancing existing estimators with FLAML's optimized hyperparameters.
67
68
```python { .api }
69
def flamlize_estimator(estimator_class, task="classification", **kwargs):
70
"""
71
Enhance an estimator class with FLAML's optimized hyperparameters.
72
73
Args:
74
estimator_class: Scikit-learn compatible estimator class
75
task (str): Task type - 'classification' or 'regression'
76
**kwargs: Additional parameters
77
78
Returns:
79
Enhanced estimator class with optimized hyperparameters
80
"""
81
```
82
83
### Hyperparameter Suggestion Functions
84
85
Intelligent hyperparameter suggestion based on dataset characteristics and meta-learning.
86
87
```python { .api }
88
def suggest_hyperparams(estimator_name, X, y, task="classification"):
89
"""
90
Suggest hyperparameters for an estimator based on dataset characteristics.
91
92
Args:
93
estimator_name (str): Name of the estimator
94
X: Training features
95
y: Training target
96
task (str): Task type - 'classification' or 'regression'
97
98
Returns:
99
dict: Suggested hyperparameters
100
"""
101
102
def suggest_config(estimator_name, X, y, task="classification", time_budget=60):
103
"""
104
Suggest configuration including hyperparameters and training settings.
105
106
Args:
107
estimator_name (str): Name of the estimator
108
X: Training features
109
y: Training target
110
task (str): Task type
111
time_budget (float): Available time budget in seconds
112
113
Returns:
114
dict: Suggested configuration
115
"""
116
117
def suggest_learner(X, y, task="classification"):
118
"""
119
Suggest the best learner for given dataset characteristics.
120
121
Args:
122
X: Training features
123
y: Training target
124
task (str): Task type - 'classification' or 'regression'
125
126
Returns:
127
str: Recommended learner name
128
"""
129
130
def preprocess_and_suggest_hyperparams(X, y, task, estimator_name, time_budget=60):
131
"""
132
Preprocess data and suggest hyperparameters.
133
134
Args:
135
X: Training features
136
y: Training target
137
task (str): Task type
138
estimator_name (str): Name of the estimator
139
time_budget (float): Available time budget
140
141
Returns:
142
tuple: (preprocessed_X, preprocessed_y, suggested_hyperparams)
143
"""
144
145
def meta_feature(X, y, task="classification"):
146
"""
147
Extract meta-features from dataset for hyperparameter suggestion.
148
149
Args:
150
X: Training features
151
y: Training target
152
task (str): Task type
153
154
Returns:
155
dict: Meta-features of the dataset
156
"""
157
```
158
159
## Usage Examples
160
161
### Using Enhanced Estimators
162
163
```python
164
from flaml.default import LGBMRegressor, XGBClassifier
165
import pandas as pd
166
from sklearn.model_selection import train_test_split
167
168
# Load your data
169
X, y = load_data() # your dataset
170
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
171
172
# Use enhanced LightGBM regressor with optimized hyperparameters
173
regressor = LGBMRegressor()
174
regressor.fit(X_train, y_train)
175
predictions = regressor.predict(X_test)
176
177
# Use enhanced XGBoost classifier
178
classifier = XGBClassifier()
179
classifier.fit(X_train, y_train)
180
probabilities = classifier.predict_proba(X_test)
181
```
182
183
### Hyperparameter Suggestions
184
185
```python
186
from flaml.default import suggest_hyperparams, suggest_learner
187
188
# Get hyperparameter suggestions
189
suggested_params = suggest_hyperparams("lgbm", X_train, y_train, task="regression")
190
print(f"Suggested hyperparameters: {suggested_params}")
191
192
# Get learner recommendation
193
best_learner = suggest_learner(X_train, y_train, task="classification")
194
print(f"Recommended learner: {best_learner}")
195
```