def test_feature_importances_regressor(): """Test feature_importances of Regressor class.""" regressor = Regressor() with pytest.raises(ValueError): regressor.feature_importances() df_train = pd.read_csv("data_for_tests/clean_train.csv") y_train = pd.read_csv("data_for_tests/clean_target.csv", squeeze=True) regressor.set_params(strategy="LightGBM") regressor.fit(df_train, y_train) importance = regressor.feature_importances() assert importance != {} regressor.set_params(strategy="Linear") regressor.fit(df_train, y_train) importance = regressor.feature_importances() assert importance != {} regressor.set_params(strategy="RandomForest") regressor.fit(df_train, y_train) importance = regressor.feature_importances() assert importance != {} regressor.set_params(strategy="AdaBoost") regressor.fit(df_train, y_train) importance = regressor.feature_importances() assert importance != {} regressor.set_params(strategy="Bagging") regressor.fit(df_train, y_train) importance = regressor.feature_importances() assert importance != {}
def test_fit_regressor(): """Test fit method of Regressor class.""" df_train = pd.read_csv("data_for_tests/clean_train.csv") y_train = pd.read_csv("data_for_tests/clean_target.csv", squeeze=True) regressor = Regressor() regressor.fit(df_train, y_train) assert np.all(regressor._Regressor__col == df_train.columns) assert regressor._Regressor__fitOK
def test_predict_regressor(): """Test predict method of Regressor class.""" df_train = pd.read_csv("data_for_tests/clean_train.csv") y_train = pd.read_csv("data_for_tests/clean_target.csv", squeeze=True) regressor = Regressor() with pytest.raises(ValueError): regressor.predict(df_train) regressor.fit(df_train, y_train) with pytest.raises(ValueError): regressor.predict(None) assert len(regressor.predict(df_train)) > 0
def test_score_regressor(): """Test_score method of Regressor class.""" df_train = pd.read_csv("data_for_tests/clean_train.csv") y_train = pd.read_csv("data_for_tests/clean_target.csv", squeeze=True) regressor = Regressor(strategy="Linear") with pytest.raises(ValueError): regressor.score(df_train, y_train) regressor.fit(df_train, y_train) with pytest.raises(ValueError): regressor.score(None, y_train) with pytest.raises(ValueError): regressor.score(df_train, None) assert regressor.score(df_train, y_train) > 0