Add parser='auto' to fetch_openml(), and normalized_stress=False to MDS(), to avoid warnings
parent
d67673a290
commit
c919a818f5
|
@ -775,7 +775,7 @@
|
||||||
"source": [
|
"source": [
|
||||||
"from sklearn.datasets import fetch_openml\n",
|
"from sklearn.datasets import fetch_openml\n",
|
||||||
"\n",
|
"\n",
|
||||||
"mnist = fetch_openml('mnist_784', as_frame=False)\n",
|
"mnist = fetch_openml('mnist_784', as_frame=False, parser=\"auto\")\n",
|
||||||
"X_train, y_train = mnist.data[:60_000], mnist.target[:60_000]\n",
|
"X_train, y_train = mnist.data[:60_000], mnist.target[:60_000]\n",
|
||||||
"X_test, y_test = mnist.data[60_000:], mnist.target[60_000:]\n",
|
"X_test, y_test = mnist.data[60_000:], mnist.target[60_000:]\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -785,6 +785,13 @@
|
||||||
"d = np.argmax(cumsum >= 0.95) + 1 # d equals 154"
|
"d = np.argmax(cumsum >= 0.95) + 1 # d equals 154"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Note: I added `parser=\"auto\"` when calling `fetch_openml()` to avoid a warning about the fact that the default value for that parameter will change in the future (it's irrelevant in this case). Please see the [documentation](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.fetch_openml.html) for more details."
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 21,
|
"execution_count": 21,
|
||||||
|
@ -1388,6 +1395,13 @@
|
||||||
"plt.show()"
|
"plt.show()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Note: I added `normalized_stress=False` below to avoid a warning about the fact that the default value for that hyperparameter will change in the future. Please see the [documentation](https://scikit-learn.org/stable/modules/generated/sklearn.manifold.MDS.html) for more details."
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 46,
|
"execution_count": 46,
|
||||||
|
@ -1396,7 +1410,7 @@
|
||||||
"source": [
|
"source": [
|
||||||
"from sklearn.manifold import MDS\n",
|
"from sklearn.manifold import MDS\n",
|
||||||
"\n",
|
"\n",
|
||||||
"mds = MDS(n_components=2, random_state=42)\n",
|
"mds = MDS(n_components=2, normalized_stress=False, random_state=42)\n",
|
||||||
"X_reduced_mds = mds.fit_transform(X_swiss)"
|
"X_reduced_mds = mds.fit_transform(X_swiss)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -2418,7 +2432,8 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%time X_mds_reduced = MDS(n_components=2, random_state=42).fit_transform(X_sample)\n",
|
"%time X_mds_reduced = MDS(n_components=2, normalized_stress=False,\n",
|
||||||
|
" random_state=42).fit_transform(X_sample)\n",
|
||||||
"plot_digits(X_mds_reduced, y_sample)\n",
|
"plot_digits(X_mds_reduced, y_sample)\n",
|
||||||
"plt.show()"
|
"plt.show()"
|
||||||
]
|
]
|
||||||
|
@ -2464,8 +2479,10 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"pca_mds = make_pipeline(PCA(n_components=0.95, random_state=42),\n",
|
"pca_mds = make_pipeline(\n",
|
||||||
" MDS(n_components=2, random_state=42))\n",
|
" PCA(n_components=0.95, random_state=42),\n",
|
||||||
|
" MDS(n_components=2, normalized_stress=False, random_state=42)\n",
|
||||||
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"%time X_pca_mds_reduced = pca_mds.fit_transform(X_sample)\n",
|
"%time X_pca_mds_reduced = pca_mds.fit_transform(X_sample)\n",
|
||||||
"plot_digits(X_pca_mds_reduced, y_sample)\n",
|
"plot_digits(X_pca_mds_reduced, y_sample)\n",
|
||||||
|
@ -2552,7 +2569,7 @@
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3",
|
"display_name": "Python 3 (ipykernel)",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
|
@ -2566,7 +2583,7 @@
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.6"
|
"version": "3.10.13"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|
Loading…
Reference in New Issue