Answer To: ISYE 6740 Homework 7 (Last Homework) Total 100 points. As usual, please submit a report with...
Ximi answered on Apr 13 2021
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Question 1.1\n",
"df = pd.read_csv('spambase/spambase.data', names=list(range(57)) + ['class'])\n",
"df.head()\n",
"df = df.fillna(0)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total count 4601\n",
"spam count 1813\n",
"regular count 2788\n"
]
}
],
"source": [
"print (\"total count\", df.shape[0])\n",
"print (\"spam count\", df[df['class'] == 1].shape[0])\n",
"print (\"regular count\", df[df['class']==0].shape[0])"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split, cross_val_score, TimeSeriesSplit\n",
"from sklearn.tree import DecisionTreeClassifier"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',\n",
" max_depth=None, max_features=None, max_leaf_nodes=None,\n",
" min_impurity_decrease=0.0, min_impurity_split=None,\n",
" min_samples_leaf=1, min_samples_split=2,\n",
" min_weight_fraction_leaf=0.0, presort='deprecated',\n",
" random_state=None, splitter='best')"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Question 1.2\n",
"X = df.iloc[:, 1:-1]\n",
"y = df.iloc[:, -1]\n",
"clf = DecisionTreeClassifier()\n",
"clf.fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import plot_tree\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"image/png":...