-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
executable file
·43 lines (36 loc) · 1.09 KB
/
plot.py
File metadata and controls
executable file
·43 lines (36 loc) · 1.09 KB
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
38
39
40
41
42
43
#!/usr/bin/python
import numpy as np
import urllib
cols=39
begin,end = 16,24
#begin,end = 1,30
categorycol=38
raw_data = urllib.urlopen("train")
dataset = np.loadtxt(raw_data, delimiter=",", usecols=range(cols))
x = dataset[:,begin:end]
y = dataset[:,categorycol]
varify_data1 = urllib.urlopen("varification")
#varify_dataset = np.loadtxt(varify_data1, delimiter=",", usecols=range(cols-1))
varify_dataset = np.loadtxt(varify_data1, delimiter=",", usecols=range(cols))
z = varify_dataset[:,begin:end]
a = varify_dataset[:,categorycol]
from sklearn import preprocessing
# normalize the data attributes
normalized_X = preprocessing.normalize(x)
# standardize the data attributes
standardized_X = preprocessing.scale(x)
import pylab as pl
from sklearn import decomposition
pca = decomposition.PCA(n_components=2)
pca.fit(x)
X = pca.transform(x)
pl.scatter(X[:,0], X[:,1], c=y)
print "---------------------------------------"
from sklearn import cluster
model = cluster.KMeans()
model.fit(x)
x_pred = model.predict(x)
pca.fit(x)
X = pca.transform(x)
pl.scatter(X[:,0], X[:,1], c=x_pred)
print model.labels_[::10]