Esempio n. 1
0
    def test_art_handle_errors(self):
        with self.assertRaises(ValueError):
            # Invalid input data dimension
            artnet = algorithms.ART1(step=0.4,
                                     rho=0.1,
                                     n_clusters=3,
                                     verbose=False)
            artnet.predict(np.array([0.5]))

        with self.assertRaises(ValueError):
            # Non-binary input values
            artnet = algorithms.ART1(step=0.4,
                                     rho=0.1,
                                     n_clusters=3,
                                     verbose=False)
            artnet.predict(np.array([[0.5]]))

        with self.assertRaises(ValueError):
            # Invalid data size for second input
            artnet = algorithms.ART1(step=0.4,
                                     rho=0.1,
                                     n_clusters=3,
                                     verbose=False)
            artnet.predict(np.array([[0.5]]))
            artnet.predict(np.array([[0.5, 1]]))
Esempio n. 2
0
    def test_simple_art1(self):
        ann = algorithms.ART1(step=2, rho=0.7, n_clusters=2, verbose=False)
        classes = ann.predict(data)

        for answer, result in zip([0, 1, 1], classes):
            self.assertEqual(result, answer)

        self.assertPickledNetwork(ann, data)
Esempio n. 3
0
    def test_art1_on_real_problem(self):
        data = pd.DataFrame(lenses)

        encoder = preprocessing.OneHotEncoder()
        enc_data = encoder.fit_transform(data.values[:, 1:]).toarray()

        artnet = algorithms.ART1(step=1.5,
                                 rho=0.7,
                                 n_clusters=3,
                                 verbose=False)
        classes = artnet.predict(enc_data)

        unique_classes = list(np.sort(np.unique(classes)))
        self.assertEqual(unique_classes, [0, 1, 2])
Esempio n. 4
0
    def test_art1_on_real_problem(self):
        path_to_data = os.path.join(BASEDIR, '..', 'data', 'lenses.csv')
        data = pd.read_csv(path_to_data, index_col=[0], sep=' ', header=None)

        encoder = preprocessing.OneHotEncoder()
        enc_data = encoder.fit_transform(data.values[:, 1:]).toarray()

        artnet = algorithms.ART1(step=1.5,
                                 rho=0.7,
                                 n_clusters=3,
                                 verbose=False)
        classes = artnet.predict(enc_data)

        self.assertEqual(list(np.sort(np.unique(classes))), [0, 1, 2])
Esempio n. 5
0
import numpy as np
from neupy import algorithms, environment

environment.reproducible()
file_name = 'dosen'
data = np.genfromtxt(file_name + '.csv', delimiter=',')
artnet = algorithms.ART1(step=2, rho=0.7, n_clusters=2, verbose=False)
artnet.predict(data)