예제 #1
0
    def test_validation(self):
        with self.assertRaises(ValueError):
            # More clusters than samples
            nw = algorithms.RBFKMeans(n_clusters=1000, verbose=False)
            nw.train(data, epsilon=1e-5)

        with self.assertRaises(ValueError):
            # Number of clusters the same as number of samples
            nw = algorithms.RBFKMeans(n_clusters=data.shape[0], verbose=False)
            nw.train(data, epsilon=1e-5)

        with self.assertRaises(ValueError):
            # One cluster
            nw = algorithms.RBFKMeans(n_clusters=1, verbose=False)
            nw.train(data, epsilon=1e-5)
예제 #2
0
    def test_rbfk_predict_different_inputs(self):
        kmnet = algorithms.RBFKMeans(verbose=False, n_clusters=2)

        data = np.array([[1, 2, 10]]).T
        target = np.array([[0, 0, 1]]).T

        kmnet.train(data)
        self.assertInvalidVectorPred(kmnet, data.ravel(), target, decimal=2)
예제 #3
0
    def test_rbfk_classification(self):
        expected_centers = np.array([
            [0.228, 0.312],
            [0.482,  0.767],
        ])

        nw = algorithms.RBFKMeans(n_clusters=2, verbose=False)
        nw.train(data, epsilon=1e-5)
        np.testing.assert_array_almost_equal(expected_centers, nw.centers,
                                             decimal=3)
예제 #4
0
    def test_classification(self):
        result = np.array([
            [0.228, 0.312],
            [0.48166667, 0.76666667],
        ])

        nw = algorithms.RBFKMeans(n_clusters=2, verbose=False)
        nw.train(self.data, epsilon=1e-5)
        self.assertTrue(np.all(result == np.round(nw.centers, 8)))

        if self.draw_plot:
            classes = nw.predict(self.data)

            for i, center in enumerate(nw.centers):
                positions = np.argwhere(classes[:, 0] == i)
                class_data = np.take(self.data, positions[:, 0], axis=0)
                plt.plot(class_data[:, 0], class_data[:, 1], 'o')

            for center in nw.centers:
                plt.plot(center[0], center[1], 'kx')

            plt.axis([0, 1, 0, 1])
            plt.show()
예제 #5
0
 def test_rbfk_means_assign_step_exception(self):
     with self.assertRaises(ValueError):
         algorithms.RBFKMeans(n_cluster=2, step=0.01)
예제 #6
0
 def test_rbfk_train_different_inputs(self):
     self.assertInvalidVectorTrain(
         algorithms.RBFKMeans(n_clusters=2, verbose=False),
         np.array([1, 2, 10]),
     )
예제 #7
0
#confusion matrix
confusion_matrix(y1_test, y1_pnn_predicted)

# In[20]:

pnn_acc_score = accuracy_score(y1_test, y1_pnn_predicted)
print("Pnn accuracy score ", pnn_acc_score)

#  ## 1c.  RBF - [ Diabities Problem ]
#
#

# In[21]:

rbf_nw = algorithms.RBFKMeans(n_clusters=2, verbose=False)

# In[22]:

rbf_nw.train(X1_train, epsilon=1e-5)

# In[23]:

y1_rbf_predicted = rbf_nw.predict(X1_test)

# In[24]:

confusion_matrix(y1_test, y1_rbf_predicted)

# In[25]: