Example #1
0
def test_embedding_no_layers():
    # Make sure the embedding works with no layers.
    data = load_diabetes()
    X, y = data['data'], data['target']

    clf = MLPRegressor(n_epochs=1, hidden_units=[])
    clf.fit(X, y)

    assert clf.transform(X).shape[1] == 1
Example #2
0
def test_embedding_default():
    # Make sure the embedding works by default.
    data = load_diabetes()
    X, y = data['data'], data['target']

    clf = MLPRegressor(n_epochs=1)
    clf.fit(X, y)

    assert clf.transform(X).shape[1] == 256
Example #3
0
def test_partial_fit():
    data = load_diabetes()
    clf = MLPRegressor(n_epochs=1)

    X, y = data['data'], data['target']

    for _ in range(30):
        clf.partial_fit(X, y)

    y_pred = clf.predict(X)
    assert pearsonr(y_pred, y)[0] > 0.5
Example #4
0
def test_partial_fit():
    data = load_diabetes()
    clf = MLPRegressor(n_epochs=1)

    X, y = data['data'], data['target']

    for _ in range(30):
        clf.partial_fit(X, y)

    y_pred = clf.predict(X)
    assert pearsonr(y_pred, y)[0] > 0.5
Example #5
0
def test_embedding_specific_layer():
    # Make sure the embedding works with no layers.
    data = load_diabetes()
    X, y = data['data'], data['target']

    clf = MLPRegressor(n_epochs=1,
                       hidden_units=(256, 8, 256),
                       transform_layer_index=1)
    clf.fit(X, y)

    assert clf.transform(X).shape[1] == 8
Example #6
0
def test_replicability():
    """Make sure running fit twice in a row finds the same parameters."""
    diabetes = load_diabetes()
    X_diabetes, y_diabetes = diabetes.data, diabetes.target
    ind = np.arange(X_diabetes.shape[0])
    rng = np.random.RandomState(0)
    rng.shuffle(ind)
    X_diabetes, y_diabetes = X_diabetes[ind], y_diabetes[ind]

    clf = MLPRegressor(keep_prob=0.9, random_state=42, n_epochs=100)
    target = y_diabetes
    # Just predict on the training set, for simplicity.
    pred1 = clf.fit(X_diabetes, target).predict(X_diabetes)
    pred2 = clf.fit(X_diabetes, target).predict(X_diabetes)
    assert_array_almost_equal(pred1, pred2)
Example #7
0
def test_replicability():
    """Make sure running fit twice in a row finds the same parameters."""
    diabetes = load_diabetes()
    X_diabetes, y_diabetes = diabetes.data, diabetes.target
    ind = np.arange(X_diabetes.shape[0])
    rng = np.random.RandomState(0)
    rng.shuffle(ind)
    X_diabetes, y_diabetes = X_diabetes[ind], y_diabetes[ind]

    clf = MLPRegressor(keep_prob=0.9, random_state=42, n_epochs=100)
    target = y_diabetes
    # Just predict on the training set, for simplicity.
    pred1 = clf.fit(X_diabetes, target).predict(X_diabetes)
    pred2 = clf.fit(X_diabetes, target).predict(X_diabetes)
    assert_array_almost_equal(pred1, pred2)
Example #8
0
def test_predict():
    """Test binary classification."""
    check_predictions(MLPRegressor(**KWARGS), X, Y)
    check_predictions(MLPRegressor(**KWARGS), X_sp, Y)
Example #9
0
def test_sample_weight():
    """Ensure we handle sample weights for regression problems."""
    assert_sample_weights_work(
        make_regression, {'n_samples': 3000}, lambda: MLPRegressor(
            n_epochs=30, random_state=42, keep_prob=0.8, hidden_units=(128, )))