-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (27 loc) · 880 Bytes
/
main.cpp
File metadata and controls
41 lines (27 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//Example to call KMeans algorithm
#include<iostream>
#include<fstream>
#include<vector>
#include "kmeans.h"
using namespace std;
int main()
{
float test_data[10] = {100.0, 200.0,300.0,400,500,600,700,800,900,10000};
int num_of_clusters = 5;
int size_of_data;
vector<float> data_vector;
for (int i=0;i<10;i++) data_vector.push_back(test_data[i]);
size_of_data = data_vector.size();
vector<float> members;
vector<int> members_index;
KMeans kmeans(num_of_clusters,size_of_data);
kmeans.def_initial_centroids(data_vector ,size_of_data, num_of_clusters, 'r');
kmeans.print_centroids();
kmeans.clustering(data_vector);
cout<<"The new centroids are: "<<endl;
kmeans.print_centroids();
kmeans.print_members(1);
members = kmeans.get_members(1);
members_index = kmeans.get_index_members(1);
return 0;
}