9951 explained code solutions for 126 technologies


python-scikit-learnAdaboost classifier model learning rate


A higher learning rate increases the contribution of each classifier:

from sklearn import datasets, ensemble, model_selection

X, y = datasets.load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y)

model = ensemble.AdaBoostClassifier(learning_rate=10)
model.fit(X_train, y_train)

score = model.score(X_test, y_test)ctrl + c
from sklearn import

import module from scikit-learn

load_iris

loads Iris dataset

model_selection.train_test_split

splits given X and y datasets to test (25% of values by default) and train (75% of values by default) subsets

.AdaBoostClassifier(

create AdaBoost model

.fit(

train model with a given features and target variable dataset

learning_rate

set learning rate (to 10 in our case)

.score(

returns model accuracy score


Usage example

from sklearn import datasets, ensemble, model_selection

X, y = datasets.load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y)

model = ensemble.AdaBoostClassifier(learning_rate=10)
model.fit(X_train, y_train)

print(model.score(X_test, y_test))
output
0.631578947368421