예제 #1
0
def test_iris_ensemble_iterative_regression():
    print('\ntest_iris_ensemble_iterative_regression():')
    X_train, X_test, y_train, y_test = train_test_split(X_iris,
                                                        y_iris,
                                                        test_size=5,
                                                        random_state=42)
    cls = ESNClassifier(input_to_node=[('tanh',
                                        InputToNode(hidden_layer_size=10,
                                                    random_state=42,
                                                    activation='identity')),
                                       ('bounded_relu',
                                        InputToNode(hidden_layer_size=10,
                                                    random_state=42,
                                                    activation='bounded_relu'))
                                       ],
                        node_to_node=[('default',
                                       NodeToNode(hidden_layer_size=20,
                                                  spectral_radius=0.0))],
                        regressor=IncrementalRegression(alpha=.01),
                        random_state=42)

    for samples in np.split(np.arange(0, X_train.shape[0]), 5):
        cls.partial_fit(X_train[samples, :],
                        y_train[samples],
                        classes=np.arange(3, dtype=int))
    y_predicted = cls.predict(X_test)

    for record in range(len(y_test)):
        print('predicted: {0} \ttrue: {1}'.format(y_predicted[record],
                                                  y_test[record]))

    print('score: {0}'.format(cls.score(X_test, y_test)))
    print('proba: {0}'.format(cls.predict_proba(X_test)))
    print('log_proba: {0}'.format(cls.predict_log_proba(X_test)))
    assert cls.score(X_test, y_test) >= 4. / 5.
예제 #2
0
파일: test_esn.py 프로젝트: TUD-STKS/PyRCN
def test_esn_classifier_instance_fit() -> None:
    X, y = load_digits(return_X_y=True, as_sequence=True)
    esn = ESNClassifier(hidden_layer_size=50).fit(X[0], np.repeat(y[0], 8))
    assert (esn.sequence_to_value is False)
    y_pred = esn.predict_proba(X[0])
    assert (y_pred.ndim == 2)
    y_pred = esn.predict_log_proba(X[0])
    assert (y_pred.ndim == 2)
예제 #3
0
파일: test_esn.py 프로젝트: TUD-STKS/PyRCN
def test_esn_classifier_sequence_to_value() -> None:
    X, y = load_digits(return_X_y=True, as_sequence=True)
    esn = ESNClassifier(hidden_layer_size=50).fit(X, y)
    y_pred = esn.predict(X)
    assert (len(y) == len(y_pred))
    assert (len(y_pred[0]) == 1)
    assert (esn.sequence_to_value is True)
    assert (esn.decision_strategy == "winner_takes_all")
    y_pred = esn.predict_proba(X)
    assert (y_pred[0].ndim == 1)
    y_pred = esn.predict_log_proba(X)
    assert (y_pred[0].ndim == 1)
    esn.sequence_to_value = False
    y_pred = esn.predict(X)
    assert (len(y_pred[0]) == 8)
    y_pred = esn.predict_proba(X)
    assert (y_pred[0].ndim == 2)
    y_pred = esn.predict_log_proba(X)
    assert (y_pred[0].ndim == 2)