How to use the susi.SOMClassifier function in susi

To help you get started, we’ve selected a few susi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_fit(train_mode_unsupervised, train_mode_supervised):
    som = susi.SOMClassifier(
        n_rows=8,
        n_columns=8,
        train_mode_unsupervised=train_mode_unsupervised,
        train_mode_supervised=train_mode_supervised,
        random_state=3)
    som.fit(X_train, y_train)
    assert(som.score(X_test, y_test) >= 0.8)
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_fit_semi(train_mode_unsupervised, train_mode_supervised):
    som = susi.SOMClassifier(
        n_rows=5,
        n_columns=5,
        train_mode_unsupervised=train_mode_unsupervised,
        train_mode_supervised=train_mode_supervised,
        missing_label_placeholder=-1,
        random_state=3)
    som.fit(X_train, y_train_semi)
    assert(som.score(X_test, y_test) > 0.5)
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_change_class_proba(n_rows, n_columns, learningrate,
                            dist_weight_matrix, random_state, class_weight,
                            expected):
    som = susi.SOMClassifier(n_rows=n_rows, n_columns=n_columns,
                             random_state=random_state)
    new_som_array = som.change_class_proba(learningrate, dist_weight_matrix,
                                           class_weight)
    assert(new_som_array.shape == (n_rows, n_columns, 1))
    assert(new_som_array.dtype == bool)
    if expected is not None:
        assert np.array_equal(new_som_array, expected.reshape((2, 2, 1)))
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
# initialize with placeholder in class list
    with pytest.raises(ValueError):
        som = susi.SOMClassifier()
        som.X_ = X_train
        som.placeholder_ = -1
        som.y_ = np.full(shape=y_train.shape, fill_value="PLACEHOLDER")
        som.sample_weights_ = np.full(fill_value=1., shape=(len(som.X_), 1))
        som.labeled_indices_ = list(range(len(som.y_)))
        som.train_unsupervised_som()
        som.set_bmus(som.X_)
        som.init_super_som()

    # initialize with placeholder = missing_label_placeholder
    with pytest.raises(ValueError):
        som = susi.SOMClassifier(missing_label_placeholder=-999999)
        som.X_ = X_train
        som.y_ = y_train
        som.sample_weights_ = np.full(fill_value=1., shape=(len(som.X_), 1))
        som.labeled_indices_ = list(range(len(som.y_)))
        som.train_unsupervised_som()
        som.set_bmus(som.X_)
        som.init_super_som()
        print(y_train)
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_set_placeholder(class_dtype):
    som = susi.SOMClassifier()
    som.placeholder_dict_ = {
            "str": "PLACEHOLDER",
            "int": -999999,
            "float": -99.999,
        }
    som.class_dtype_ = class_dtype
    if class_dtype != dict:
        som.set_placeholder()
        assert(type(som.placeholder_) == class_dtype)
    else:
        with pytest.raises(ValueError):
            som.set_placeholder()
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_modify_weight_matrix_supervised(
        n_rows, n_columns, learningrate, dist_weight_matrix, som_array,
        random_state, true_vector):
    som = susi.SOMClassifier(
        n_rows=n_rows,
        n_columns=n_columns,
        random_state=random_state)
    som.classes_ = [0, 1, 2]
    som.class_weights_ = [1., 1., 1.]
    som.super_som_ = som_array
    new_som = som.modify_weight_matrix_supervised(
        dist_weight_matrix=dist_weight_matrix,
        true_vector=true_vector,
        learningrate=learningrate)
    assert(new_som.shape == (n_rows, n_columns, 1))
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_init_super_som_raises():
    # initialize without sample_weights:
    with pytest.raises(AttributeError):
        som = susi.SOMClassifier()
        som.X_ = X_train
        som.y_ = y_train
        som.train_unsupervised_som()
        som.set_bmus(som.X_)
        som.init_super_som()

    # initialize with placeholder in class list
    with pytest.raises(ValueError):
        som = susi.SOMClassifier()
        som.X_ = X_train
        som.placeholder_ = -1
        som.y_ = np.full(shape=y_train.shape, fill_value="PLACEHOLDER")
        som.sample_weights_ = np.full(fill_value=1., shape=(len(som.X_), 1))
        som.labeled_indices_ = list(range(len(som.y_)))
        som.train_unsupervised_som()
        som.set_bmus(som.X_)
        som.init_super_som()

    # initialize with placeholder = missing_label_placeholder
    with pytest.raises(ValueError):
        som = susi.SOMClassifier(missing_label_placeholder=-999999)
        som.X_ = X_train
        som.y_ = y_train
        som.sample_weights_ = np.full(fill_value=1., shape=(len(som.X_), 1))
        som.labeled_indices_ = list(range(len(som.y_)))
github felixriese / susi / tests / test_SOMClassifier.py View on Github external
def test_init_super_som(n_rows, n_columns, do_class_weighting):
    random_state = 3
    som = susi.SOMClassifier(
        n_rows=n_rows,
        n_columns=n_columns,
        do_class_weighting=do_class_weighting,
        random_state=random_state)

    som.X_ = X_train
    som.y_ = y_train
    som.sample_weights_ = np.full(fill_value=1., shape=(len(som.X_), 1))
    som.train_unsupervised_som()
    som.labeled_indices_ = list(range(len(som.y_)))
    som.set_bmus(som.X_)
    som.init_super_som()