Machine Learning
uv add scikit-learnpip install scikit-learnConfigurable Machine Learning Classifier
from hypster import HP, instantiate
def classifier_config(hp: HP):
from sklearn.ensemble import HistGradientBoostingClassifier, RandomForestClassifier
# Define the model type choice
model_type = hp.select(["random_forest", "hist_boost"],
name="model_type", default="hist_boost")
# Create the classifier based on selection
if model_type == "hist_boost":
learning_rate = hp.float(0.01, name="learning_rate", min=0.001, max=0.1)
max_depth = hp.int(10, name="max_depth", min=3)
classifier = HistGradientBoostingClassifier(
learning_rate=learning_rate,
max_depth=max_depth,
)
else: # model_type == "random_forest"
n_estimators = hp.int(100, name="n_estimators", max=500)
max_depth = hp.int(5, name="max_depth")
bootstrap = hp.bool(True, name="bootstrap")
classifier = RandomForestClassifier(
n_estimators=n_estimators,
max_depth=max_depth,
bootstrap=bootstrap
)
return {"classifier": classifier}Understanding the Code
Training and Evaluating
Last updated
Was this helpful?