def test_KMeans_random_init(self): datapoints, labels = gaussian(n=100, d=2, labels=3, sigma=0.1, seed=1970) X_train, y_train, X_test, y_test = train_test_split(datapoints, labels, train_split=0.95, seed=1970) classifier = KMeans(k=3, seed=1970, initialisation='Random') classifier.train(X=X_train) self.assertEqual(self.classifier.iterations, 7)
def setUpClass(cls): cls.datapoints, cls.labels = gaussian(n=100, d=2, labels=3, sigma=0.1, seed=1970) cls.X_train, cls.y_train, cls.X_test, cls.y_test = train_test_split( cls.datapoints, cls.labels, train_split=0.95, seed=1970) cls.classifier = KNNClassifier(n=5) cls.classifier.train(X=cls.X_train, y=cls.y_train)
def test_KMeans_MoreKThanN_Error(self): datapoints, labels = gaussian(n=5, d=2, labels=2, sigma=0.1, seed=1970) classifier = KMeans(k=11) self.assertRaises(ValueError, classifier.train, datapoints, labels)