Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "import pandas as pd\n",
- "#para dividir los datos en train y test\n",
- "from sklearn.model_selection import train_test_split\n",
- "from sklearn.preprocessing import StandardScaler\n",
- "from sklearn.neural_network import MLPClassifier\n",
- "from sklearn.metrics import classification_report,confusion_matrix\n",
- "\n",
- "\n",
- "\n",
- "train = pd.read_csv('data/fashion-mnist_train.csv')\n",
- "\n",
- "#por ahora no lo estamos usando\n",
- "test = pd.read_csv('data/fashion-mnist_test.csv')\n",
- "\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "train.head()\n",
- "\n",
- "train.describe().transpose()\n",
- "\n",
- "X = train.drop('label',axis=1)\n",
- "\n",
- "y = train['label']\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "#divide los datos de entrenamiento y los datos de pruebas\n",
- "X_train, X_test, y_train, y_test = train_test_split(X, y)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [],
- "source": [
- "\n",
- "#normalizacion de datos\n",
- "scaler = StandardScaler()\n",
- "\n",
- "# Fit only to the training data\n",
- "scaler.fit(X_train)\n",
- "\n",
- "StandardScaler(copy=True, with_mean=True, with_std=True)\n",
- "\n",
- "\n",
- "\n",
- "# Now apply the transformations to the data:\n",
- "X_train = scaler.transform(X_train)\n",
- "X_test = scaler.transform(X_test)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "\n",
- "#no esta definida muy inteligentemente la cantidad de capas ni de neuronas\n",
- "#modelo de mi clasificador\n",
- "mlp = MLPClassifier(hidden_layer_sizes=(24,24,24,24,24),max_iter=500)\n",
- "\n",
- "#entrenamiento\n",
- "mlp.fit(X_train,y_train)\n",
- "\n",
- "predictions = mlp.predict(X_test)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[[1226 4 20 54 5 0 193 0 13 0]\n",
- " [ 10 1498 0 19 3 1 4 0 3 0]\n",
- " [ 17 5 1121 15 175 0 122 0 8 0]\n",
- " [ 64 16 20 1311 46 1 38 0 12 0]\n",
- " [ 5 6 112 50 1149 0 138 0 12 0]\n",
- " [ 4 1 1 0 0 1462 4 33 5 18]\n",
- " [ 214 5 127 42 99 0 1029 0 13 1]\n",
- " [ 0 0 0 0 0 58 0 1420 6 51]\n",
- " [ 22 7 9 8 11 16 29 4 1390 1]\n",
- " [ 0 0 0 0 0 20 0 56 1 1337]]\n"
- ]
- }
- ],
- "source": [
- "print(confusion_matrix(y_test,predictions))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- " precision recall f1-score support\n",
- "\n",
- " 0 0.78 0.81 0.80 1515\n",
- " 1 0.97 0.97 0.97 1538\n",
- " 2 0.80 0.77 0.78 1463\n",
- " 3 0.87 0.87 0.87 1508\n",
- " 4 0.77 0.78 0.78 1472\n",
- " 5 0.94 0.96 0.95 1528\n",
- " 6 0.66 0.67 0.67 1530\n",
- " 7 0.94 0.93 0.93 1535\n",
- " 8 0.95 0.93 0.94 1497\n",
- " 9 0.95 0.95 0.95 1414\n",
- "\n",
- "avg / total 0.86 0.86 0.86 15000\n",
- "\n"
- ]
- }
- ],
- "source": [
- "print(classification_report(y_test,predictions))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "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",
- "version": "3.6.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment