コード例 #1
0
ファイル: test_regressor.py プロジェクト: zhuohuwu0603/MLBox
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 != {}
コード例 #2
0
ファイル: test_regressor.py プロジェクト: zhuohuwu0603/MLBox
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
コード例 #3
0
ファイル: test_regressor.py プロジェクト: zhuohuwu0603/MLBox
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
コード例 #4
0
ファイル: test_regressor.py プロジェクト: zhuohuwu0603/MLBox
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