Пример #1
0
    def test_Ridge(self):

        breast_cancer = load_breast_cancer()
        X = breast_cancer.data
        y = breast_cancer.target
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.2,
                                                            random_state=71023)

        wine = load_wine()
        Z = wine.data
        t = wine.target
        Z_train, Z_test, t_train, t_test = train_test_split(Z,
                                                            t,
                                                            test_size=0.2,
                                                            random_state=61283)

        fit_obj = ns.Ridge2Classifier(lambda1=0.025,
                                      lambda2=0.5,
                                      n_hidden_features=5,
                                      n_clusters=0)

        fit_obj2 = ns.Ridge2Classifier(lambda1=0.01,
                                       lambda2=0.01,
                                       n_hidden_features=10,
                                       n_clusters=2)

        fit_obj3 = ns.Ridge2Classifier(lambda1=0.025,
                                       lambda2=0.05,
                                       n_hidden_features=5,
                                       n_clusters=0)

        fit_obj4 = ns.Ridge2Classifier(lambda1=0.001,
                                       lambda2=0.01,
                                       n_hidden_features=10,
                                       n_clusters=2)

        fit_obj.fit(X_train, y_train)
        preds1 = fit_obj.predict_proba(X_test)

        fit_obj2.fit(X_train, y_train)
        preds2 = fit_obj.predict_proba(X_test)

        fit_obj3.fit(Z_train, t_train)
        preds3 = fit_obj3.predict_proba(Z_test)

        fit_obj4.fit(Z_train, t_train)
        preds4 = fit_obj4.predict_proba(Z_test)

        self.assertTrue(np.allclose(preds1[0, 0], 5.1412488698250085e-06))
        self.assertTrue(np.allclose(preds2[0, 0], 5.1412488698250085e-06))
        self.assertTrue(np.allclose(preds3[0, 0], 0.0488412175))
        self.assertTrue(np.allclose(preds4[0, 0], 0.8545733738))

        self.assertTrue(
            np.allclose(fit_obj.predict(X_test)[0], 1)
            & np.allclose(fit_obj2.predict(X_test)[0], 1)
            & np.allclose(fit_obj3.predict(Z_test)[0], 1)
            & np.allclose(fit_obj4.predict(Z_test)[0], 0))
Пример #2
0
    def test_score(self):
        breast_cancer = load_breast_cancer()
        X = breast_cancer.data
        y = breast_cancer.target
        np.random.seed(123)
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.2)

        wine = load_wine()
        Z = wine.data
        t = wine.target
        np.random.seed(123)
        Z_train, Z_test, t_train, t_test = train_test_split(Z,
                                                            t,
                                                            test_size=0.2)

        fit_obj = ns.Ridge2Classifier(lambda1=0.025,
                                      lambda2=0.5,
                                      n_hidden_features=5,
                                      n_clusters=2)

        fit_obj2 = ns.Ridge2Classifier(lambda1=0.01,
                                       lambda2=0.01,
                                       n_hidden_features=10,
                                       n_clusters=2)

        fit_obj3 = ns.Ridge2Classifier(lambda1=0.025,
                                       lambda2=0.05,
                                       n_hidden_features=5,
                                       n_clusters=2)

        fit_obj4 = ns.Ridge2Classifier(lambda1=0.001,
                                       lambda2=0.01,
                                       n_hidden_features=10,
                                       n_clusters=2)

        fit_obj.fit(X_train, y_train)
        score1 = fit_obj.score(X_test, y_test)

        fit_obj2.fit(X_train, y_train)
        score2 = fit_obj2.score(X_test, y_test)

        fit_obj3.fit(Z_train, t_train)
        score3 = fit_obj3.score(Z_test, t_test)

        fit_obj4.fit(Z_train, t_train)
        score4 = fit_obj4.score(Z_test, t_test)

        self.assertTrue(np.allclose(score1, 0.9649122807017544))

        self.assertTrue(np.allclose(score2, 0.94736842105263153))

        self.assertTrue(np.allclose(score3, 1.0))

        self.assertTrue(np.allclose(score4, 0.9722222222222222))
Пример #3
0
# dataset no. 1 ----------

breast_cancer = load_breast_cancer()
X = breast_cancer.data
y = breast_cancer.target

# split data into training test and test set
np.random.seed(123)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# create the model with nnetsauce
fit_obj = ns.Ridge2Classifier(lambda1=6.90185578e+04,
                              lambda2=3.17392781e+02,
                              n_hidden_features=95,
                              n_clusters=2,
                              row_sample=4.63427734e-01,
                              dropout=3.62817383e-01,
                              type_clust="gmm")

# fit the model on training set
fit_obj.fit(X_train, y_train)

# get the accuracy on test set
print(fit_obj.score(X_test, y_test))

# get area under the curve on test set (auc)
print(fit_obj.score(X_test, y_test, scoring="roc_auc"))

# dataset no. 2 ----------