Example #1
0
    def test_fit_predict_strings(self):
        """ GENSVM_GRID: Test fit and predict with string targets """
        iris = load_iris()
        X = iris.data
        y = iris.target
        labels = iris.target_names
        yy = labels[y]
        X_train, X_test, y_train, y_test = train_test_split(X, yy)

        pg = {
            "p": [1, 1.5, 2.0],
            "kappa": [-0.9, 1.0],
            "lmd": [0.1, 1.0],
            "epsilon": [0.01, 0.002],
            "gamma": [1.0, 2.0],
            "weights": ["unit", "group"],
        }

        clf = GenSVMGridSearchCV(pg)
        clf.fit(X_train, y_train)
        y_pred = clf.predict(X_test)

        pred_set = set(y_pred)
        label_set = set(labels)
        self.assertTrue(pred_set.issubset(label_set))
Example #2
0
    def test_params_rbf_kernel(self):
        """ GENSVM_GRID: Test best params with RBF kernel """
        X, y = load_iris(return_X_y=True)
        X = maxabs_scale(X)
        X_train, X_test, y_train, y_test = train_test_split(X, y)

        pg = {"lmd": [1e-4, 100, 10000], "kernel": ["rbf"]}

        clf = GenSVMGridSearchCV(pg)
        clf.fit(X_train, y_train)

        self.assertTrue(hasattr(clf, "best_params_"))

        y_pred = clf.predict(X_test, trainX=X_train)
        del y_pred