Skip to content

Commit 214d9f7

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 813eb4cfc90740cb62cc933ef7a5cbfca57c2e37
1 parent b461177 commit 214d9f7

File tree

1,078 files changed

+3415
-3403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,078 files changed

+3415
-3403
lines changed
170 Bytes
Binary file not shown.
166 Bytes
Binary file not shown.

dev/_downloads/plot_iterative_imputer_variants_comparison.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\nfrom sklearn.datasets import fetch_california_housing\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.impute import IterativeImputer\nfrom sklearn.linear_model import BayesianRidge\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import ExtraTreesRegressor\nfrom sklearn.neighbors import KNeighborsRegressor\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.model_selection import cross_val_score\n\nN_SPLITS = 5\n\nrng = np.random.RandomState(0)\n\nX_full, y_full = fetch_california_housing(return_X_y=True)\nn_samples, n_features = X_full.shape\n\n# Estimate the score on the entire dataset, with no missing values\nbr_estimator = BayesianRidge()\nscore_full_data = pd.DataFrame(\n cross_val_score(\n br_estimator, X_full, y_full, scoring='neg_mean_squared_error',\n cv=N_SPLITS\n ),\n columns=['Full Data']\n)\n\n# Add a single missing value to each row\nX_missing = X_full.copy()\ny_missing = y_full\nmissing_samples = np.arange(n_samples)\nmissing_features = rng.choice(n_features, n_samples, replace=True)\nX_missing[missing_samples, missing_features] = np.nan\n\n# Estimate the score after imputation (mean and median strategies)\nscore_simple_imputer = pd.DataFrame()\nfor strategy in ('mean', 'median'):\n estimator = make_pipeline(\n SimpleImputer(missing_values=np.nan, strategy=strategy),\n br_estimator\n )\n score_simple_imputer[strategy] = cross_val_score(\n estimator, X_missing, y_missing, scoring='neg_mean_squared_error',\n cv=N_SPLITS\n )\n\n# Estimate the score after iterative imputation of the missing values\n# with different estimators\nestimators = [\n BayesianRidge(),\n DecisionTreeRegressor(max_features='sqrt', random_state=0),\n ExtraTreesRegressor(n_estimators=10, n_jobs=-1, random_state=0),\n KNeighborsRegressor(n_neighbors=15)\n]\nscore_iterative_imputer = pd.DataFrame()\nfor impute_estimator in estimators:\n estimator = make_pipeline(\n IterativeImputer(random_state=0, estimator=impute_estimator),\n br_estimator\n )\n score_iterative_imputer[impute_estimator.__class__.__name__] = \\\n cross_val_score(\n estimator, X_missing, y_missing, scoring='neg_mean_squared_error',\n cv=N_SPLITS\n )\n\nscores = pd.concat(\n [score_full_data, score_simple_imputer, score_iterative_imputer],\n keys=['Original', 'SimpleImputer', 'IterativeImputer'], axis=1\n)\n\n# plot boston results\nfig, ax = plt.subplots(figsize=(13, 6))\nmeans = -scores.mean()\nerrors = scores.std()\nmeans.plot.barh(xerr=errors, ax=ax)\nax.set_title('California Housing Regression with Different Imputation Methods')\nax.set_xlabel('MSE (smaller is better)')\nax.set_yticks(np.arange(means.shape[0]))\nax.set_yticklabels([\" w/ \".join(label) for label in means.index.get_values()])\nplt.tight_layout(pad=1)\nplt.show()"
29+
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\nfrom sklearn.datasets import fetch_california_housing\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.impute import IterativeImputer\nfrom sklearn.linear_model import BayesianRidge\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import ExtraTreesRegressor\nfrom sklearn.neighbors import KNeighborsRegressor\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.model_selection import cross_val_score\n\nN_SPLITS = 5\n\nrng = np.random.RandomState(0)\n\nX_full, y_full = fetch_california_housing(return_X_y=True)\n# ~2k samples is enough for the purpose of the example.\n# Remove the following two lines for a slower run with different error bars.\nX_full = X_full[::10]\ny_full = y_full[::10]\nn_samples, n_features = X_full.shape\n\n# Estimate the score on the entire dataset, with no missing values\nbr_estimator = BayesianRidge()\nscore_full_data = pd.DataFrame(\n cross_val_score(\n br_estimator, X_full, y_full, scoring='neg_mean_squared_error',\n cv=N_SPLITS\n ),\n columns=['Full Data']\n)\n\n# Add a single missing value to each row\nX_missing = X_full.copy()\ny_missing = y_full\nmissing_samples = np.arange(n_samples)\nmissing_features = rng.choice(n_features, n_samples, replace=True)\nX_missing[missing_samples, missing_features] = np.nan\n\n# Estimate the score after imputation (mean and median strategies)\nscore_simple_imputer = pd.DataFrame()\nfor strategy in ('mean', 'median'):\n estimator = make_pipeline(\n SimpleImputer(missing_values=np.nan, strategy=strategy),\n br_estimator\n )\n score_simple_imputer[strategy] = cross_val_score(\n estimator, X_missing, y_missing, scoring='neg_mean_squared_error',\n cv=N_SPLITS\n )\n\n# Estimate the score after iterative imputation of the missing values\n# with different estimators\nestimators = [\n BayesianRidge(),\n DecisionTreeRegressor(max_features='sqrt', random_state=0),\n ExtraTreesRegressor(n_estimators=10, random_state=0),\n KNeighborsRegressor(n_neighbors=15)\n]\nscore_iterative_imputer = pd.DataFrame()\nfor impute_estimator in estimators:\n estimator = make_pipeline(\n IterativeImputer(random_state=0, estimator=impute_estimator),\n br_estimator\n )\n score_iterative_imputer[impute_estimator.__class__.__name__] = \\\n cross_val_score(\n estimator, X_missing, y_missing, scoring='neg_mean_squared_error',\n cv=N_SPLITS\n )\n\nscores = pd.concat(\n [score_full_data, score_simple_imputer, score_iterative_imputer],\n keys=['Original', 'SimpleImputer', 'IterativeImputer'], axis=1\n)\n\n# plot boston results\nfig, ax = plt.subplots(figsize=(13, 6))\nmeans = -scores.mean()\nerrors = scores.std()\nmeans.plot.barh(xerr=errors, ax=ax)\nax.set_title('California Housing Regression with Different Imputation Methods')\nax.set_xlabel('MSE (smaller is better)')\nax.set_yticks(np.arange(means.shape[0]))\nax.set_yticklabels([\" w/ \".join(label) for label in means.index.get_values()])\nplt.tight_layout(pad=1)\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_iterative_imputer_variants_comparison.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
rng = np.random.RandomState(0)
5858

5959
X_full, y_full = fetch_california_housing(return_X_y=True)
60+
# ~2k samples is enough for the purpose of the example.
61+
# Remove the following two lines for a slower run with different error bars.
62+
X_full = X_full[::10]
63+
y_full = y_full[::10]
6064
n_samples, n_features = X_full.shape
6165

6266
# Estimate the score on the entire dataset, with no missing values
@@ -93,7 +97,7 @@
9397
estimators = [
9498
BayesianRidge(),
9599
DecisionTreeRegressor(max_features='sqrt', random_state=0),
96-
ExtraTreesRegressor(n_estimators=10, n_jobs=-1, random_state=0),
100+
ExtraTreesRegressor(n_estimators=10, random_state=0),
97101
KNeighborsRegressor(n_neighbors=15)
98102
]
99103
score_iterative_imputer = pd.DataFrame()

dev/_downloads/scikit-learn-docs.pdf

-1.11 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
632 Bytes
632 Bytes
35 Bytes
35 Bytes

0 commit comments

Comments
 (0)