Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

i got error in this code please help me to rectify this error

Thowsif ShaikThowsif Shaik Member Posts: 1

import numpy as np
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
from sklearn.preprocessing import scale

def createClusterdData(N,K):
np.random.seed(10)
pointspercluster=float (N)/K
x=[]
for i in range (K):
incomecentroid = np.random.uniform(20000.0,200000.0)
agecentroid = np.random.uniform(20.0,70.0)
for j in range(int(pointspercluster)):
x.append([np.random.normal(incomecentroid,10000.0),np.random.normal(agecentroid,2.0)])

y=np.array(x)
return x

data = createClusterdData(100,5)

print data

model = KMeans(n_clusters=5)
model = model.fit(scale(data))

print model.labels_

s = np.array(data[0:,0])
t = np.arrsy(data[0:,1])
plt.figure(figsize = (8, 6))
plt.scatter(s,t,c=model.labels_.astype(np.float))
plt.show()

error:
s = np.array(data[0:,0])
TypeError: list indices must be integers, not tuple

Sign In or Register to comment.