def test_return_incumbent(self): X_train, X_test, y_train, y_test = load_benchmark(return_split=True) linear_basis_fn = 'ridge' n_regressors = 1 boosting_loss = 'ls' line_search_options = dict(init_guess=1, opt_method='minimize', method='Nelder-Mead', tol=1e-7, options={"maxiter": 10000}, niter=None, T=None, loss='lad', regularization=0.1) base_boosting_options = dict(n_regressors=n_regressors, boosting_loss=boosting_loss, line_search_options=line_search_options) index = 3 reg = Regressor(regressor_choice=linear_basis_fn, params=dict(alpha=0.1), target_index=index, base_boosting_options=base_boosting_options) reg.baseboostcv(X_train.iloc[:10, :], y_train.iloc[:10, :]) self.assertHasAttr(reg, 'return_incumbent_')
def test_baseboostcv_score(self): X_train, X_test, y_train, y_test = load_benchmark(return_split=True) stack = dict(regressors=['ridge', 'lgbmregressor'], final_regressor='ridge') line_search_options = dict(init_guess=1, opt_method='minimize', method='Nelder-Mead', tol=1e-7, options={"maxiter": 10000}, niter=None, T=None, loss='lad', regularization=0.1) base_boosting_options = dict(n_regressors=3, boosting_loss='ls', line_search_options=line_search_options) reg = Regressor(regressor_choice='stackingregressor', target_index=0, stacking_options=dict(layers=stack), base_boosting_options=base_boosting_options) y_pred = reg.baseboostcv(X_train, y_train).predict(X_test) score = reg.score(y_test, y_pred) self.assertNotHasAttr(reg, 'return_incumbent_') self.assertGreaterEqual(score['mae'].values, 0.0) self.assertGreaterEqual(score['mse'].values, 0.0) self.assertLess(score['mae'].values, 2.0) self.assertLess(score['mse'].values, 6.2)
base_boosting_options=options_with_lad) else: # We make an instance of Regressor with our choice of ridge # regression for the single-target regression subtask: 3. # The parameter alpha denotes the regularization strength # in ridge regression, where the Tikhonov matrix is the # scalar alpha times the identity matrix. reg = Regressor(regressor_choice=linear_basis_fn, params=dict(alpha=0.1), target_index=index, base_boosting_options=options_with_huber) # We use the baseboostcv method, which utilizes a private # inbuilt model selection method to choose either the # incumbent or the candidate. y_pred = reg.baseboostcv(X_train, y_train).predict(X_test) # We can check if the incumbent won model selection with # the return_incumbent_ attribute. if hasattr(reg, 'return_incumbent_'): print(f'Incumbent was chosen in subtask {index + 1}') # We compute the single-target test error. score = reg.score(y_test, y_pred) test_error.append(score) test_error = pd.concat(test_error) print('Finished building the scoring DataFrame.') print(test_error.round(decimals=2)) print('Finished computing the multi-target scores.') print(test_error.mean().round(decimals=2))