Guest User

Untitled

a guest
Nov 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 9,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import pandas as pd\n",
  10. "#para dividir los datos en train y test\n",
  11. "from sklearn.model_selection import train_test_split\n",
  12. "from sklearn.preprocessing import StandardScaler\n",
  13. "from sklearn.neural_network import MLPClassifier\n",
  14. "from sklearn.metrics import classification_report,confusion_matrix\n",
  15. "\n",
  16. "\n",
  17. "\n",
  18. "train = pd.read_csv('data/fashion-mnist_train.csv')\n",
  19. "\n",
  20. "#por ahora no lo estamos usando\n",
  21. "test = pd.read_csv('data/fashion-mnist_test.csv')\n",
  22. "\n",
  23. "\n"
  24. ]
  25. },
  26. {
  27. "cell_type": "code",
  28. "execution_count": 10,
  29. "metadata": {
  30. "collapsed": true
  31. },
  32. "outputs": [],
  33. "source": [
  34. "train.head()\n",
  35. "\n",
  36. "train.describe().transpose()\n",
  37. "\n",
  38. "X = train.drop('label',axis=1)\n",
  39. "\n",
  40. "y = train['label']\n"
  41. ]
  42. },
  43. {
  44. "cell_type": "code",
  45. "execution_count": 11,
  46. "metadata": {
  47. "collapsed": true
  48. },
  49. "outputs": [],
  50. "source": [
  51. "#divide los datos de entrenamiento y los datos de pruebas\n",
  52. "X_train, X_test, y_train, y_test = train_test_split(X, y)\n"
  53. ]
  54. },
  55. {
  56. "cell_type": "code",
  57. "execution_count": 14,
  58. "metadata": {},
  59. "outputs": [],
  60. "source": [
  61. "\n",
  62. "#normalizacion de datos\n",
  63. "scaler = StandardScaler()\n",
  64. "\n",
  65. "# Fit only to the training data\n",
  66. "scaler.fit(X_train)\n",
  67. "\n",
  68. "StandardScaler(copy=True, with_mean=True, with_std=True)\n",
  69. "\n",
  70. "\n",
  71. "\n",
  72. "# Now apply the transformations to the data:\n",
  73. "X_train = scaler.transform(X_train)\n",
  74. "X_test = scaler.transform(X_test)\n"
  75. ]
  76. },
  77. {
  78. "cell_type": "code",
  79. "execution_count": 15,
  80. "metadata": {
  81. "collapsed": true
  82. },
  83. "outputs": [],
  84. "source": [
  85. "\n",
  86. "#no esta definida muy inteligentemente la cantidad de capas ni de neuronas\n",
  87. "#modelo de mi clasificador\n",
  88. "mlp = MLPClassifier(hidden_layer_sizes=(24,24,24,24,24),max_iter=500)\n",
  89. "\n",
  90. "#entrenamiento\n",
  91. "mlp.fit(X_train,y_train)\n",
  92. "\n",
  93. "predictions = mlp.predict(X_test)\n"
  94. ]
  95. },
  96. {
  97. "cell_type": "code",
  98. "execution_count": 16,
  99. "metadata": {},
  100. "outputs": [
  101. {
  102. "name": "stdout",
  103. "output_type": "stream",
  104. "text": [
  105. "[[1226 4 20 54 5 0 193 0 13 0]\n",
  106. " [ 10 1498 0 19 3 1 4 0 3 0]\n",
  107. " [ 17 5 1121 15 175 0 122 0 8 0]\n",
  108. " [ 64 16 20 1311 46 1 38 0 12 0]\n",
  109. " [ 5 6 112 50 1149 0 138 0 12 0]\n",
  110. " [ 4 1 1 0 0 1462 4 33 5 18]\n",
  111. " [ 214 5 127 42 99 0 1029 0 13 1]\n",
  112. " [ 0 0 0 0 0 58 0 1420 6 51]\n",
  113. " [ 22 7 9 8 11 16 29 4 1390 1]\n",
  114. " [ 0 0 0 0 0 20 0 56 1 1337]]\n"
  115. ]
  116. }
  117. ],
  118. "source": [
  119. "print(confusion_matrix(y_test,predictions))"
  120. ]
  121. },
  122. {
  123. "cell_type": "code",
  124. "execution_count": 17,
  125. "metadata": {},
  126. "outputs": [
  127. {
  128. "name": "stdout",
  129. "output_type": "stream",
  130. "text": [
  131. " precision recall f1-score support\n",
  132. "\n",
  133. " 0 0.78 0.81 0.80 1515\n",
  134. " 1 0.97 0.97 0.97 1538\n",
  135. " 2 0.80 0.77 0.78 1463\n",
  136. " 3 0.87 0.87 0.87 1508\n",
  137. " 4 0.77 0.78 0.78 1472\n",
  138. " 5 0.94 0.96 0.95 1528\n",
  139. " 6 0.66 0.67 0.67 1530\n",
  140. " 7 0.94 0.93 0.93 1535\n",
  141. " 8 0.95 0.93 0.94 1497\n",
  142. " 9 0.95 0.95 0.95 1414\n",
  143. "\n",
  144. "avg / total 0.86 0.86 0.86 15000\n",
  145. "\n"
  146. ]
  147. }
  148. ],
  149. "source": [
  150. "print(classification_report(y_test,predictions))"
  151. ]
  152. },
  153. {
  154. "cell_type": "code",
  155. "execution_count": null,
  156. "metadata": {
  157. "collapsed": true
  158. },
  159. "outputs": [],
  160. "source": []
  161. }
  162. ],
  163. "metadata": {
  164. "kernelspec": {
  165. "display_name": "Python 3",
  166. "language": "python",
  167. "name": "python3"
  168. },
  169. "language_info": {
  170. "codemirror_mode": {
  171. "name": "ipython",
  172. "version": 3
  173. },
  174. "file_extension": ".py",
  175. "mimetype": "text/x-python",
  176. "name": "python",
  177. "nbconvert_exporter": "python",
  178. "pygments_lexer": "ipython3",
  179. "version": "3.6.3"
  180. }
  181. },
  182. "nbformat": 4,
  183. "nbformat_minor": 2
  184. }
Add Comment
Please, Sign In to add comment