Skip to content

Commit b461177

Browse files
committed
Pushing the docs to dev/ for branch: master, commit a3ccbe98f2ca8c2ce7b4f01361024099cca7600b
1 parent 66bd0e9 commit b461177

File tree

1,051 files changed

+3289
-3289
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,051 files changed

+3289
-3289
lines changed
21 Bytes
Binary file not shown.
21 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 estimator in estimators:\n estimator = make_pipeline(\n IterativeImputer(random_state=0, estimator=estimator),\n br_estimator\n )\n score_iterative_imputer[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)\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()"
3030
]
3131
}
3232
],

dev/_downloads/plot_iterative_imputer_variants_comparison.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@
9797
KNeighborsRegressor(n_neighbors=15)
9898
]
9999
score_iterative_imputer = pd.DataFrame()
100-
for estimator in estimators:
100+
for impute_estimator in estimators:
101101
estimator = make_pipeline(
102-
IterativeImputer(random_state=0, estimator=estimator),
102+
IterativeImputer(random_state=0, estimator=impute_estimator),
103103
br_estimator
104104
)
105-
score_iterative_imputer[estimator.__class__.__name__] = \
105+
score_iterative_imputer[impute_estimator.__class__.__name__] = \
106106
cross_val_score(
107107
estimator, X_missing, y_missing, scoring='neg_mean_squared_error',
108108
cv=N_SPLITS

dev/_downloads/scikit-learn-docs.pdf

6.22 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
-560 Bytes
-560 Bytes
557 Bytes
557 Bytes

0 commit comments

Comments
 (0)