From 7190cb2c2c7b4cb245ba3f980a5b2ef87378728b Mon Sep 17 00:00:00 2001 From: Benjamin Phillips Date: Tue, 2 Jun 2015 14:51:59 -0400 Subject: [PATCH 1/2] Added ipython notebook Classifying Spam.py --- Classifying Spam.ipynb | 161 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 Classifying Spam.ipynb diff --git a/Classifying Spam.ipynb b/Classifying Spam.ipynb new file mode 100644 index 0000000..04a6bdd --- /dev/null +++ b/Classifying Spam.ipynb @@ -0,0 +1,161 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "from sklearn.naive_bayes import MultinomialNB\n", + "from sklearn.cross_validation import train_test_split\n", + "from sklearn.pipeline import Pipeline" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "data = np.loadtxt(\"spambase/spambase.data\", delimiter=\",\")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "train, test = train_test_split(data, test_size=0.4)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "y_train = train[:,-1]\n", + "x_train = np.delete(train, -1, 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "y_test = test[:,-1]\n", + "x_test = np.delete(test, -1, 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True)" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "spam_filter = MultinomialNB()\n", + "spam_filter.fit(x_train, y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.80326086956521736" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "spam_filter.score(x_train, y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.7957631721890277" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "spam_filter.score(x_test, y_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "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.4.3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From d53fe4b4ca61c552dfc49b33dff0044600fa7a1a Mon Sep 17 00:00:00 2001 From: Benjamin Phillips Date: Tue, 2 Jun 2015 14:54:01 -0400 Subject: [PATCH 2/2] Added data directory to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f00dbf2..55f3aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,5 @@ docs/_build/ # PyBuilder target/ +# Directories +spambase/