def test_setup(params): """Tests __init__ and attributes set during fit""" coverage = 0.90 silverkite = SimpleSilverkiteForecast() model = SimpleSilverkiteEstimator(silverkite=silverkite, score_func=mean_squared_error, coverage=coverage, null_model_params=None, **params) assert model.silverkite == silverkite assert model.score_func == mean_squared_error assert model.coverage == coverage assert model.null_model_params is None # set_params must be able to replicate the init model2 = SimpleSilverkiteEstimator() model2.set_params(**dict(silverkite=silverkite, score_func=mean_squared_error, coverage=coverage, null_model_params=None, **params)) assert model2.__dict__ == model.__dict__ initialized_params = model.__dict__ initialized_params_subset = { k: v for k, v in initialized_params.items() if k in params.keys() } assert_equal(initialized_params_subset, params) assert model.model_dict is None assert model.pred_cols is None assert model.feature_cols is None assert model.coef_ is None train_df = daily_data_reg().get("train_df").copy() model.fit(train_df) assert model.fit_algorithm_dict == { "fit_algorithm": "sgd", "fit_algorithm_params": { "alpha": 0.1 } } assert model.model_dict is not None assert type(model.model_dict["ml_model"]) == SGDRegressor assert model.model_dict["ml_model"].alpha == ( params["fit_algorithm_dict"]["fit_algorithm_params"]["alpha"]) assert model.model_dict["training_evaluation"] is not None assert model.model_dict["test_evaluation"] is None assert model.pred_cols is not None assert model.feature_cols is not None assert_frame_equal(model.df, train_df) assert model.coef_ is not None
def test_setup2(params2): """Tests __init__ and attributes set during fit""" coverage = 0.95 silverkite = SilverkiteForecast() model = SilverkiteEstimator( silverkite=silverkite, score_func=mean_squared_error, coverage=coverage, null_model_params=None, **params2) assert model.silverkite == silverkite assert model.score_func == mean_squared_error assert model.coverage == coverage assert model.null_model_params is None # set_params must be able to replicate the init model2 = SilverkiteEstimator() model2.set_params(**dict( silverkite=silverkite, score_func=mean_squared_error, coverage=coverage, null_model_params=None, **params2)) assert model2.__dict__ == model.__dict__ initalized_params = model.__dict__ initalized_params_subset = { k: v for k, v in initalized_params.items() if k in params2.keys()} assert_equal(initalized_params_subset, params2) assert model.model_dict is None assert model.pred_cols is None assert model.feature_cols is None assert model.coef_ is None train_df = daily_data_reg().get("train_df").copy() model.fit(train_df) assert model.model_dict is not None assert model.model_dict["training_evaluation"] is not None assert model.model_dict["test_evaluation"] is None assert model.pred_cols is not None assert model.feature_cols is not None assert_frame_equal(model.df, train_df) assert model.coef_ is not None
def daily_data_with_reg(): return daily_data_reg()