{ "cells": [ { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import sklearn.model_selection" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "import requests\n", "\n", "url = \"https://huggingface.co/datasets/mstz/wine/raw/main/Wine_Quality_Data.csv\"\n", "save_path = \"Wine_Quality_Data.csv\"\n", "\n", "response = requests.get(url)\n", "response.raise_for_status()\n", "\n", "with open(save_path, \"wb\") as f:\n", " f.write(response.content)\n" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [], "source": [ "wine_dataset = pd.read_csv(\"Wine_Quality_Data.csv\")" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fixed_acidityvolatile_aciditycitric_acidresidual_sugarchloridesfree_sulfur_dioxidetotal_sulfur_dioxidedensitypHsulphatesalcoholqualitycolor
07.40.700.001.90.07611.034.00.99783.510.569.45red
17.80.880.002.60.09825.067.00.99683.200.689.85red
27.80.760.042.30.09215.054.00.99703.260.659.85red
311.20.280.561.90.07517.060.00.99803.160.589.86red
47.40.700.001.90.07611.034.00.99783.510.569.45red
\n", "
" ], "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 color \n", "0 9.4 5 red \n", "1 9.8 5 red \n", "2 9.8 5 red \n", "3 9.8 6 red \n", "4 9.4 5 red " ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_dataset.head()# podgląd danych" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "wine_dataset['color'] = wine_dataset['color'].replace({'red': 1, 'white': 0})" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fixed_acidityvolatile_aciditycitric_acidresidual_sugarchloridesfree_sulfur_dioxidetotal_sulfur_dioxidedensitypHsulphatesalcoholqualitycolor
count6497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.000000
mean7.2153070.3396660.3186335.4432350.05603430.525319115.7445740.9946973.2185010.53126810.4918015.8183780.246114
std1.2964340.1646360.1453184.7578040.03503417.74940056.5218550.0029990.1607870.1488061.1927120.8732550.430779
min3.8000000.0800000.0000000.6000000.0090001.0000006.0000000.9871102.7200000.2200008.0000003.0000000.000000
25%6.4000000.2300000.2500001.8000000.03800017.00000077.0000000.9923403.1100000.4300009.5000005.0000000.000000
50%7.0000000.2900000.3100003.0000000.04700029.000000118.0000000.9948903.2100000.51000010.3000006.0000000.000000
75%7.7000000.4000000.3900008.1000000.06500041.000000156.0000000.9969903.3200000.60000011.3000006.0000000.000000
max15.9000001.5800001.66000065.8000000.611000289.000000440.0000001.0389804.0100002.00000014.9000009.0000001.000000
\n", "
" ], "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 color \n", "count 6497.000000 6497.000000 6497.000000 6497.000000 6497.000000 \n", "mean 3.218501 0.531268 10.491801 5.818378 0.246114 \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 0.000000 \n", "50% 3.210000 0.510000 10.300000 6.000000 0.000000 \n", "75% 3.320000 0.600000 11.300000 6.000000 0.000000 \n", "max 4.010000 2.000000 14.900000 9.000000 1.000000 " ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_dataset.describe(include='all')" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjMAAAGbCAYAAAAx9RHcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy88F64QAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAeNUlEQVR4nO3df0xV9/3H8de9XH4J3g5RuLSG1uHEkW1F6zWQDMdMvqzZ3BZGl2URs7pqWWdGh2Omi/SXzq5LUTubudaotaYSZwbp1nRZTU2WtYtSYO2aFVmrVWM7gVIptyJwy733+4e5d15tC5cVL2/u85EY5ZzP+eRjOYc+PfdwcYRCoZAAAACMcsZ7AQAAAP8LYgYAAJhGzAAAANOIGQAAYBoxAwAATC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j3kvBFEbMwLQPP/xQx48fV09Pj4aGhpSWliaPx6OFCxcqJSUl3ssD8D/q7e3V66+/rq9+9avxXgqmMGIGAACYxv13AABgGjEDAABMI2YAAIBpxAwAADCNmAEAAKYRMwAAwDRiBgAAmEbMAAAA0/4fapCwNl9f+CcAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "wine_dataset[\"color\"].value_counts().plot(kind=\"bar\")\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.2964337577998153" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_dataset[\"fixed_acidity\"].std()" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([], dtype=int64), array([], dtype=int64))" ] }, "execution_count": 64, "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": 65, "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": 66, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fixed_acidityvolatile_aciditycitric_acidresidual_sugarchloridesfree_sulfur_dioxidetotal_sulfur_dioxidedensitypHsulphatesalcoholqualitycolor
count6497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.0000006497.000000
mean0.4537930.2149780.1919480.0827240.0917080.1056240.2630560.9573780.8026190.2656340.7041480.6464860.246114
std0.0815370.1042000.0875410.0723070.0573380.0614170.1284590.0028860.0400970.0744030.0800480.0970280.430779
min0.2389940.0506330.0000000.0091190.0147300.0034600.0136360.9500760.6783040.1100000.5369130.3333330.000000
25%0.4025160.1455700.1506020.0273560.0621930.0588240.1750000.9551100.7755610.2150000.6375840.5555560.000000
50%0.4402520.1835440.1867470.0455930.0769230.1003460.2681820.9575640.8004990.2550000.6912750.6666670.000000
75%0.4842770.2531650.2349400.1231000.1063830.1418690.3545450.9595850.8279300.3000000.7583890.6666670.000000
max1.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.000000
\n", "
" ], "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 color \n", "count 6497.000000 6497.000000 6497.000000 6497.000000 6497.000000 \n", "mean 0.802619 0.265634 0.704148 0.646486 0.246114 \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 0.000000 \n", "50% 0.800499 0.255000 0.691275 0.666667 0.000000 \n", "75% 0.827930 0.300000 0.758389 0.666667 0.000000 \n", "max 1.000000 1.000000 1.000000 1.000000 1.000000 " ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_dataset.describe(include='all') # sprawdzanie wartości po znormalizowaniu" ] }, { "cell_type": "code", "execution_count": 67, "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": 67, "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": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0 4408\n", "1.0 1439\n", "Name: color, dtype: int64" ] }, "execution_count": 68, "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[\"color\"])\n", "wine_train[\"color\"].value_counts() \n", "# podzielenie na train i test" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0 490\n", "1.0 160\n", "Name: color, dtype: int64" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_test[\"color\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 70, "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[\"color\"]) # podzielenie na test i validation" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0 245\n", "1.0 80\n", "Name: color, dtype: int64" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_test[\"color\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0 245\n", "1.0 80\n", "Name: color, dtype: int64" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_val[\"color\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "import seaborn as sns\n", "sns.set_theme()" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "13" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(wine_dataset.columns)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [], "source": [ "#sns.pairplot(data=wine_dataset, hue=\"color\")" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fixed_acidityvolatile_aciditycitric_acidresidual_sugarchloridesfree_sulfur_dioxidetotal_sulfur_dioxidedensitypHsulphatesalcoholqualitycolor
count325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000
mean0.4601260.2098830.1972940.0838390.0963520.1053070.2720280.9576850.7997700.2664770.6913890.6362390.246154
std0.0873210.1009710.0865320.0721720.0660170.0618950.1319810.0027800.0386400.0822430.0732930.0887320.431433
min0.3081760.0664560.0000000.0106380.0261870.0034600.0204550.9520300.6982540.1150000.5771810.3333330.000000
25%0.4088050.1392410.1566270.0273560.0621930.0588240.1886360.9553220.7730670.2150000.6308720.5555560.000000
50%0.4402520.1898730.1867470.0486320.0785600.1003460.2750000.9579780.7955110.2500000.6711410.6666670.000000
75%0.4842770.2405060.2469880.1215810.1162030.1453290.3568180.9597870.8229430.3050000.7382550.6666670.000000
max0.9433960.7151900.4698800.3031910.7643210.4792390.7818180.9660340.8952620.9750000.9060400.8888891.000000
\n", "
" ], "text/plain": [ " fixed_acidity volatile_acidity citric_acid residual_sugar \\\n", "count 325.000000 325.000000 325.000000 325.000000 \n", "mean 0.460126 0.209883 0.197294 0.083839 \n", "std 0.087321 0.100971 0.086532 0.072172 \n", "min 0.308176 0.066456 0.000000 0.010638 \n", "25% 0.408805 0.139241 0.156627 0.027356 \n", "50% 0.440252 0.189873 0.186747 0.048632 \n", "75% 0.484277 0.240506 0.246988 0.121581 \n", "max 0.943396 0.715190 0.469880 0.303191 \n", "\n", " chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n", "count 325.000000 325.000000 325.000000 325.000000 \n", "mean 0.096352 0.105307 0.272028 0.957685 \n", "std 0.066017 0.061895 0.131981 0.002780 \n", "min 0.026187 0.003460 0.020455 0.952030 \n", "25% 0.062193 0.058824 0.188636 0.955322 \n", "50% 0.078560 0.100346 0.275000 0.957978 \n", "75% 0.116203 0.145329 0.356818 0.959787 \n", "max 0.764321 0.479239 0.781818 0.966034 \n", "\n", " pH sulphates alcohol quality color \n", "count 325.000000 325.000000 325.000000 325.000000 325.000000 \n", "mean 0.799770 0.266477 0.691389 0.636239 0.246154 \n", "std 0.038640 0.082243 0.073293 0.088732 0.431433 \n", "min 0.698254 0.115000 0.577181 0.333333 0.000000 \n", "25% 0.773067 0.215000 0.630872 0.555556 0.000000 \n", "50% 0.795511 0.250000 0.671141 0.666667 0.000000 \n", "75% 0.822943 0.305000 0.738255 0.666667 0.000000 \n", "max 0.895262 0.975000 0.906040 0.888889 1.000000 " ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_test.describe()" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fixed_acidityvolatile_aciditycitric_acidresidual_sugarchloridesfree_sulfur_dioxidetotal_sulfur_dioxidedensitypHsulphatesalcoholqualitycolor
count5847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.0000005847.000000
mean0.4537240.2151280.1920910.0828770.0916560.1058990.2628340.9573740.8026370.2656010.7045720.6468460.246109
std0.0815970.1043190.0871660.0724870.0575020.0619080.1283880.0028990.0400300.0744000.0803990.0972120.430780
min0.2389940.0506330.0000000.0091190.0147300.0034600.0136360.9500760.6783040.1100000.5369130.3333330.000000
25%0.4025160.1455700.1506020.0273560.0621930.0588240.1750000.9551100.7755610.2150000.6375840.5555560.000000
50%0.4402520.1835440.1867470.0455930.0769230.1003460.2681820.9575550.8004990.2550000.6912750.6666670.000000
75%0.4842770.2594940.2349400.1231000.1063830.1418690.3545450.9595850.8279300.3000000.7583890.6666670.000000
max1.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.0000001.000000
\n", "
" ], "text/plain": [ " fixed_acidity volatile_acidity citric_acid residual_sugar \\\n", "count 5847.000000 5847.000000 5847.000000 5847.000000 \n", "mean 0.453724 0.215128 0.192091 0.082877 \n", "std 0.081597 0.104319 0.087166 0.072487 \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.259494 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.091656 0.105899 0.262834 0.957374 \n", "std 0.057502 0.061908 0.128388 0.002899 \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.957555 \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 color \n", "count 5847.000000 5847.000000 5847.000000 5847.000000 5847.000000 \n", "mean 0.802637 0.265601 0.704572 0.646846 0.246109 \n", "std 0.040030 0.074400 0.080399 0.097212 0.430780 \n", "min 0.678304 0.110000 0.536913 0.333333 0.000000 \n", "25% 0.775561 0.215000 0.637584 0.555556 0.000000 \n", "50% 0.800499 0.255000 0.691275 0.666667 0.000000 \n", "75% 0.827930 0.300000 0.758389 0.666667 0.000000 \n", "max 1.000000 1.000000 1.000000 1.000000 1.000000 " ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_train.describe()" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fixed_acidityvolatile_aciditycitric_acidresidual_sugarchloridesfree_sulfur_dioxidetotal_sulfur_dioxidedensitypHsulphatesalcoholqualitycolor
count325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000325.000000
mean0.4487080.2173810.1840220.0788640.0880170.1009850.2580730.9571470.8051410.2653850.7092690.6502560.246154
std0.0739600.1053880.0947360.0692320.0431590.0511740.1261200.0027460.0425840.0659460.0791980.1012250.431433
min0.3018870.0759490.0000000.0121580.0261870.0069200.0181820.9507310.6832920.1500000.5704700.3333330.000000
25%0.4025160.1455700.1385540.0288750.0621930.0588240.1795450.9548790.7755610.2150000.6375840.5555560.000000
50%0.4339620.1772150.1867470.0425530.0769230.1003460.2568180.9571890.8054860.2600000.6979870.6666670.000000
75%0.4842770.2531650.2349400.1170210.1014730.1384080.3568180.9593060.8304240.3050000.7583890.6666670.000000
max0.7987420.6962030.6024100.3031910.4369890.2802770.5750000.9629350.9351620.4900000.9530200.8888891.000000
\n", "
" ], "text/plain": [ " fixed_acidity volatile_acidity citric_acid residual_sugar \\\n", "count 325.000000 325.000000 325.000000 325.000000 \n", "mean 0.448708 0.217381 0.184022 0.078864 \n", "std 0.073960 0.105388 0.094736 0.069232 \n", "min 0.301887 0.075949 0.000000 0.012158 \n", "25% 0.402516 0.145570 0.138554 0.028875 \n", "50% 0.433962 0.177215 0.186747 0.042553 \n", "75% 0.484277 0.253165 0.234940 0.117021 \n", "max 0.798742 0.696203 0.602410 0.303191 \n", "\n", " chlorides free_sulfur_dioxide total_sulfur_dioxide density \\\n", "count 325.000000 325.000000 325.000000 325.000000 \n", "mean 0.088017 0.100985 0.258073 0.957147 \n", "std 0.043159 0.051174 0.126120 0.002746 \n", "min 0.026187 0.006920 0.018182 0.950731 \n", "25% 0.062193 0.058824 0.179545 0.954879 \n", "50% 0.076923 0.100346 0.256818 0.957189 \n", "75% 0.101473 0.138408 0.356818 0.959306 \n", "max 0.436989 0.280277 0.575000 0.962935 \n", "\n", " pH sulphates alcohol quality color \n", "count 325.000000 325.000000 325.000000 325.000000 325.000000 \n", "mean 0.805141 0.265385 0.709269 0.650256 0.246154 \n", "std 0.042584 0.065946 0.079198 0.101225 0.431433 \n", "min 0.683292 0.150000 0.570470 0.333333 0.000000 \n", "25% 0.775561 0.215000 0.637584 0.555556 0.000000 \n", "50% 0.805486 0.260000 0.697987 0.666667 0.000000 \n", "75% 0.830424 0.305000 0.758389 0.666667 0.000000 \n", "max 0.935162 0.490000 0.953020 0.888889 1.000000 " ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wine_val.describe()" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [], "source": [ "import torch\n", "from torch import nn\n", "from torch.utils.data import DataLoader, Dataset" ] }, { "cell_type": "code", "execution_count": 80, "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": 81, "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": 82, "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": 83, "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": 84, "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": 85, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1, loss: 0.4864\n", "Epoch 3, loss: 0.3413\n", "Epoch 5, loss: 0.3345\n", "Epoch 7, loss: 0.3337\n", "Epoch 9, loss: 0.3331\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": 86, "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 }