Newer
Older
]
},
{
"cell_type": "code",
"source": [
"import seaborn as sns\n",
"sns.set(style=\"ticks\")\n",
"\n",
"for_plot = df.copy()\n",
"\n",
"def transform_label(class_):\n",
" return data.target_names[class_]\n",
"\n",
"# seaborn does not work here if we use numeric values in the class\n",
"# column, or strings which represent numbers. To fix this we\n",
"# create textual class labels\n",
"for_plot[\"class\"] = for_plot[\"class\"].apply(transform_label)\n",
"sns.pairplot(for_plot, hue=\"class\", diag_kind=\"hist\");"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"solution"
]
},
"features = df.iloc[:, :-1]\n",
"labels = df.iloc[:, -1]\n",
"classifier.fit(features, labels)\n",
"predicted_labels = classifier.predict(features)\n",
"\n",
"print(len(labels), \"examples\")\n",
"print(sum(predicted_labels == labels), \"labeled correctly\")"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Copyright (C) 2019-2021 ETH Zurich, SIS ID"
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "288px"
},
"toc_section_display": true,
"toc_window_display": true