1750 lines
67 KiB
Plaintext
1750 lines
67 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c:\\Users\\macty\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
|
" from .autonotebook import tqdm as notebook_tqdm\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import sklearn.model_selection\n",
|
|
"from datasets import load_dataset"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Found cached dataset wine (C:/Users/macty/.cache/huggingface/datasets/mstz___wine/wine/1.0.0/7c3844cac7ac7a22d5fbbaf60fc1d4e9c9deb1b9b9c4dbae6a7b1a962dbc96d8)\n",
|
|
"100%|██████████| 1/1 [00:00<00:00, 49.24it/s]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"dataset = load_dataset(\"mstz/wine\", \"wine\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Dataset({\n",
|
|
" features: ['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar', 'chlorides', 'free_sulfur_dioxide', 'total_sulfur_dioxide', 'density', 'pH', 'sulphates', 'alcohol', 'quality', 'is_red'],\n",
|
|
" num_rows: 6497\n",
|
|
"})"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"dataset[\"train\"]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"wine_dataset = pd.DataFrame(dataset[\"train\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>fixed_acidity</th>\n",
|
|
" <th>volatile_acidity</th>\n",
|
|
" <th>citric_acid</th>\n",
|
|
" <th>residual_sugar</th>\n",
|
|
" <th>chlorides</th>\n",
|
|
" <th>free_sulfur_dioxide</th>\n",
|
|
" <th>total_sulfur_dioxide</th>\n",
|
|
" <th>density</th>\n",
|
|
" <th>pH</th>\n",
|
|
" <th>sulphates</th>\n",
|
|
" <th>alcohol</th>\n",
|
|
" <th>quality</th>\n",
|
|
" <th>is_red</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>7.4</td>\n",
|
|
" <td>0.70</td>\n",
|
|
" <td>0.00</td>\n",
|
|
" <td>1.9</td>\n",
|
|
" <td>0.076</td>\n",
|
|
" <td>11.0</td>\n",
|
|
" <td>34.0</td>\n",
|
|
" <td>0.9978</td>\n",
|
|
" <td>3.51</td>\n",
|
|
" <td>0.56</td>\n",
|
|
" <td>9.4</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>7.8</td>\n",
|
|
" <td>0.88</td>\n",
|
|
" <td>0.00</td>\n",
|
|
" <td>2.6</td>\n",
|
|
" <td>0.098</td>\n",
|
|
" <td>25.0</td>\n",
|
|
" <td>67.0</td>\n",
|
|
" <td>0.9968</td>\n",
|
|
" <td>3.20</td>\n",
|
|
" <td>0.68</td>\n",
|
|
" <td>9.8</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>7.8</td>\n",
|
|
" <td>0.76</td>\n",
|
|
" <td>0.04</td>\n",
|
|
" <td>2.3</td>\n",
|
|
" <td>0.092</td>\n",
|
|
" <td>15.0</td>\n",
|
|
" <td>54.0</td>\n",
|
|
" <td>0.9970</td>\n",
|
|
" <td>3.26</td>\n",
|
|
" <td>0.65</td>\n",
|
|
" <td>9.8</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>11.2</td>\n",
|
|
" <td>0.28</td>\n",
|
|
" <td>0.56</td>\n",
|
|
" <td>1.9</td>\n",
|
|
" <td>0.075</td>\n",
|
|
" <td>17.0</td>\n",
|
|
" <td>60.0</td>\n",
|
|
" <td>0.9980</td>\n",
|
|
" <td>3.16</td>\n",
|
|
" <td>0.58</td>\n",
|
|
" <td>9.8</td>\n",
|
|
" <td>6</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>7.4</td>\n",
|
|
" <td>0.70</td>\n",
|
|
" <td>0.00</td>\n",
|
|
" <td>1.9</td>\n",
|
|
" <td>0.076</td>\n",
|
|
" <td>11.0</td>\n",
|
|
" <td>34.0</td>\n",
|
|
" <td>0.9978</td>\n",
|
|
" <td>3.51</td>\n",
|
|
" <td>0.56</td>\n",
|
|
" <td>9.4</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" fixed_acidity volatile_acidity citric_acid residual_sugar chlorides \\\n",
|
|
"0 7.4 0.70 0.00 1.9 0.076 \n",
|
|
"1 7.8 0.88 0.00 2.6 0.098 \n",
|
|
"2 7.8 0.76 0.04 2.3 0.092 \n",
|
|
"3 11.2 0.28 0.56 1.9 0.075 \n",
|
|
"4 7.4 0.70 0.00 1.9 0.076 \n",
|
|
"\n",
|
|
" free_sulfur_dioxide total_sulfur_dioxide density pH sulphates \\\n",
|
|
"0 11.0 34.0 0.9978 3.51 0.56 \n",
|
|
"1 25.0 67.0 0.9968 3.20 0.68 \n",
|
|
"2 15.0 54.0 0.9970 3.26 0.65 \n",
|
|
"3 17.0 60.0 0.9980 3.16 0.58 \n",
|
|
"4 11.0 34.0 0.9978 3.51 0.56 \n",
|
|
"\n",
|
|
" alcohol quality is_red \n",
|
|
"0 9.4 5 0 \n",
|
|
"1 9.8 5 0 \n",
|
|
"2 9.8 5 0 \n",
|
|
"3 9.8 6 0 \n",
|
|
"4 9.4 5 0 "
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_dataset.head()# podgląd danych"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>fixed_acidity</th>\n",
|
|
" <th>volatile_acidity</th>\n",
|
|
" <th>citric_acid</th>\n",
|
|
" <th>residual_sugar</th>\n",
|
|
" <th>chlorides</th>\n",
|
|
" <th>free_sulfur_dioxide</th>\n",
|
|
" <th>total_sulfur_dioxide</th>\n",
|
|
" <th>density</th>\n",
|
|
" <th>pH</th>\n",
|
|
" <th>sulphates</th>\n",
|
|
" <th>alcohol</th>\n",
|
|
" <th>quality</th>\n",
|
|
" <th>is_red</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>7.215307</td>\n",
|
|
" <td>0.339666</td>\n",
|
|
" <td>0.318633</td>\n",
|
|
" <td>5.443235</td>\n",
|
|
" <td>0.056034</td>\n",
|
|
" <td>30.525319</td>\n",
|
|
" <td>115.744574</td>\n",
|
|
" <td>0.994697</td>\n",
|
|
" <td>3.218501</td>\n",
|
|
" <td>0.531268</td>\n",
|
|
" <td>10.491801</td>\n",
|
|
" <td>5.818378</td>\n",
|
|
" <td>0.753886</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>1.296434</td>\n",
|
|
" <td>0.164636</td>\n",
|
|
" <td>0.145318</td>\n",
|
|
" <td>4.757804</td>\n",
|
|
" <td>0.035034</td>\n",
|
|
" <td>17.749400</td>\n",
|
|
" <td>56.521855</td>\n",
|
|
" <td>0.002999</td>\n",
|
|
" <td>0.160787</td>\n",
|
|
" <td>0.148806</td>\n",
|
|
" <td>1.192712</td>\n",
|
|
" <td>0.873255</td>\n",
|
|
" <td>0.430779</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>3.800000</td>\n",
|
|
" <td>0.080000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.600000</td>\n",
|
|
" <td>0.009000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>6.000000</td>\n",
|
|
" <td>0.987110</td>\n",
|
|
" <td>2.720000</td>\n",
|
|
" <td>0.220000</td>\n",
|
|
" <td>8.000000</td>\n",
|
|
" <td>3.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>6.400000</td>\n",
|
|
" <td>0.230000</td>\n",
|
|
" <td>0.250000</td>\n",
|
|
" <td>1.800000</td>\n",
|
|
" <td>0.038000</td>\n",
|
|
" <td>17.000000</td>\n",
|
|
" <td>77.000000</td>\n",
|
|
" <td>0.992340</td>\n",
|
|
" <td>3.110000</td>\n",
|
|
" <td>0.430000</td>\n",
|
|
" <td>9.500000</td>\n",
|
|
" <td>5.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>7.000000</td>\n",
|
|
" <td>0.290000</td>\n",
|
|
" <td>0.310000</td>\n",
|
|
" <td>3.000000</td>\n",
|
|
" <td>0.047000</td>\n",
|
|
" <td>29.000000</td>\n",
|
|
" <td>118.000000</td>\n",
|
|
" <td>0.994890</td>\n",
|
|
" <td>3.210000</td>\n",
|
|
" <td>0.510000</td>\n",
|
|
" <td>10.300000</td>\n",
|
|
" <td>6.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>7.700000</td>\n",
|
|
" <td>0.400000</td>\n",
|
|
" <td>0.390000</td>\n",
|
|
" <td>8.100000</td>\n",
|
|
" <td>0.065000</td>\n",
|
|
" <td>41.000000</td>\n",
|
|
" <td>156.000000</td>\n",
|
|
" <td>0.996990</td>\n",
|
|
" <td>3.320000</td>\n",
|
|
" <td>0.600000</td>\n",
|
|
" <td>11.300000</td>\n",
|
|
" <td>6.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>15.900000</td>\n",
|
|
" <td>1.580000</td>\n",
|
|
" <td>1.660000</td>\n",
|
|
" <td>65.800000</td>\n",
|
|
" <td>0.611000</td>\n",
|
|
" <td>289.000000</td>\n",
|
|
" <td>440.000000</td>\n",
|
|
" <td>1.038980</td>\n",
|
|
" <td>4.010000</td>\n",
|
|
" <td>2.000000</td>\n",
|
|
" <td>14.900000</td>\n",
|
|
" <td>9.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" fixed_acidity volatile_acidity citric_acid residual_sugar \\\n",
|
|
"count 6497.000000 6497.000000 6497.000000 6497.000000 \n",
|
|
"mean 7.215307 0.339666 0.318633 5.443235 \n",
|
|
"std 1.296434 0.164636 0.145318 4.757804 \n",
|
|
"min 3.800000 0.080000 0.000000 0.600000 \n",
|
|
"25% 6.400000 0.230000 0.250000 1.800000 \n",
|
|
"50% 7.000000 0.290000 0.310000 3.000000 \n",
|
|
"75% 7.700000 0.400000 0.390000 8.100000 \n",
|
|
"max 15.900000 1.580000 1.660000 65.800000 \n",
|
|
"\n",
|
|
" chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n",
|
|
"count 6497.000000 6497.000000 6497.000000 6497.000000 \n",
|
|
"mean 0.056034 30.525319 115.744574 0.994697 \n",
|
|
"std 0.035034 17.749400 56.521855 0.002999 \n",
|
|
"min 0.009000 1.000000 6.000000 0.987110 \n",
|
|
"25% 0.038000 17.000000 77.000000 0.992340 \n",
|
|
"50% 0.047000 29.000000 118.000000 0.994890 \n",
|
|
"75% 0.065000 41.000000 156.000000 0.996990 \n",
|
|
"max 0.611000 289.000000 440.000000 1.038980 \n",
|
|
"\n",
|
|
" pH sulphates alcohol quality is_red \n",
|
|
"count 6497.000000 6497.000000 6497.000000 6497.000000 6497.000000 \n",
|
|
"mean 3.218501 0.531268 10.491801 5.818378 0.753886 \n",
|
|
"std 0.160787 0.148806 1.192712 0.873255 0.430779 \n",
|
|
"min 2.720000 0.220000 8.000000 3.000000 0.000000 \n",
|
|
"25% 3.110000 0.430000 9.500000 5.000000 1.000000 \n",
|
|
"50% 3.210000 0.510000 10.300000 6.000000 1.000000 \n",
|
|
"75% 3.320000 0.600000 11.300000 6.000000 1.000000 \n",
|
|
"max 4.010000 2.000000 14.900000 9.000000 1.000000 "
|
|
]
|
|
},
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_dataset.describe(include='all')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<Axes: >"
|
|
]
|
|
},
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
},
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGYCAYAAABc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AAAMAcAgYAAJhDwAAAAHMIGAAAYA4BAwAAzCFgAACAOQQMAAAwh4ABAADmEDAAAMAcAgYAAJhDwAAAAHMIGAAAYM4VBcyaNWuUkJCggoICZ9/p06eVn5+vESNGaOjQocrLy1NTU1PM++rr6xUIBDR48GClpKRo2bJlOnPmTMycPXv2aPLkyXK5XBo3bpzKysquZKkAAKAPueyAOXDggH7zm99o4sSJMfsLCwu1fft2bdu2TdXV1WpsbNSsWbOc8c7OTgUCAbW3t2vv3r3avHmzysrKVFJS4sw5duyYAoGApk2bptraWhUUFGjRokWqqKi43OUCAIA+5LIC5uTJk5o7d65eeeUV3XDDDc7+cDis3/3ud3r++ed19913Kzs7W7///e+1d+9evf/++5Kkd955Rx9//LH++Mc/6vbbb9eMGTP0y1/+Ui+99JLa29slSaWlpcrIyNBzzz2n8ePHa+nSpZo9e7bWrVvXA6cMAACsu6yAyc/PVyAQUG5ubsz+mpoadXR0xOzPzMzU2LFjFQwGJUnBYFATJkxQamqqM8fv9ysSiejw4cPOnP89tt/vd45xIW1tbYpEIjEbAADom/p39w2vv/66PvjgAx04cOC8sVAopKSkJCUnJ8fsT01NVSgUcuacGy9d411jF5sTiUR06tQpDRo06LyvvXr1aj399NPdPR0AAGBQt67ANDQ06Be/+IVee+01DRw48Gqt6bIUFxcrHA47W0NDQ7yXBAAArpJuBUxNTY2am5s1efJk9e/fX/3791d1dbU2bNig/v37KzU1Ve3t7WppaYl5X1NTk7xeryTJ6/We96mkrtdfN8ftdl/w6oskuVwuud3umA0AAPRN3QqYe+65R3V1daqtrXW2O+64Q3PnznX+PGDAAFVVVTnvOXr0qOrr6+Xz+SRJPp9PdXV1am5uduZUVlbK7XYrKyvLmXPuMbrmdB0DAABc37p1D8ywYcN02223xewbMmSIRowY4exfuHChioqKNHz4cLndbj322GPy+XzKycmRJE2fPl1ZWVmaN2+e1q5dq1AopJUrVyo/P18ul0uStHjxYr344otavny5FixYoN27d2vr1q0qLy/viXMGAADGdfsm3q+zbt069evXT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BjvZaIX4Dkw6HM+/PBDTZ48WZ2dnfFeCoBuysnJ0aRJk1RaWnreP8QbjUa1ePFiffTRRwoGg3FaIXoLfoUEc95+++2Ljn/66afXaCUAetqHH36osrKy8+JFkhISElRYWKhvfvObcVgZehsCBubcf//9SkhI0MUuHl7oLz8AvZ/X69X+/fuVmZl5wfH9+/fzT8pAEgEDg0aPHq2NGzfqvvvuu+B4bW2tsrOzr/GqAPSExx9/XI8++qhqamp0zz33OLHS1NSkqqoqvfLKK3r22WfjvEr0BgQMzMnOzlZNTc1XBszXXZ0B0Hvl5+dr5MiRWrdunTZu3Ojcy5aYmKjs7GyVlZXpJz/5SZxXid6Am3hhzl/+8he1trbq3nvvveB4a2urDh48qO9973vXeGUAelJHR4e++OILSdLIkSM1YMCAOK8IvQkBAwAAzOE5MAAAwBwCBgAAmEPAAAAAcwgYAABgDgEDAADMIWAAAIA5BAwAADCHgAEAAOb8P8GPNhrybRfSAAAAAElFTkSuQmCC",
|
|
"text/plain": [
|
|
"<Figure size 640x480 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_dataset[\"is_red\"].value_counts().plot(kind=\"bar\")\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1.2964337577998153"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_dataset[\"fixed_acidity\"].std()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(array([], dtype=int64), array([], dtype=int64))"
|
|
]
|
|
},
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"np.where(pd.isnull(wine_dataset))## sprawdzanie czy istnieją puste wartości"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"for column in wine_dataset.columns:\n",
|
|
" wine_dataset[column] = wine_dataset[column] / wine_dataset[column].abs().max() # normalizacja"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>fixed_acidity</th>\n",
|
|
" <th>volatile_acidity</th>\n",
|
|
" <th>citric_acid</th>\n",
|
|
" <th>residual_sugar</th>\n",
|
|
" <th>chlorides</th>\n",
|
|
" <th>free_sulfur_dioxide</th>\n",
|
|
" <th>total_sulfur_dioxide</th>\n",
|
|
" <th>density</th>\n",
|
|
" <th>pH</th>\n",
|
|
" <th>sulphates</th>\n",
|
|
" <th>alcohol</th>\n",
|
|
" <th>quality</th>\n",
|
|
" <th>is_red</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" <td>6497.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>0.453793</td>\n",
|
|
" <td>0.214978</td>\n",
|
|
" <td>0.191948</td>\n",
|
|
" <td>0.082724</td>\n",
|
|
" <td>0.091708</td>\n",
|
|
" <td>0.105624</td>\n",
|
|
" <td>0.263056</td>\n",
|
|
" <td>0.957378</td>\n",
|
|
" <td>0.802619</td>\n",
|
|
" <td>0.265634</td>\n",
|
|
" <td>0.704148</td>\n",
|
|
" <td>0.646486</td>\n",
|
|
" <td>0.753886</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>0.081537</td>\n",
|
|
" <td>0.104200</td>\n",
|
|
" <td>0.087541</td>\n",
|
|
" <td>0.072307</td>\n",
|
|
" <td>0.057338</td>\n",
|
|
" <td>0.061417</td>\n",
|
|
" <td>0.128459</td>\n",
|
|
" <td>0.002886</td>\n",
|
|
" <td>0.040097</td>\n",
|
|
" <td>0.074403</td>\n",
|
|
" <td>0.080048</td>\n",
|
|
" <td>0.097028</td>\n",
|
|
" <td>0.430779</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>0.238994</td>\n",
|
|
" <td>0.050633</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.009119</td>\n",
|
|
" <td>0.014730</td>\n",
|
|
" <td>0.003460</td>\n",
|
|
" <td>0.013636</td>\n",
|
|
" <td>0.950076</td>\n",
|
|
" <td>0.678304</td>\n",
|
|
" <td>0.110000</td>\n",
|
|
" <td>0.536913</td>\n",
|
|
" <td>0.333333</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>0.402516</td>\n",
|
|
" <td>0.145570</td>\n",
|
|
" <td>0.150602</td>\n",
|
|
" <td>0.027356</td>\n",
|
|
" <td>0.062193</td>\n",
|
|
" <td>0.058824</td>\n",
|
|
" <td>0.175000</td>\n",
|
|
" <td>0.955110</td>\n",
|
|
" <td>0.775561</td>\n",
|
|
" <td>0.215000</td>\n",
|
|
" <td>0.637584</td>\n",
|
|
" <td>0.555556</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>0.440252</td>\n",
|
|
" <td>0.183544</td>\n",
|
|
" <td>0.186747</td>\n",
|
|
" <td>0.045593</td>\n",
|
|
" <td>0.076923</td>\n",
|
|
" <td>0.100346</td>\n",
|
|
" <td>0.268182</td>\n",
|
|
" <td>0.957564</td>\n",
|
|
" <td>0.800499</td>\n",
|
|
" <td>0.255000</td>\n",
|
|
" <td>0.691275</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>0.484277</td>\n",
|
|
" <td>0.253165</td>\n",
|
|
" <td>0.234940</td>\n",
|
|
" <td>0.123100</td>\n",
|
|
" <td>0.106383</td>\n",
|
|
" <td>0.141869</td>\n",
|
|
" <td>0.354545</td>\n",
|
|
" <td>0.959585</td>\n",
|
|
" <td>0.827930</td>\n",
|
|
" <td>0.300000</td>\n",
|
|
" <td>0.758389</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" fixed_acidity volatile_acidity citric_acid residual_sugar \\\n",
|
|
"count 6497.000000 6497.000000 6497.000000 6497.000000 \n",
|
|
"mean 0.453793 0.214978 0.191948 0.082724 \n",
|
|
"std 0.081537 0.104200 0.087541 0.072307 \n",
|
|
"min 0.238994 0.050633 0.000000 0.009119 \n",
|
|
"25% 0.402516 0.145570 0.150602 0.027356 \n",
|
|
"50% 0.440252 0.183544 0.186747 0.045593 \n",
|
|
"75% 0.484277 0.253165 0.234940 0.123100 \n",
|
|
"max 1.000000 1.000000 1.000000 1.000000 \n",
|
|
"\n",
|
|
" chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n",
|
|
"count 6497.000000 6497.000000 6497.000000 6497.000000 \n",
|
|
"mean 0.091708 0.105624 0.263056 0.957378 \n",
|
|
"std 0.057338 0.061417 0.128459 0.002886 \n",
|
|
"min 0.014730 0.003460 0.013636 0.950076 \n",
|
|
"25% 0.062193 0.058824 0.175000 0.955110 \n",
|
|
"50% 0.076923 0.100346 0.268182 0.957564 \n",
|
|
"75% 0.106383 0.141869 0.354545 0.959585 \n",
|
|
"max 1.000000 1.000000 1.000000 1.000000 \n",
|
|
"\n",
|
|
" pH sulphates alcohol quality is_red \n",
|
|
"count 6497.000000 6497.000000 6497.000000 6497.000000 6497.000000 \n",
|
|
"mean 0.802619 0.265634 0.704148 0.646486 0.753886 \n",
|
|
"std 0.040097 0.074403 0.080048 0.097028 0.430779 \n",
|
|
"min 0.678304 0.110000 0.536913 0.333333 0.000000 \n",
|
|
"25% 0.775561 0.215000 0.637584 0.555556 1.000000 \n",
|
|
"50% 0.800499 0.255000 0.691275 0.666667 1.000000 \n",
|
|
"75% 0.827930 0.300000 0.758389 0.666667 1.000000 \n",
|
|
"max 1.000000 1.000000 1.000000 1.000000 1.000000 "
|
|
]
|
|
},
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_dataset.describe(include='all') # sprawdzanie wartości po znormalizowaniu"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"652 1.000000\n",
|
|
"442 0.981132\n",
|
|
"557 0.981132\n",
|
|
"554 0.974843\n",
|
|
"555 0.974843\n",
|
|
"243 0.943396\n",
|
|
"244 0.943396\n",
|
|
"544 0.899371\n",
|
|
"3125 0.893082\n",
|
|
"374 0.880503\n",
|
|
"Name: fixed_acidity, dtype: float64"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_dataset[\"fixed_acidity\"].nlargest(10) #sprawdza czy najwyższe wartości mają sens"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1.0 4408\n",
|
|
"0.0 1439\n",
|
|
"Name: is_red, dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"from sklearn.model_selection import train_test_split\n",
|
|
"wine_train, wine_test = sklearn.model_selection.train_test_split(wine_dataset, test_size=0.1, random_state=1, stratify=wine_dataset[\"is_red\"])\n",
|
|
"wine_train[\"is_red\"].value_counts() \n",
|
|
"# podzielenie na train i test"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1.0 490\n",
|
|
"0.0 160\n",
|
|
"Name: is_red, dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_test[\"is_red\"].value_counts()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"wine_test, wine_val = sklearn.model_selection.train_test_split(wine_test, test_size=0.5, random_state=1, stratify=wine_test[\"is_red\"]) # podzielenie na test i validation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1.0 245\n",
|
|
"0.0 80\n",
|
|
"Name: is_red, dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_test[\"is_red\"].value_counts()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1.0 245\n",
|
|
"0.0 80\n",
|
|
"Name: is_red, dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_val[\"is_red\"].value_counts()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import seaborn as sns\n",
|
|
"sns.set_theme()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"13"
|
|
]
|
|
},
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"len(wine_dataset.columns)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#sns.pairplot(data=wine_dataset, hue=\"is_red\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>fixed_acidity</th>\n",
|
|
" <th>volatile_acidity</th>\n",
|
|
" <th>citric_acid</th>\n",
|
|
" <th>residual_sugar</th>\n",
|
|
" <th>chlorides</th>\n",
|
|
" <th>free_sulfur_dioxide</th>\n",
|
|
" <th>total_sulfur_dioxide</th>\n",
|
|
" <th>density</th>\n",
|
|
" <th>pH</th>\n",
|
|
" <th>sulphates</th>\n",
|
|
" <th>alcohol</th>\n",
|
|
" <th>quality</th>\n",
|
|
" <th>is_red</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>0.448244</td>\n",
|
|
" <td>0.217069</td>\n",
|
|
" <td>0.180630</td>\n",
|
|
" <td>0.078990</td>\n",
|
|
" <td>0.088742</td>\n",
|
|
" <td>0.103024</td>\n",
|
|
" <td>0.257462</td>\n",
|
|
" <td>0.957255</td>\n",
|
|
" <td>0.803553</td>\n",
|
|
" <td>0.263877</td>\n",
|
|
" <td>0.703930</td>\n",
|
|
" <td>0.646154</td>\n",
|
|
" <td>0.753846</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>0.074301</td>\n",
|
|
" <td>0.107627</td>\n",
|
|
" <td>0.078046</td>\n",
|
|
" <td>0.070045</td>\n",
|
|
" <td>0.051400</td>\n",
|
|
" <td>0.054750</td>\n",
|
|
" <td>0.125165</td>\n",
|
|
" <td>0.002786</td>\n",
|
|
" <td>0.039808</td>\n",
|
|
" <td>0.072275</td>\n",
|
|
" <td>0.078704</td>\n",
|
|
" <td>0.095014</td>\n",
|
|
" <td>0.431433</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>0.314465</td>\n",
|
|
" <td>0.063291</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.012158</td>\n",
|
|
" <td>0.031097</td>\n",
|
|
" <td>0.010381</td>\n",
|
|
" <td>0.020455</td>\n",
|
|
" <td>0.951116</td>\n",
|
|
" <td>0.713217</td>\n",
|
|
" <td>0.130000</td>\n",
|
|
" <td>0.570470</td>\n",
|
|
" <td>0.333333</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>0.402516</td>\n",
|
|
" <td>0.145570</td>\n",
|
|
" <td>0.144578</td>\n",
|
|
" <td>0.027356</td>\n",
|
|
" <td>0.060556</td>\n",
|
|
" <td>0.058824</td>\n",
|
|
" <td>0.168182</td>\n",
|
|
" <td>0.955168</td>\n",
|
|
" <td>0.775561</td>\n",
|
|
" <td>0.210000</td>\n",
|
|
" <td>0.637584</td>\n",
|
|
" <td>0.555556</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>0.433962</td>\n",
|
|
" <td>0.177215</td>\n",
|
|
" <td>0.180723</td>\n",
|
|
" <td>0.042553</td>\n",
|
|
" <td>0.078560</td>\n",
|
|
" <td>0.100346</td>\n",
|
|
" <td>0.261364</td>\n",
|
|
" <td>0.957478</td>\n",
|
|
" <td>0.800499</td>\n",
|
|
" <td>0.250000</td>\n",
|
|
" <td>0.691275</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>0.471698</td>\n",
|
|
" <td>0.253165</td>\n",
|
|
" <td>0.222892</td>\n",
|
|
" <td>0.113982</td>\n",
|
|
" <td>0.101473</td>\n",
|
|
" <td>0.141869</td>\n",
|
|
" <td>0.343182</td>\n",
|
|
" <td>0.959354</td>\n",
|
|
" <td>0.827930</td>\n",
|
|
" <td>0.300000</td>\n",
|
|
" <td>0.758389</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>0.817610</td>\n",
|
|
" <td>0.569620</td>\n",
|
|
" <td>0.445783</td>\n",
|
|
" <td>0.334347</td>\n",
|
|
" <td>0.679214</td>\n",
|
|
" <td>0.231834</td>\n",
|
|
" <td>0.575000</td>\n",
|
|
" <td>0.965264</td>\n",
|
|
" <td>0.917706</td>\n",
|
|
" <td>0.585000</td>\n",
|
|
" <td>0.939597</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" fixed_acidity volatile_acidity citric_acid residual_sugar \\\n",
|
|
"count 325.000000 325.000000 325.000000 325.000000 \n",
|
|
"mean 0.448244 0.217069 0.180630 0.078990 \n",
|
|
"std 0.074301 0.107627 0.078046 0.070045 \n",
|
|
"min 0.314465 0.063291 0.000000 0.012158 \n",
|
|
"25% 0.402516 0.145570 0.144578 0.027356 \n",
|
|
"50% 0.433962 0.177215 0.180723 0.042553 \n",
|
|
"75% 0.471698 0.253165 0.222892 0.113982 \n",
|
|
"max 0.817610 0.569620 0.445783 0.334347 \n",
|
|
"\n",
|
|
" chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n",
|
|
"count 325.000000 325.000000 325.000000 325.000000 \n",
|
|
"mean 0.088742 0.103024 0.257462 0.957255 \n",
|
|
"std 0.051400 0.054750 0.125165 0.002786 \n",
|
|
"min 0.031097 0.010381 0.020455 0.951116 \n",
|
|
"25% 0.060556 0.058824 0.168182 0.955168 \n",
|
|
"50% 0.078560 0.100346 0.261364 0.957478 \n",
|
|
"75% 0.101473 0.141869 0.343182 0.959354 \n",
|
|
"max 0.679214 0.231834 0.575000 0.965264 \n",
|
|
"\n",
|
|
" pH sulphates alcohol quality is_red \n",
|
|
"count 325.000000 325.000000 325.000000 325.000000 325.000000 \n",
|
|
"mean 0.803553 0.263877 0.703930 0.646154 0.753846 \n",
|
|
"std 0.039808 0.072275 0.078704 0.095014 0.431433 \n",
|
|
"min 0.713217 0.130000 0.570470 0.333333 0.000000 \n",
|
|
"25% 0.775561 0.210000 0.637584 0.555556 1.000000 \n",
|
|
"50% 0.800499 0.250000 0.691275 0.666667 1.000000 \n",
|
|
"75% 0.827930 0.300000 0.758389 0.666667 1.000000 \n",
|
|
"max 0.917706 0.585000 0.939597 1.000000 1.000000 "
|
|
]
|
|
},
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_test.describe()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>fixed_acidity</th>\n",
|
|
" <th>volatile_acidity</th>\n",
|
|
" <th>citric_acid</th>\n",
|
|
" <th>residual_sugar</th>\n",
|
|
" <th>chlorides</th>\n",
|
|
" <th>free_sulfur_dioxide</th>\n",
|
|
" <th>total_sulfur_dioxide</th>\n",
|
|
" <th>density</th>\n",
|
|
" <th>pH</th>\n",
|
|
" <th>sulphates</th>\n",
|
|
" <th>alcohol</th>\n",
|
|
" <th>quality</th>\n",
|
|
" <th>is_red</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" <td>5847.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>0.453848</td>\n",
|
|
" <td>0.215061</td>\n",
|
|
" <td>0.192235</td>\n",
|
|
" <td>0.082331</td>\n",
|
|
" <td>0.092161</td>\n",
|
|
" <td>0.105659</td>\n",
|
|
" <td>0.262894</td>\n",
|
|
" <td>0.957364</td>\n",
|
|
" <td>0.802569</td>\n",
|
|
" <td>0.265798</td>\n",
|
|
" <td>0.704326</td>\n",
|
|
" <td>0.646732</td>\n",
|
|
" <td>0.753891</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>0.081742</td>\n",
|
|
" <td>0.104315</td>\n",
|
|
" <td>0.088036</td>\n",
|
|
" <td>0.071982</td>\n",
|
|
" <td>0.058619</td>\n",
|
|
" <td>0.061749</td>\n",
|
|
" <td>0.128256</td>\n",
|
|
" <td>0.002882</td>\n",
|
|
" <td>0.039880</td>\n",
|
|
" <td>0.074864</td>\n",
|
|
" <td>0.079852</td>\n",
|
|
" <td>0.096928</td>\n",
|
|
" <td>0.430780</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>0.238994</td>\n",
|
|
" <td>0.050633</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.009119</td>\n",
|
|
" <td>0.014730</td>\n",
|
|
" <td>0.003460</td>\n",
|
|
" <td>0.013636</td>\n",
|
|
" <td>0.950076</td>\n",
|
|
" <td>0.678304</td>\n",
|
|
" <td>0.110000</td>\n",
|
|
" <td>0.536913</td>\n",
|
|
" <td>0.333333</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>0.402516</td>\n",
|
|
" <td>0.145570</td>\n",
|
|
" <td>0.150602</td>\n",
|
|
" <td>0.027356</td>\n",
|
|
" <td>0.062193</td>\n",
|
|
" <td>0.058824</td>\n",
|
|
" <td>0.176136</td>\n",
|
|
" <td>0.955071</td>\n",
|
|
" <td>0.775561</td>\n",
|
|
" <td>0.215000</td>\n",
|
|
" <td>0.637584</td>\n",
|
|
" <td>0.555556</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>0.440252</td>\n",
|
|
" <td>0.183544</td>\n",
|
|
" <td>0.186747</td>\n",
|
|
" <td>0.045593</td>\n",
|
|
" <td>0.076923</td>\n",
|
|
" <td>0.100346</td>\n",
|
|
" <td>0.268182</td>\n",
|
|
" <td>0.957516</td>\n",
|
|
" <td>0.800499</td>\n",
|
|
" <td>0.255000</td>\n",
|
|
" <td>0.691275</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>0.484277</td>\n",
|
|
" <td>0.253165</td>\n",
|
|
" <td>0.234940</td>\n",
|
|
" <td>0.123100</td>\n",
|
|
" <td>0.106383</td>\n",
|
|
" <td>0.141869</td>\n",
|
|
" <td>0.353409</td>\n",
|
|
" <td>0.959581</td>\n",
|
|
" <td>0.827930</td>\n",
|
|
" <td>0.300000</td>\n",
|
|
" <td>0.758389</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" fixed_acidity volatile_acidity citric_acid residual_sugar \\\n",
|
|
"count 5847.000000 5847.000000 5847.000000 5847.000000 \n",
|
|
"mean 0.453848 0.215061 0.192235 0.082331 \n",
|
|
"std 0.081742 0.104315 0.088036 0.071982 \n",
|
|
"min 0.238994 0.050633 0.000000 0.009119 \n",
|
|
"25% 0.402516 0.145570 0.150602 0.027356 \n",
|
|
"50% 0.440252 0.183544 0.186747 0.045593 \n",
|
|
"75% 0.484277 0.253165 0.234940 0.123100 \n",
|
|
"max 1.000000 1.000000 1.000000 1.000000 \n",
|
|
"\n",
|
|
" chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n",
|
|
"count 5847.000000 5847.000000 5847.000000 5847.000000 \n",
|
|
"mean 0.092161 0.105659 0.262894 0.957364 \n",
|
|
"std 0.058619 0.061749 0.128256 0.002882 \n",
|
|
"min 0.014730 0.003460 0.013636 0.950076 \n",
|
|
"25% 0.062193 0.058824 0.176136 0.955071 \n",
|
|
"50% 0.076923 0.100346 0.268182 0.957516 \n",
|
|
"75% 0.106383 0.141869 0.353409 0.959581 \n",
|
|
"max 1.000000 1.000000 1.000000 1.000000 \n",
|
|
"\n",
|
|
" pH sulphates alcohol quality is_red \n",
|
|
"count 5847.000000 5847.000000 5847.000000 5847.000000 5847.000000 \n",
|
|
"mean 0.802569 0.265798 0.704326 0.646732 0.753891 \n",
|
|
"std 0.039880 0.074864 0.079852 0.096928 0.430780 \n",
|
|
"min 0.678304 0.110000 0.536913 0.333333 0.000000 \n",
|
|
"25% 0.775561 0.215000 0.637584 0.555556 1.000000 \n",
|
|
"50% 0.800499 0.255000 0.691275 0.666667 1.000000 \n",
|
|
"75% 0.827930 0.300000 0.758389 0.666667 1.000000 \n",
|
|
"max 1.000000 1.000000 1.000000 1.000000 1.000000 "
|
|
]
|
|
},
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_train.describe()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>fixed_acidity</th>\n",
|
|
" <th>volatile_acidity</th>\n",
|
|
" <th>citric_acid</th>\n",
|
|
" <th>residual_sugar</th>\n",
|
|
" <th>chlorides</th>\n",
|
|
" <th>free_sulfur_dioxide</th>\n",
|
|
" <th>total_sulfur_dioxide</th>\n",
|
|
" <th>density</th>\n",
|
|
" <th>pH</th>\n",
|
|
" <th>sulphates</th>\n",
|
|
" <th>alcohol</th>\n",
|
|
" <th>quality</th>\n",
|
|
" <th>is_red</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" <td>325.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>0.458355</td>\n",
|
|
" <td>0.211412</td>\n",
|
|
" <td>0.198091</td>\n",
|
|
" <td>0.093521</td>\n",
|
|
" <td>0.086537</td>\n",
|
|
" <td>0.107596</td>\n",
|
|
" <td>0.271556</td>\n",
|
|
" <td>0.957757</td>\n",
|
|
" <td>0.802570</td>\n",
|
|
" <td>0.264446</td>\n",
|
|
" <td>0.701160</td>\n",
|
|
" <td>0.642393</td>\n",
|
|
" <td>0.753846</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>0.084621</td>\n",
|
|
" <td>0.098749</td>\n",
|
|
" <td>0.086862</td>\n",
|
|
" <td>0.079346</td>\n",
|
|
" <td>0.035141</td>\n",
|
|
" <td>0.061805</td>\n",
|
|
" <td>0.135185</td>\n",
|
|
" <td>0.003031</td>\n",
|
|
" <td>0.044183</td>\n",
|
|
" <td>0.068086</td>\n",
|
|
" <td>0.084939</td>\n",
|
|
" <td>0.100957</td>\n",
|
|
" <td>0.431433</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>0.295597</td>\n",
|
|
" <td>0.056962</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.012158</td>\n",
|
|
" <td>0.019640</td>\n",
|
|
" <td>0.010381</td>\n",
|
|
" <td>0.018182</td>\n",
|
|
" <td>0.950413</td>\n",
|
|
" <td>0.715711</td>\n",
|
|
" <td>0.140000</td>\n",
|
|
" <td>0.563758</td>\n",
|
|
" <td>0.333333</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>0.402516</td>\n",
|
|
" <td>0.145570</td>\n",
|
|
" <td>0.156627</td>\n",
|
|
" <td>0.030395</td>\n",
|
|
" <td>0.063830</td>\n",
|
|
" <td>0.055363</td>\n",
|
|
" <td>0.179545</td>\n",
|
|
" <td>0.955456</td>\n",
|
|
" <td>0.773067</td>\n",
|
|
" <td>0.215000</td>\n",
|
|
" <td>0.630872</td>\n",
|
|
" <td>0.555556</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>0.446541</td>\n",
|
|
" <td>0.183544</td>\n",
|
|
" <td>0.186747</td>\n",
|
|
" <td>0.069149</td>\n",
|
|
" <td>0.078560</td>\n",
|
|
" <td>0.100346</td>\n",
|
|
" <td>0.284091</td>\n",
|
|
" <td>0.957978</td>\n",
|
|
" <td>0.800499</td>\n",
|
|
" <td>0.250000</td>\n",
|
|
" <td>0.684564</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>0.490566</td>\n",
|
|
" <td>0.253165</td>\n",
|
|
" <td>0.240964</td>\n",
|
|
" <td>0.133739</td>\n",
|
|
" <td>0.098200</td>\n",
|
|
" <td>0.155709</td>\n",
|
|
" <td>0.370455</td>\n",
|
|
" <td>0.960028</td>\n",
|
|
" <td>0.827930</td>\n",
|
|
" <td>0.305000</td>\n",
|
|
" <td>0.758389</td>\n",
|
|
" <td>0.666667</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>0.943396</td>\n",
|
|
" <td>0.746835</td>\n",
|
|
" <td>0.445783</td>\n",
|
|
" <td>0.480243</td>\n",
|
|
" <td>0.278232</td>\n",
|
|
" <td>0.266436</td>\n",
|
|
" <td>0.570455</td>\n",
|
|
" <td>0.972396</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>0.570000</td>\n",
|
|
" <td>0.939597</td>\n",
|
|
" <td>0.888889</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" fixed_acidity volatile_acidity citric_acid residual_sugar \\\n",
|
|
"count 325.000000 325.000000 325.000000 325.000000 \n",
|
|
"mean 0.458355 0.211412 0.198091 0.093521 \n",
|
|
"std 0.084621 0.098749 0.086862 0.079346 \n",
|
|
"min 0.295597 0.056962 0.000000 0.012158 \n",
|
|
"25% 0.402516 0.145570 0.156627 0.030395 \n",
|
|
"50% 0.446541 0.183544 0.186747 0.069149 \n",
|
|
"75% 0.490566 0.253165 0.240964 0.133739 \n",
|
|
"max 0.943396 0.746835 0.445783 0.480243 \n",
|
|
"\n",
|
|
" chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n",
|
|
"count 325.000000 325.000000 325.000000 325.000000 \n",
|
|
"mean 0.086537 0.107596 0.271556 0.957757 \n",
|
|
"std 0.035141 0.061805 0.135185 0.003031 \n",
|
|
"min 0.019640 0.010381 0.018182 0.950413 \n",
|
|
"25% 0.063830 0.055363 0.179545 0.955456 \n",
|
|
"50% 0.078560 0.100346 0.284091 0.957978 \n",
|
|
"75% 0.098200 0.155709 0.370455 0.960028 \n",
|
|
"max 0.278232 0.266436 0.570455 0.972396 \n",
|
|
"\n",
|
|
" pH sulphates alcohol quality is_red \n",
|
|
"count 325.000000 325.000000 325.000000 325.000000 325.000000 \n",
|
|
"mean 0.802570 0.264446 0.701160 0.642393 0.753846 \n",
|
|
"std 0.044183 0.068086 0.084939 0.100957 0.431433 \n",
|
|
"min 0.715711 0.140000 0.563758 0.333333 0.000000 \n",
|
|
"25% 0.773067 0.215000 0.630872 0.555556 1.000000 \n",
|
|
"50% 0.800499 0.250000 0.684564 0.666667 1.000000 \n",
|
|
"75% 0.827930 0.305000 0.758389 0.666667 1.000000 \n",
|
|
"max 1.000000 0.570000 0.939597 0.888889 1.000000 "
|
|
]
|
|
},
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"wine_val.describe()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import torch\n",
|
|
"from torch import nn\n",
|
|
"from torch.utils.data import DataLoader, Dataset"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class TabularDataset(Dataset):\n",
|
|
" def __init__(self, data):\n",
|
|
" self.data = data.values.astype('float32')\n",
|
|
"\n",
|
|
" def __getitem__(self, index):\n",
|
|
" x = torch.tensor(self.data[index, :-1])\n",
|
|
" y = torch.tensor(self.data[index, -1])\n",
|
|
" return x, y\n",
|
|
"\n",
|
|
" def __len__(self):\n",
|
|
" return len(self.data)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"batch_size = 64\n",
|
|
"train_dataset = TabularDataset(wine_train)\n",
|
|
"train_dataloader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)\n",
|
|
"test_dataset = TabularDataset(wine_test)\n",
|
|
"test_dataloader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 28,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class TabularModel(nn.Module):\n",
|
|
" def __init__(self, input_dim, hidden_dim, output_dim):\n",
|
|
" super(TabularModel, self).__init__()\n",
|
|
" self.fc1 = nn.Linear(input_dim, hidden_dim)\n",
|
|
" self.relu = nn.ReLU()\n",
|
|
" self.fc2 = nn.Linear(hidden_dim, output_dim)\n",
|
|
" self.softmax = nn.Softmax(dim=1)\n",
|
|
" \n",
|
|
" def forward(self, x):\n",
|
|
" out = self.fc1(x)\n",
|
|
" out = self.relu(out)\n",
|
|
" out = self.fc2(out)\n",
|
|
" out = self.softmax(out)\n",
|
|
" return out"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"input_dim = wine_train.shape[1] - 1\n",
|
|
"hidden_dim = 32\n",
|
|
"output_dim = 2\n",
|
|
"model = TabularModel(input_dim, hidden_dim, output_dim)\n",
|
|
"criterion = nn.CrossEntropyLoss()\n",
|
|
"optimizer = torch.optim.Adam(model.parameters())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 30,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"model = TabularModel(input_dim=len(wine_train.columns)-1, hidden_dim=32, output_dim=2)\n",
|
|
"criterion = nn.CrossEntropyLoss()\n",
|
|
"optimizer = torch.optim.Adam(model.parameters(), lr=0.01)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Epoch 1, loss: 0.5358\n",
|
|
"Epoch 3, loss: 0.3417\n",
|
|
"Epoch 5, loss: 0.3344\n",
|
|
"Epoch 7, loss: 0.3338\n",
|
|
"Epoch 9, loss: 0.3318\n",
|
|
"Finished Training\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"num_epochs = 10\n",
|
|
"for epoch in range(num_epochs):\n",
|
|
" running_loss = 0.0\n",
|
|
" for i, data in enumerate(train_dataloader, 0):\n",
|
|
" inputs, labels = data\n",
|
|
" labels = labels.type(torch.LongTensor)\n",
|
|
" optimizer.zero_grad()\n",
|
|
" outputs = model(inputs)\n",
|
|
" loss = criterion(outputs, labels)\n",
|
|
" loss.backward()\n",
|
|
" optimizer.step()\n",
|
|
" running_loss += loss.item()\n",
|
|
"\n",
|
|
" # Print the loss every 1000 mini-batches\n",
|
|
" if (epoch%2) == 0:\n",
|
|
" print(f'Epoch {epoch + 1}, loss: {running_loss / len(train_dataloader):.4f}')\n",
|
|
"\n",
|
|
"print('Finished Training')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Accuracy on test set: 98 %\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"correct = 0\n",
|
|
"total = 0\n",
|
|
"with torch.no_grad():\n",
|
|
" for data in test_dataloader:\n",
|
|
" inputs, labels = data\n",
|
|
" outputs = model(inputs.float())\n",
|
|
" _, predicted = torch.max(outputs.data, 1)\n",
|
|
" total += labels.size(0)\n",
|
|
" correct += (predicted == labels).sum().item()\n",
|
|
"print('Accuracy on test set: %d %%' % (100 * correct / total))"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.11.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|