Example #1
0
def test_mexicanhat_nbh_dist_weight_mode():
    som = susi.SOMRegressor(nbh_dist_weight_mode="mexican-hat")
    som.fit(X_train, y_train)
    som.predict(X_test)
    with pytest.raises(Exception):
        som = susi.SOMRegressor(nbh_dist_weight_mode="pseudogaussian")
        som.fit(X_train, y_train)
Example #2
0
def test_mexicanhat_nbh_dist_weight_mode(training_data):
    X_train, X_test, y_train, _ = training_data
    som = susi.SOMRegressor(nbh_dist_weight_mode="mexican-hat")
    som.fit(X_train, y_train)
    som.predict(X_test)
    with pytest.raises(ValueError):
        som = susi.SOMRegressor(nbh_dist_weight_mode="pseudogaussian")
        som.fit(X_train, y_train)
Example #3
0
def test_calc_estimation_output(n_rows, n_columns, unsuper_som, super_som,
                                datapoint, expected):
    som = susi.SOMRegressor(n_rows=n_rows, n_columns=n_columns)
    som.unsuper_som_ = unsuper_som
    som.super_som_ = super_som
    output = som.calc_estimation_output(datapoint)
    print(output)
    assert np.array_equal(output, expected)
Example #4
0
def test_estimator_status():
    check_estimator(
        susi.SOMRegressor(
            n_iter_unsupervised=10000,
            n_iter_supervised=10000,
            n_rows=30,
            n_columns=30,
        ))
Example #5
0
def test_init_super_som_regressor(X, y, init_mode):
    som = susi.SOMRegressor(init_mode_supervised=init_mode)
    som.X_ = X
    som.y_ = y
    som.init_super_som()

    # test type
    assert isinstance(som.super_som_, np.ndarray)

    # test shape
    n_rows = som.n_rows
    n_columns = som.n_columns
    assert som.super_som_.shape == (n_rows, n_columns, y.shape[1])

    with pytest.raises(Exception):
        som = susi.SOMRegressor(init_mode_supervised="pca")
        som.X_ = X
        som.y_ = y
        som.init_super_som()
Example #6
0
def test_init_super_som_regressor(X, y, init_mode):
    som = susi.SOMRegressor(init_mode_supervised=init_mode)
    som.X_ = X
    som.y_ = y
    som.labeled_indices_ = np.where(som.y_ != -1)[0]
    som._init_super_som()

    # test type
    assert isinstance(som.super_som_, np.ndarray)

    # test shape
    n_rows = som.n_rows
    n_columns = som.n_columns
    assert som.super_som_.shape == (n_rows, n_columns, som.n_regression_vars_)

    with pytest.raises(Exception):
        som = susi.SOMRegressor(init_mode_supervised="pca")
        som.X_ = X
        som.y_ = y
        som._init_super_som()
Example #7
0
def test_calc_estimation_output(n_rows, n_columns, unsuper_som, super_som,
                                datapoint, expected):
    som = susi.SOMRegressor(n_rows=n_rows, n_columns=n_columns)
    som.unsuper_som_ = unsuper_som
    som.super_som_ = super_som
    output = som._calc_estimation_output(datapoint)
    print(output)
    assert np.array_equal(output, expected)

    with pytest.raises(ValueError):
        som._calc_estimation_output(datapoint, mode="wrong")
Example #8
0
def test_predict(train_mode_unsupervised, train_mode_supervised):
    som_reg = susi.SOMRegressor(
        n_rows=3,
        n_columns=3,
        train_mode_unsupervised=train_mode_unsupervised,
        train_mode_supervised=train_mode_supervised,
        n_iter_unsupervised=100,
        n_iter_supervised=100,
        random_state=42)

    som_reg.fit(X_train, y_train)
    y_pred = som_reg.predict(X_test)
    assert(y_pred.shape == y_test.shape)
Example #9
0
def test_modify_weight_matrix_supervised():
    som = susi.SOMRegressor(train_mode_supervised="online")

    with pytest.raises(ValueError):
        som._modify_weight_matrix_supervised(
            dist_weight_matrix=np.array([1.0, 2.0]),
            true_vector=None,
            learning_rate=1.0,
        )
    with pytest.raises(ValueError):
        som._modify_weight_matrix_supervised(
            dist_weight_matrix=np.array([1.0, 2.0]),
            true_vector=np.array([1.0, 2.0]),
            learning_rate=None,
        )

    som = susi.SOMRegressor(train_mode_supervised="wrong")
    with pytest.raises(ValueError):
        som._modify_weight_matrix_supervised(
            dist_weight_matrix=np.array([1.0, 2.0]),
            true_vector=np.array([1.0, 2.0]),
            learning_rate=None,
        )
Example #10
0
def test_semisupervised_regressor(train_mode_unsupervised,
                                  train_mode_supervised):
    som_reg = susi.SOMRegressor(
        n_rows=3,
        n_columns=3,
        train_mode_unsupervised=train_mode_unsupervised,
        train_mode_supervised=train_mode_supervised,
        n_iter_unsupervised=100,
        n_iter_supervised=100,
        missing_label_placeholder=-1,
        random_state=42)

    som_reg.fit(X_train, y_train_semi)
    y_pred = som_reg.predict(X_test)
    assert (y_pred.shape == y_test.shape)
Example #11
0
def test_get_estimation_map(super_som):
    som = susi.SOMRegressor()  # works the same with SOMClassifier
    som.super_som_ = super_som
    assert np.array_equal(som.get_estimation_map(), super_som)
Example #12
0
def test_som_regressor_init(n_rows, n_columns):
    som_reg = susi.SOMRegressor(
        n_rows=n_rows, n_columns=n_columns)
    assert som_reg.n_rows == n_rows
    assert som_reg.n_columns == n_columns
Example #13
0
def test_MultiOutputRegressor():
    mor = MultiOutputRegressor(estimator=susi.SOMRegressor(n_jobs=2), n_jobs=2)
    mor.fit(X, y)
Example #14
0
def test_estimator_status():
    check_estimator(susi.SOMRegressor())
Example #15
0
def test_calc_proba():
    som = susi.SOMRegressor()
    assert som._calc_proba(bmu_pos=(1, 1)) == np.array([1.0])