Skip to content

Commit

Permalink
Merge pull request #2 from ogrisel/glouppe-parallel-forest
Browse files Browse the repository at this point in the history
Update random forest example to demo n_jobs=2
  • Loading branch information
glouppe committed Dec 30, 2011
2 parents da927fb + 1d1348e commit 7aedf4b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/ensemble/plot_forest_importances_faces.py
Expand Up @@ -9,11 +9,15 @@
"""
print __doc__

from time import time
import pylab as pl

from sklearn.datasets import fetch_olivetti_faces
from sklearn.ensemble import ExtraTreesClassifier

# Number of cores to use to perform parallel fitting of the forest model
n_jobs=2

# Loading the digits dataset
data = fetch_olivetti_faces()
X = data.images.reshape((len(data.images), -1))
Expand All @@ -24,12 +28,15 @@
y = y[mask]

# Build a forest and compute the pixel importances
print "Fitting ExtraTreesClassifier on faces data with %d cores..." % n_jobs
t0 = time()
forest = ExtraTreesClassifier(n_estimators=1000,
max_features=128,
compute_importances=True,
random_state=0)
random_state=0, n_jobs=n_jobs)

forest.fit(X, y)
print "done in %0.3fs" % (time() - t0)
importances = forest.feature_importances_
importances = importances.reshape(data.images[0].shape)

Expand Down

0 comments on commit 7aedf4b

Please sign in to comment.