Fix My Tutorial
Report

Diving into data

Open the original tutorial
Could not fix Python 3.12 · checked 17 Oct 2026 · model cost $0.142

We ran out of time to try more fixes for step s4.

3 changes to make it work today

Run block 1: basic random forest feature importance

s2 · run_code migrate

Replace deprecated load_boston with fetch_california_housing and fix print syntax for Python 3.

@@ -1,13 +1,12 @@
-from sklearn.datasets import load_boston
+from sklearn.datasets import fetch_california_housing
from sklearn.ensemble import RandomForestRegressor
import numpy as np
-#Load boston housing dataset as an example
-boston = load_boston()
-X = boston["data"]
-Y = boston["target"]
-names = boston["feature_names"]
+# Load california housing dataset as an example
+california = fetch_california_housing(as_frame=False)
+X = california["data"]
+Y = california["target"]
+names = california["feature_names"]
rf = RandomForestRegressor()
rf.fit(X, Y)
-print "Features sorted by their score:"
-print sorted(zip(map(lambda x: round(x, 4), rf.feature_importances_), names),
- reverse=True)
+print("Features sorted by their score:")
+print(sorted(zip(map(lambda x: round(x, 4), rf.feature_importances_), names), reverse=True))

Sources

Run block 2: correlated features example

s3 · run_code migrate

Fix print syntax, update numpy random seed call, and convert map to list for Python 3.

@@ -1,4 +1,4 @@
size = 10000
-np.random.seed(seed=10)
+np.random.seed(10)
X_seed = np.random.normal(0, 1, size)
X0 = X_seed + np.random.normal(0, .1, size)
@@ -9,5 +9,4 @@
rf = RandomForestRegressor(n_estimators=20, max_features=2)
-rf.fit(X, Y);
-print "Scores for X0, X1, X2:", map(lambda x:round (x,3),
- rf.feature_importances_)
+rf.fit(X, Y)
+print("Scores for X0, X1, X2:", list(map(lambda x: round(x, 3), rf.feature_importances_)))

Sources

Run block 3: mean decrease accuracy (permutation importance)

s4 · run_code migrate

Update ShuffleSplit import to current location, use california dataset, and fix print syntax.

@@ -1,17 +1,17 @@
-from sklearn.cross_validation import ShuffleSplit
+from sklearn.model_selection import ShuffleSplit
from sklearn.metrics import r2_score
from collections import defaultdict
-X = boston["data"]
-Y = boston["target"]
+X = california["data"]
+Y = california["target"]
rf = RandomForestRegressor()
scores = defaultdict(list)
-#crossvalidate the scores on a number of different random splits of the data
+# crossvalidate the scores on a number of different random splits of the data
for train_idx, test_idx in ShuffleSplit(len(X), 100, .3):
X_train, X_test = X[train_idx], X[test_idx]
Y_train, Y_test = Y[train_idx], Y[test_idx]
- r = rf.fit(X_train, Y_train)
+ rf.fit(X_train, Y_train)
acc = r2_score(Y_test, rf.predict(X_test))
for i in range(X.shape[1]):
@@ -19,6 +19,5 @@
np.random.shuffle(X_t[:, i])
shuff_acc = r2_score(Y_test, rf.predict(X_t))
- scores[names[i]].append((acc-shuff_acc)/acc)
-print "Features sorted by their score:"
-print sorted([(round(np.mean(score), 4), feat) for
- feat, score in scores.items()], reverse=True)
+ scores[names[i]].append((acc - shuff_acc) / acc)
+print("Features sorted by their score:")
+print(sorted([(round(np.mean(score), 4), feat) for feat, score in scores.items()], reverse=True))

Sources

What we tried

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

3 rounds of fixes.

TypeError: ShuffleSplit.__init__() takes from 1 to 2 positional arguments but 4 were given

1 round of fixes, none passed.

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