-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkmeans.py
More file actions
37 lines (30 loc) · 835 Bytes
/
kmeans.py
File metadata and controls
37 lines (30 loc) · 835 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
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 23 10:06:45 2016
@author: Damien
"""
#general purpose
from __future__ import division
import math
import time
import pandas as pd
import datetime
import boto3
import psycopg2
import psycopg2.extras
from sqlalchemy import create_engine
import numpy as np
import csv
import datetime as dt
from datetime import timedelta
from functions import *
#kmeans
from scipy import cluster
from sklearn.cluster import KMeans
############################ KMEANS #############################
def mainkmeans(data_res,elbow):
cent, var = cluster.vq.kmeans(data_res,elbow)
#use vq() to get as assignment for each obs.
assignment,cdist = cluster.vq.vq(data_res,cent)
classes = np.array([binarize(i,elbow) for i in assignment])
return classes