GithubHelp home page GithubHelp logo

jorgeavilacartes / k-means-waveletemd Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 22 KB

K-means using wavelet Earth Mover's Distance

License: GNU General Public License v3.0

Jupyter Notebook 77.00% Python 23.00%

k-means-waveletemd's Introduction

K-means-waveletEMD

K-means using wavelet Earth Mover's Distance

K-means is trained using pyclustering library. WaveletEMD is based on wavelet transoform, using pywavelet library


Usage

import random
from src import KmeansOT
from src import WaveletEMD

# data to train the model
n_samples = 100
train_data = [[random.random() for _ in range(10)] for _ in range(n_samples)]

# train
num_clusters = 2
kmeans = KmeansOT(n_clusters=num_clusters, random_state=2)
kmeans.fit(train_data)

# test
n_test = 10
test_data = [[random.random() for _ in range(10)] for _ in range(n_test)]

# A list with cluster predictions ([0,num_clusters-1])
kmeans.predict(test_data) 

Information after training

# Centers of each cluster
kmeans.centers

# List for each cluster, with the idx of each sample in train_data 
kmeans.clusters

# trained model
kmeans.kmeans

By default, the WaveletEMD is set under this configuration

pywt.wavedec(wavelet = "sym5", level = 6, mode = "zero")

To run K-means using a different family and/or level, you must initialize K-means as shown below:

# New wavelet function
wemd = WaveletEMD(wavelet = "haar", level = 2, mode = "zero") 
new_metric = distance_metric(type_metric.USER_DEFINED, func=wemd)

# Include new metric in the KmeansOT
kmeans = KmeansOT(n_clusters=num_clusters, metric = new_metric, random_state=2)

k-means-waveletemd's People

Contributors

jorgeavilacartes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.