K-Medoids algorithm
2016-08-23
0 0 0
4.0
Other
Earn points
#!/usr/bin/python import argparse import csv import numpy import sys # SCRIPT PARAMETERS parser = argparse.ArgumentParser(description='k-Medoids clustering implementation.') parser.add_argument('--dataset', required=True, help='File in CSV format containing samples.') parser.add_argument('--k', required=True, type=int, help='Number of clusters.') parser.add_argument('--iterations', required=False, default=500, type=int, help='Maximum number of iterations.') opt = vars(parser.parse_args()) # GLOBAL VARIABLES targetClass = '' attributeClass = {} data = [] medoids = [] k = opt['k'] N = 0 # N: size of training set max_iter = int(opt['iterations']) # LOAD DATASET with open(opt['dataset']) as f: reader = csv.DictReader(f, delimiter='\t') # LOAD ATTRIBUTE TYPES (continuous, discrete, ignore) attributeClass = reader.next() # DETERMINE TARGET CLASS classLine = reader.next() for i in attributeClass: if classLine[i]=='class': targetClass = i
python
Related Source Codes
Word memorization software
0
0
no vote
CWT Python example
0
0
no vote
STFT example
0
0
no vote
Chinese Speech Recognition
0
0
no vote
python-ela
0
0
no vote
No comment