Fix My Tutorial
Report

Supervised Learning: Classification of Handwritten Digits

Open the original tutorial
Fixed Python 3.12 · checked 17 Oct 2026 · model cost $0.073

After applying the fixes, the tutorial runs successfully under Python 3.12. The original code failed because it imported RandomizedPCA from sklearn.decomposition and used the deprecated sklearn.cross_validation module, both of which were removed in newer scikit‑learn releases. The repairs replaced RandomizedPCA with PCA(svd_solver='randomized') and updated the import to sklearn.model_selection.

2 changes to make it work today

Apply RandomizedPCA for dimensionality reduction

s5 · run_code migrate

Replace deprecated RandomizedPCA with PCA using the randomized SVD solver, which provides equivalent functionality in scikit-learn 1.9.1.

@@ -1,3 +1,3 @@
-from sklearn.decomposition import RandomizedPCA
-pca = RandomizedPCA(n_components=2, random_state=1999)
+from sklearn.decomposition import PCA
+pca = PCA(n_components=2, svd_solver='randomized', random_state=1999)
proj = pca.fit_transform(digits.data)

Sources

  • sklearn.decomposition.PCA — scikit-learn 0.17.1 documentation`RandomizedPCA`, `KernelPCA`, `SparsePCA`, `TruncatedSVD`
  • Release history — scikit-learn 0.18.2 documentationRefactored and vectorized implementation of `metrics.roc_curve` and `metrics.precision_recall_curve`. By Joel Nothman. The new estimator `sklearn.decomposition.TruncatedSVD` performs dimensionality reduction using SVD on sparse matrices, and can be used for latent semantic analysis (LSA). By Lars Buitinck. Added self-contained example of out-of-core learning on text data Out-of-core classification of text documents. By Eustache Diemert. The default number of components for `sklearn.decomposition.RandomizedPCA` is now correctly documented to be `n_features`. This was the default behavior, so pr

Import GaussianNB and train_test_split

s9 · run_code migrate

Replace the removed sklearn.cross_validation import with the current sklearn.model_selection module where train_test_split now lives.

@@ -1,2 +1,2 @@
from sklearn.naive_bayes import GaussianNB
-from sklearn.cross_validation import train_test_split
+from sklearn.model_selection import train_test_split

Sources

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error. The issue opens on GitHub under your own account, filled in for you to review.

Badge

Add it to the tutorial so readers know when it was last checked.

Fix My Tutorial badge
Markdown
[![Fix My Tutorial](https://fix-my-tutorial.onrender.com/badge/ri-LZxheVYy.svg)](https://fix-my-tutorial.onrender.com/r/ri-LZxheVYy)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/ri-LZxheVYy"><img src="https://fix-my-tutorial.onrender.com/badge/ri-LZxheVYy.svg" alt="Fix My Tutorial"></a>