Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eblancoh/c635d788f41f21b54767944f3953280b to your computer and use it in GitHub Desktop.
Save eblancoh/c635d788f41f21b54767944f3953280b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Testeando y evaluando el modelo"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"sorted_labels= clf.classes_"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"y_pred = clf.predict(x_test)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import accuracy_score, f1_score\n",
"\n",
"accscore = accuracy_score(y_test, y_pred)\n",
"f1score = f1_score(y_test, y_pred, average = None)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"La precisión conjunta del test dataset se puede obtener a continuación:"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Acc. Score: 93.03 %\n"
]
}
],
"source": [
"print('Acc. Score: ', np.round(accscore*100, 2), '%')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Podemos visualizar la F1-Score para cada clase:"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('STAR', 92.729439809296778)\n",
"('GALAXY', 93.665768194070083)\n",
"('QSO', 90.873786407766985)\n"
]
}
],
"source": [
"for i in range(sorted_labels.__len__()):\n",
" print((inv_class_mapper[sorted_labels[i]], f1score[i]*100))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": true,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment