def test_kmeans(self): with open('s2/tests/datasets/iris.pkl', mode='rb') as f: expected_predictions = pickle.load(f) kmeans = KMeans(K=3, metric='euclidean', vis_dims=0, seed=self.seed, name='test') predictions = kmeans.fit_predict(self.dataset) self.assertEqual(predictions, expected_predictions)
for nb_points in range(5000,46000,2500): x.append(nb_points) print(nb_points) X = dataset.sample(n=nb_points) y = [0] * nb_points fit_times['K-Means'][nb_points] = [] fit_times['K-Means++'][nb_points] = [] fit_times['GK-Means'][nb_points] = [] fit_times['IF K-Means'][nb_points] = [] for count in range(0, 10): print('\t{}'.format(count)) print('\tK-Means Random Initialization') start_time = time.clock() kmeans = KMeans(15, X=X.values, Y=y, name='NORM-10') kmeans.find_centers() end_time = time.clock() fit_times['K-Means'][nb_points].append(end_time-start_time) print('\tK-Means++') start_time = time.clock() kpp = KPlusPlus(15, X=X.values, Y=y, name='NORM-10') kpp.init_centers() kpp.find_centers(method='++') end_time = time.clock() fit_times['K-Means++'][nb_points].append(end_time-start_time) print('\tK-Means Graph') start_time = time.clock() kmeansgraph = KMeansGraph(15, X=X, Y=y, name='NORM-10')
return temp if __name__ == '__main__': HOST = sys.argv[1] PORT = int(sys.argv[2]) BROKER_HOST = sys.argv[3] BROKER_PORT = int(sys.argv[4]) print("Initializing the web server & MQTT broker") print("BROKER HOST {}".format(BROKER_HOST)) print("BROKER PORT {}".format(BROKER_PORT)) print("HOST {}".format(HOST)) print("PORT {}".format(PORT)) # Initialization of data postprocessing and ML algorithm kmeans = KMeans(k=3) kmeans.load('algorithms/model/{}.pickle'.format(MODEL_NAME)) # Calibrate the sensors sensor = PostProcessing() sensor.load_gyro_calibration( file_path="algorithms/calibration/calibration_values.txt") ### Establishing code for the broker # Establish the broker service def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) client.subscribe("esys/HeadAid/sensor") def on_message(client, userdata, msg): # Get the raw data
def test_predict_before_fit_throws_error(self): kmeans = KMeans(K=3, metric='euclidean', vis_dims=0, seed=self.seed, name='test') with self.assertRaises(Exception): kmeans.predict(self.dataset)
def test_kmeans_with_invalid_metric(self): with self.assertRaises(ValueError): _ = KMeans(K=3, metric='mahalanobis', name='test')
def test_kmeans_with_invalid_visualization_dimensions(self): with self.assertRaises(ValueError): _ = KMeans(K=0, name='test')
def test_kmeans_with_invalid_clusters(self): with self.assertRaises(ValueError): _ = KMeans(K=0, name='test')
print(train.shape) for i in range(0, iterations): print('Iteration {}'.format(i + 1)) # Train train = train.rename(columns={0: 'label'}) y_train = train.label y_train = y_train.apply(str) X_train = train.drop("label", axis=1) ### Random initialization print('\tK-Means Random Initialization') start_time = time.clock() kmeans = KMeans(args.k, X=X_train.values, Y=y_train.values, name=dataset_name) kmeans.find_centers() end_time = time.clock() #accuracy['kmeans'].append(kmeans.get_error_count(X_test.values, y_test.values)) method['K-Means']['phi'].append(kmeans.get_sum_distances()) method['K-Means']['fit_time'].append(end_time - start_time) #kmeans.plot_board() ### K-means++ initialization print('\tK-Means++') start_time = time.clock() kpp = KPlusPlus(args.k, X=X_train.values, Y=y_train.values,