class AdaBoostRegressorImpl(): def __init__(self, base_estimator=None, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None): self._hyperparams = { 'base_estimator': base_estimator, 'n_estimators': n_estimators, 'learning_rate': learning_rate, 'loss': loss, 'random_state': random_state } self._wrapped_model = Op(**self._hyperparams) def fit(self, X, y=None): if (y is not None): self._wrapped_model.fit(X, y) else: self._wrapped_model.fit(X) return self def predict(self, X): return self._wrapped_model.predict(X)
class AdaBoostRegressorImpl(): def __init__(self, base_estimator=None, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None): if isinstance(base_estimator, lale.operators.Operator): if isinstance(base_estimator, lale.operators.IndividualOp): base_estimator = base_estimator._impl_instance()._wrapped_model else: raise ValueError( "If base_estimator is a Lale operator, it needs to be an individual operator. " ) self._hyperparams = { 'base_estimator': base_estimator, 'n_estimators': n_estimators, 'learning_rate': learning_rate, 'loss': loss, 'random_state': random_state } self._wrapped_model = SKLModel(**self._hyperparams) def fit(self, X, y=None): if (y is not None): self._wrapped_model.fit(X, y) else: self._wrapped_model.fit(X) return self def predict(self, X): return self._wrapped_model.predict(X)
from sklearn.ensemble.weight_boosting import AdaBoostRegressor from sklearn.model_selection._split import train_test_split tl = TrendLine(data_type='train') data_df = tl.get() train_set, test_set = train_test_split(data_df, test_size=0.2, random_state=np.random.randint(1, 1000)) y_train = train_set['time_to_failure'] x_train_seg = train_set['segment_id'] x_train = train_set.drop(['time_to_failure', 'segment_id'], axis=1) y_test = test_set['time_to_failure'] x_test_seg = test_set['segment_id'] x_test = test_set.drop(['time_to_failure', 'segment_id'], axis=1) adbReg = AdaBoostRegressor(n_estimators=50, learning_rate=1.0, loss='linear', random_state=42) adbReg.fit(x_train, y_train) y_pred = adbReg.predict(x_test) # y_pred = x_train.mean(axis=1) print('MAE Score for acerage ', mean_absolute_error(y_test, y_pred))