{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# **Learning sklearn MLP Classifier**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load in \n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the \"../input/\" directory.\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n", "\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n", "\n", "# Any results you write to the current directory are saved as output."], "metadata": {"_cell_guid": "bee1ddbc-0970-4027-bd08-e8ef316ec151", "_uuid": "15a121383916be596989140c2851cba1a44a0038"}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Taking Input of dataset**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_data=pd.read_csv(\"../input/train.csv\")"], "metadata": {}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Preview of our dataset**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_data.head()"], "metadata": {"scrolled": true}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Converting data to matrix**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_data=train_data.as_matrix()"], "metadata": {}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Preparing data by seperating labels and features**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_label=train_data[:,0]"], "metadata": {"collapsed": true}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_label"], "metadata": {}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_features=train_data[:,1:]"], "metadata": {"collapsed": true}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["print(train_features)\n", "np.shape(train_features)\n"], "metadata": {}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["from sklearn.neural_network import MLPClassifier"], "metadata": {"collapsed": true}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Taking part of the dataset to make Test set**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["test_label=train_label[30001:]"], "metadata": {"collapsed": true}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["test_features=train_features[30001:,:]"], "metadata": {"collapsed": true}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_label=train_label[:30000]"], "metadata": {"collapsed": true}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["train_features=train_features[:30000,:]\n", "## decreasing the values to get them between 0 and 1\n", "train_features=train_features/255"], "metadata": {"collapsed": true}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Initializing our MLP Classifier**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["clf=MLPClassifier(solver='adam',hidden_layer_sizes=350,alpha=1e-04)"], "metadata": {"collapsed": true}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["clf.fit(train_features,train_label)"], "metadata": {}}, {"cell_type": "markdown", "metadata": {}, "source": ["# **Getting Score on our Test set**"]}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": ["clf.score(test_features,test_label)"], "metadata": {}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": [], "metadata": {"collapsed": true}}], "metadata": {"language_info": {"mimetype": "text/x-python", "file_extension": ".py", "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "version": "3.6.4", "codemirror_mode": {"version": 3, "name": "ipython"}, "name": "python"}, "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}}, "nbformat_minor": 1, "nbformat": 4}