Ejemplo n.º 1
0
    def test_fit_nonlinear_auto(self):
        """ GENSVM: Fit and predict with nonlinear kernel """
        data = load_iris()
        X = data.data
        y = data.target_names[data.target]

        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            random_state=123)
        clf = GenSVM(kernel="rbf", max_iter=1000, random_state=123)
        clf.fit(X_train, y_train)

        pred = clf.predict(X_test, trainX=X_train)
        self.assertTrue(
            set(pred).issubset(set(["versicolor", "virginica", "setosa"])))
Ejemplo n.º 2
0
    def test_fit_predict_strings(self):
        """ GENSVM: Test fit and predict with string targets """
        digits = load_digits(4)
        n_samples = len(digits.images)
        X = digits.images.reshape(n_samples, -1)
        y = digits.target
        labels = np.array(["zero", "one", "two", "three"])
        yy = labels[y]

        X_train, X_test, y_train, y_test = train_test_split(X, yy)
        clf = GenSVM(epsilon=1e-3)  # faster testing
        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))