Kiyoshika / CppEZML

A work in progress C++ machine learning library designed to be very easy to use. Everything pretty much written from scratch.
0 stars 0 forks source link

Implement KMeans #23

Closed Kiyoshika closed 3 years ago

Kiyoshika commented 3 years ago

Implement KMeans clustering algorithm.

Kiyoshika commented 3 years ago

Implemented in v0.5.0.1 branch (in progress as of 1 August 2021)

#include <iostream>
#include "data/DataSet.h"
#include "models/clustering/KMeans.h"

using namespace std;

int main() {
    DataSet xdata;

    // a sample data set with unlabeled decimal values
    xdata.load("test.csv");

    // k = 3, max_iter = 1000
    Cluster *kmeans = new KMeans(3, 1000);
    vector<int> clusters = kmeans->fit(xdata.cast_data_double());

    for (int i = 0; i < clusters.size(); ++i)
    {
        cout << clusters[i] << " ";
    }
    delete kmeans;

    return 0;
}