Fix My Tutorial
Report

Cambridge Coding Academy

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

3 changes to make it work today

Split into training and test sets

s10 · run_code workaround

Try the old import first, then fall back to the new location.

@@ -1,3 +1,6 @@
-from sklearn.cross_validation import train_test_split
+try:
+ from sklearn.cross_validation import train_test_split
+except ImportError:
+ from sklearn.model_selection import train_test_split
# Split into training and test sets

Sources

  • Release history — scikit-learn 0.18.2 documentationSome estimators can still accept keyword arguments on the `fit` but this is restricted to data-dependent values (e.g. a Gram matrix or an affinity matrix that are precomputed from the `X` data matrix. The `cross_val` package has been renamed to `cross_validation` although there is also a `cross_val` package alias in place for backward compatibility. Third-party projects with a dependency on scikit-learn 0.9+ should upgrade their codebase. For instance, under Linux / MacOSX just run (make a backup first!): ``` find - name".py" | xargs sed - i's/ \b cross_val \b/cross_validation/g' ``` [...] > T

Set up grid search with cross-validation

s16 · run_code workaround

Try the old import first, then fall back to the new location.

@@ -1,3 +1,6 @@
-from sklearn.grid_search import GridSearchCV
+try:
+ from sklearn.grid_search import GridSearchCV
+except ImportError:
+ from sklearn.model_selection import GridSearchCV
# Search for good hyperparameter values

Sources

  • Release history — scikit-learn 0.18.2 documentationSome estimators can still accept keyword arguments on the `fit` but this is restricted to data-dependent values (e.g. a Gram matrix or an affinity matrix that are precomputed from the `X` data matrix. The `cross_val` package has been renamed to `cross_validation` although there is also a `cross_val` package alias in place for backward compatibility. Third-party projects with a dependency on scikit-learn 0.9+ should upgrade their codebase. For instance, under Linux / MacOSX just run (make a backup first!): ``` find - name".py" | xargs sed - i's/ \b cross_val \b/cross_validation/g' ``` [...] > T

Visualize grid search results as heatmap

s19 · run_code workaround

Use grid_scores_ if present (old API), otherwise use cv_results_ (new API).; Replace invalid origin='higher' with origin='upper' which is a supported value in matplotlib 3.11+.

@@ -3,5 +3,8 @@
# fetch scores, reshape into a grid
-scores = [x[1] for x in gridCV.grid_scores_]
+if hasattr(gridCV, 'grid_scores_'):
+ scores = [x[1] for x in gridCV.grid_scores_]
+else:
+ scores = gridCV.cv_results_['mean_test_score']
scores = np.array(scores).reshape(len(n_estimators), len(max_features))
scores = np.transpose(scores)
@@ -9,5 +12,5 @@
# Make heatmap from grid search results
plt.figure(figsize=(12, 6))
-plt.imshow(scores, interpolation='nearest', origin='higher', cmap='jet_r')
+plt.imshow(scores, interpolation='nearest', origin='upper', cmap='jet_r')
plt.xticks(np.arange(len(n_estimators)), n_estimators)
plt.yticks(np.arange(len(max_features)), max_features)

Sources

  • Release history — scikit-learn 0.18.2 documentationSome estimators can still accept keyword arguments on the `fit` but this is restricted to data-dependent values (e.g. a Gram matrix or an affinity matrix that are precomputed from the `X` data matrix. The `cross_val` package has been renamed to `cross_validation` although there is also a `cross_val` package alias in place for backward compatibility. Third-party projects with a dependency on scikit-learn 0.9+ should upgrade their codebase. For instance, under Linux / MacOSX just run (make a backup first!): ``` find - name".py" | xargs sed - i's/ \b cross_val \b/cross_validation/g' ``` [...] > T
  • Matplotlib.pdf(points or pixels) the origin is the bottom-left of the figure or Axes. Points are typographic points meaning that they are a physical unit measuring 1/72 of an inch. Points and pixels are discussed in further detail in Plotting in physical coordinates. [...] For origin='lower': • [0, 0] is at (left, bottom) • [M', 0] is at (left, top) • [0, N'] is at (right, bottom) • [M', N'] is at (right, top) origin='upper' reverses the vertical axes direction and filling: 284 Chapter 3. Using Matplotlib Matplotlib, Release 3.11.1 • [0, 0] is at (left, top) • [M', 0] is at (left, bottom) • [0, N'] is at (r
  • matplotlib.pyplot.imshow — Matplotlib 3.11.1 documentationmatplotlib.pyplot.imshow(X, cmap=None, norm=None, \, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, colorizer=None, origin=None, extent=None, interpolation\_stage=None, filternorm=True, filterrad=4.0, resample=None, url=None, data=None, \\kwargs)( : Display data as an image, i.e., on a 2D regular raster.
  • Positioning and orientation of imshow images — Matplotlib 3.11.2 documentationThe default value of origin is set by `rcParams["image.origin"]rcParams["image.origin"]` (default: `'upper'`) which defaults to `'upper'` to match the matrix indexing conventions in math and computer graphics image indexing conventions.

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error.

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-ktfPw61V.svg)](https://fix-my-tutorial.onrender.com/r/ri-ktfPw61V)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/ri-ktfPw61V"><img src="https://fix-my-tutorial.onrender.com/badge/ri-ktfPw61V.svg" alt="Fix My Tutorial"></a>