-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
33 changed files
with
864 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,4 @@ Advanced topics | |
sympy.rst | ||
3d_plotting/index.rst | ||
image_processing/index.rst | ||
|
||
|
||
======= | ||
scikit-learn/index.rst |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.