def test_classifier_iris(): import os csv_file = os.path.join(os.path.dirname(__file__), "iris.csv") data = np.genfromtxt(csv_file, dtype=float, delimiter=',', names=True) X = np.array([data["sepallength"], data["sepalwidth"], data["petallength"], data["petalwidth"]]).T y = data["class"] from sklearn.preprocessing import MinMaxScaler X = MinMaxScaler().fit_transform(X) l = fpcga.FuzzyPatternClassifierGA(iterations=100) from sklearn import cross_validation scores = cross_validation.cross_val_score(l, X, y, cv=10) mean = np.mean(scores) print("mean", mean) assert 0.90 < mean
def test_classifier_single(): l = fpcga.FuzzyPatternClassifierGA(iterations=25, epsilon=None) X = np.array([ [0.1, 0.2, 0.4], [0.11, 0.3, 0.5], [0.2, 0.4, 0.8], [0.18, 0.42, 0.88] ]) y = np.array([ 3, 3, 10, 10 ]) l.fit(X, y) y_pred = l.predict([0.17, 0.45, 0.85]) assert 10 == y_pred
def test_classifier_iris(): iris = load_iris() X = iris.data y = iris.target from sklearn.preprocessing import MinMaxScaler X = MinMaxScaler().fit_transform(X) l = fpcga.FuzzyPatternClassifierGA(iterations=100, random_state=1) from sklearn.model_selection import cross_val_score scores = cross_val_score(l, X, y, cv=10) assert len(scores) == 10 assert np.mean(scores) > 0.6 mean = np.mean(scores) print("mean", mean) assert 0.92 == pytest.approx(mean, 0.01)