Giter Site home page Giter Site logo

epapagia / kmeans-and-kernel-kmeans Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rarezhang/kmeans-and-kernel-kmeans

0.0 1.0 0.0 148 KB

####Goals#### * Implement the following clustering algorithms: K-means and Kernel K-means. * Implement the following supervised clustering evaluation metrics: purity and NMI.

Python 100.00%

kmeans-and-kernel-kmeans's Introduction

coursera - UIUC - clustering analysis in data mining - Programming Assignment - Python version

####Prerequisites:####

  • python: If you are working on your own machine, you will probably need to install Python. The code in this assignment works for python 2.7.
  • linux (recommended) or windows (you may not be able to apply the make commands, but you can use your own IDE, such as Visual Studio and Code Blocks.)

####Goals####

  • Implement the following clustering algorithms: K-means and Kernel K-means.
  • Implement the following supervised clustering evaluation metrics: purity and NMI.

####Step 1. K-means####

  • Complete the following two key functions of K-means in k_means.py
def updateClusterID(data, centers):
    nData = len(data) 
    
    clusterID = [0] * nData
    
    # TODO 
    # assign the closet center to each data point
    
    return clusterID

# K: number of clusters 
def updateCenters(data, clusterID, K):
    nDim = len(data[0])
    centers = [[0] * nDim for i in range(K)]

    # TODO recompute the centers based on current clustering assignment
    # If a cluster doesn't have any data points, in this homework, leave it to ALL 0s

    return centers 
  • Write the purity and NMI metrics in evaluation.py
def  purity(groundtruthAssignment, algorithmAssignment):
    # TODO  
    # Compute the purity 
    
    return purity 


def NMI(groundtruthAssignment, algorithmAssignment):
    # TODO
    # Compute the NMI

    return NMI
  • Use the following command line to run the python script
python main_k_means.py  ../data/self_test.data ../data/self_test.ground
  • If your implementation is correct, you should have information printed on your screen that is very similar to the information given below.
# of iterations: 11
SSE =  24189.053923
Purity = 0.666666666667
NMI =  0.0848243120365

####Step 2. Kernel K-means####

  • Once you have done K-means, you only need to implement a wrapper to transform the data points into the kernel space for kernel K-means. In this homework, we are going to implement the RBF kernel. Please complete the following coordinates transformation function, in file kernel_k_means.py
def kernel(data, sigma):
    nData = len(data)
    Gram = [[0] * nData for i in range(nData)] 
    # TODO
    # Calculate the Gram matrix 

    return Gram 
  • Use the following command line to run the python script
python main_kernel_k_means.py  ../data/self_test.data ../data/self_test.ground
  • If your implementation is correct, you should have information printed on your screen that is very similar to the information given below.
# of iterations: 3
SSE =  2991.54279799
Purity = 0.996666666667
NMI =  0.968782533951

kmeans-and-kernel-kmeans's People

Contributors

rarezhang 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.