Skip to content

Commit

Permalink
Merge branch 'fabianp/scikits'
Browse files Browse the repository at this point in the history
* fabianp/scikits:
  some more changes
  some exercise changes
  more cosmetic
  cosmetic stuff
  minor changes
  cosmetic changes
  minor changes
  Small fixes.
  Initial import of scikit-learn tutorial.

Conflicts:
	advanced/index.rst

The chapter on scikits-lear comes last.
  • Loading branch information
esc committed Aug 24, 2011
2 parents e66b7aa + 2fe0d3e commit 778480e
Show file tree
Hide file tree
Showing 33 changed files with 864 additions and 3 deletions.
4 changes: 1 addition & 3 deletions advanced/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,4 @@ Advanced topics
sympy.rst
3d_plotting/index.rst
image_processing/index.rst


=======
scikit-learn/index.rst
Binary file added advanced/scikit-learn/cluster_iris_truth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added advanced/scikit-learn/digits_first_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions advanced/scikit-learn/digits_svm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from scikits.learn import datasets, svm
import pylab as pl

digits = datasets.load_digits()
clf = svm.LinearSVC(fit_intercept=False)
clf.fit(digits.data, digits.target)

for i in range(4):
pl.subplot(2, 4, 1 + i)
pl.imshow(clf.coef_[i].reshape(8, 8), cmap=pl.cm.gray_r, interpolation='nearest')
pl.axis('off')
pl.show()
Binary file added advanced/scikit-learn/faces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions advanced/scikit-learn/faces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Stripped-down version of the face recognition example by Olivier Grisel
http://scikit-learn.sourceforge.net/dev/auto_examples/applications/face_recognition.html
## original shape of images: 50, 37
"""

import numpy as np
from scikits.learn import cross_val, datasets, decomposition, svm

# ..
# .. load data ..
lfw_people = datasets.fetch_lfw_people(min_faces_per_person=70, resize=0.4)
faces = np.reshape(lfw_people.data, (lfw_people.target.shape[0], -1))
train, test = iter(cross_val.StratifiedKFold(lfw_people.target, k=4)).next()
X_train, X_test = faces[train], faces[test]
y_train, y_test = lfw_people.target[train], lfw_people.target[test]

# ..
# .. dimension reduction ..
pca = decomposition.RandomizedPCA(n_components=150, whiten=True)
pca.fit(X_train)
X_train_pca = pca.transform(X_train)
X_test_pca = pca.transform(X_test)

# ..
# .. classification ..
clf = svm.SVC(C=5., gamma=0.001)
clf.fit(X_train_pca, y_train)

print 'Score on unseen data: '
print clf.score(X_test_pca, y_test)


Binary file added advanced/scikit-learn/images/Virginia_Iris.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 778480e

Please sign in to comment.