예제 #1
0
def test_feature_importance(X_y_binary):
    X, y = X_y_binary

    sk_clf = SKElasticNetClassifier(loss="log",
                                    penalty="elasticnet",
                                    alpha=0.5,
                                    l1_ratio=0.5,
                                    n_jobs=1,
                                    random_state=0)
    sk_clf.fit(X, y)

    clf = ElasticNetClassifier(n_jobs=1)
    clf.fit(X, y)

    np.testing.assert_almost_equal(sk_clf.coef_.flatten(), clf.feature_importance, decimal=5)
예제 #2
0
def test_feature_importance_multi(X_y_multi):
    X, y = X_y_multi

    sk_clf = SKElasticNetClassifier(loss="log",
                                    penalty="elasticnet",
                                    alpha=0.5,
                                    l1_ratio=0.5,
                                    n_jobs=1,
                                    random_state=0)
    sk_clf.fit(X, y)

    clf = ElasticNetClassifier(n_jobs=1)
    clf.fit(X, y)

    sk_features = np.linalg.norm(sk_clf.coef_, axis=0, ord=2)

    np.testing.assert_almost_equal(sk_features, clf.feature_importance, decimal=5)
예제 #3
0
def test_fit_predict_binary(X_y_binary):
    X, y = X_y_binary

    sk_clf = SKElasticNetClassifier(loss="log",
                                    penalty="elasticnet",
                                    alpha=0.5,
                                    l1_ratio=0.5,
                                    n_jobs=-1,
                                    random_state=0)
    sk_clf.fit(X, y)
    y_pred_sk = sk_clf.predict(X)
    y_pred_proba_sk = sk_clf.predict_proba(X)

    clf = ElasticNetClassifier()
    clf.fit(X, y)
    y_pred = clf.predict(X)
    y_pred_proba = clf.predict_proba(X)

    np.testing.assert_almost_equal(y_pred_sk, y_pred.to_series().values, decimal=5)
    np.testing.assert_almost_equal(y_pred_proba_sk, y_pred_proba.to_dataframe().values, decimal=5)
예제 #4
0
def test_fit_predict_multi(X_y_multi):
    X, y = X_y_multi

    sk_clf = SKElasticNetClassifier(loss="log",
                                    penalty="elasticnet",
                                    alpha=0.5,
                                    l1_ratio=0.5,
                                    n_jobs=-1,
                                    random_state=0)
    sk_clf.fit(X, y)
    y_pred_sk = sk_clf.predict(X)
    y_pred_proba_sk = sk_clf.predict_proba(X)

    clf = ElasticNetClassifier()
    fitted = clf.fit(X, y)
    assert isinstance(fitted, ElasticNetClassifier)

    y_pred = clf.predict(X)
    y_pred_proba = clf.predict_proba(X)

    np.testing.assert_almost_equal(y_pred, y_pred_sk, decimal=5)
    np.testing.assert_almost_equal(y_pred_proba, y_pred_proba_sk, decimal=5)