%pylab inline import pandas as pd !head data/players_dat.csv df = pd.read_csv('data/players_dat.csv') df.head(5) type(df) df.sort('cash', ascending=0).head(5) df.describe() df.groupby(['gender']).score.mean().plot(kind='bar', title="Scores", rot=0) from sklearn import datasets # generate some clustered data (X == features, L == labels) X, L = datasets.make_blobs(centers=4, cluster_std=0.5, random_state=2) scatter(X[:,0], X[:,1]) scatter(X[:,0], X[:,1], c=L) from sklearn.cluster import KMeans km = KMeans(4) km.fit(X); scatter(X[:,0], X[:,1], c=km.labels_) mu = km.cluster_centers_ print mu scatter(X[:,0], X[:,1], c=km.labels_, alpha=0.5) scatter(mu[:,0], mu[:,1], s=100, c=np.unique(km.labels_)) from skimage.data import camera im_orig = camera() print 'image shape:', im_orig.shape print 'image (min,max):', im_orig.min(), im_orig.max() gray() # set default colormap to gray scale imshow(im_orig) from skimage.transform import resize, rotate, rescale img = (resize(im_orig, (128, 128)) * 255).astype('uint16') print img.dtype print img.shape print (img.min(), img.max()) im_r = rotate(img.astype('float')/255, angle=15, order=2) plt.figure(figsize=(8,4)) plt.subplot(121) plt.imshow(img) plt.subplot(122) plt.imshow(im_r) plt.show() h = hist(img) # optimal threshold from skimage.filter import threshold_otsu thres = threshold_otsu(img) print "otsu thres:", thres plt.figure(figsize=(8,4)) plt.subplot(121) plt.imshow(img > 127) plt.title("Manual") plt.axis('off') plt.subplot(122) plt.imshow(img > thres) plt.title("Otsu") plt.axis('off') from skimage.filter import sobel imshow(sobel(img))