Datatrooper/wine
2
1{2 "nbformat": 4,3 "nbformat_minor": 0,4 "metadata": {5 "colab": {6 "name": "train_model.ipynb",7 "provenance": []8 },9 "kernelspec": {10 "name": "python3",11 "display_name": "Python 3"12 },13 "language_info": {14 "name": "python"15 }16 },17 "cells": [18 {19 "cell_type": "code",20 "execution_count": 23,21 "metadata": {22 "id": "kFAHrl4RTtV4"23 },24 "outputs": [],25 "source": [26 "import pandas as pd\n",27 "from sklearn.model_selection import train_test_split\n",28 "from sklearn.ensemble import RandomForestRegressor\n"29 ]30 },31 {32 "cell_type": "code",33 "source": [34 "wine = pd.read_csv(\"winequality-red.csv\")"35 ],36 "metadata": {37 "id": "PtRnEnZqUVz3"38 },39 "execution_count": 24,40 "outputs": []41 },42 {43 "cell_type": "code",44 "source": [45 "wine.describe()"46 ],47 "metadata": {48 "colab": {49 "base_uri": "https://localhost:8080/",50 "height": 34651 },52 "id": "BEyAqxlzcY7K",53 "outputId": "c9a6c736-27c4-4fcf-a70c-bb9f63dbb021"54 },55 "execution_count": 43,56 "outputs": [57 {58 "output_type": "execute_result",59 "data": {60 "text/html": [61 "\n",62 " <div id=\"df-0bdcf199-7a2a-4ca2-b770-b67e10da4e05\">\n",63 " <div class=\"colab-df-container\">\n",64 " <div>\n",65 "<style scoped>\n",66 " .dataframe tbody tr th:only-of-type {\n",67 " vertical-align: middle;\n",68 " }\n",69 "\n",70 " .dataframe tbody tr th {\n",71 " vertical-align: top;\n",72 " }\n",73 "\n",74 " .dataframe thead th {\n",75 " text-align: right;\n",76 " }\n",77 "</style>\n",78 "<table border=\"1\" class=\"dataframe\">\n",79 " <thead>\n",80 " <tr style=\"text-align: right;\">\n",81 " <th></th>\n",82 " <th>fixed acidity</th>\n",83 " <th>volatile acidity</th>\n",84 " <th>citric acid</th>\n",85 " <th>residual sugar</th>\n",86 " <th>chlorides</th>\n",87 " <th>free sulfur dioxide</th>\n",88 " <th>total sulfur dioxide</th>\n",89 " <th>density</th>\n",90 " <th>pH</th>\n",91 " <th>sulphates</th>\n",92 " <th>alcohol</th>\n",93 " <th>quality</th>\n",94 " </tr>\n",95 " </thead>\n",96 " <tbody>\n",97 " <tr>\n",98 " <th>count</th>\n",99 " <td>1599.000000</td>\n",100 " <td>1599.000000</td>\n",101 " <td>1599.000000</td>\n",102 " <td>1599.000000</td>\n",103 " <td>1599.000000</td>\n",104 " <td>1599.000000</td>\n",105 " <td>1599.000000</td>\n",106 " <td>1599.000000</td>\n",107 " <td>1599.000000</td>\n",108 " <td>1599.000000</td>\n",109 " <td>1599.000000</td>\n",110 " <td>1599.000000</td>\n",111 " </tr>\n",112 " <tr>\n",113 " <th>mean</th>\n",114 " <td>8.319637</td>\n",115 " <td>0.527821</td>\n",116 " <td>0.270976</td>\n",117 " <td>2.538806</td>\n",118 " <td>0.087467</td>\n",119 " <td>15.874922</td>\n",120 " <td>46.467792</td>\n",121 " <td>0.996747</td>\n",122 " <td>3.311113</td>\n",123 " <td>0.658149</td>\n",124 " <td>10.422983</td>\n",125 " <td>5.636023</td>\n",126 " </tr>\n",127 " <tr>\n",128 " <th>std</th>\n",129 " <td>1.741096</td>\n",130 " <td>0.179060</td>\n",131 " <td>0.194801</td>\n",132 " <td>1.409928</td>\n",133 " <td>0.047065</td>\n",134 " <td>10.460157</td>\n",135 " <td>32.895324</td>\n",136 " <td>0.001887</td>\n",137 " <td>0.154386</td>\n",138 " <td>0.169507</td>\n",139 " <td>1.065668</td>\n",140 " <td>0.807569</td>\n",141 " </tr>\n",142 " <tr>\n",143 " <th>min</th>\n",144 " <td>4.600000</td>\n",145 " <td>0.120000</td>\n",146 " <td>0.000000</td>\n",147 " <td>0.900000</td>\n",148 " <td>0.012000</td>\n",149 " <td>1.000000</td>\n",150 " <td>6.000000</td>\n",151 " <td>0.990070</td>\n",152 " <td>2.740000</td>\n",153 " <td>0.330000</td>\n",154 " <td>8.400000</td>\n",155 " <td>3.000000</td>\n",156 " </tr>\n",157 " <tr>\n",158 " <th>25%</th>\n",159 " <td>7.100000</td>\n",160 " <td>0.390000</td>\n",161 " <td>0.090000</td>\n",162 " <td>1.900000</td>\n",163 " <td>0.070000</td>\n",164 " <td>7.000000</td>\n",165 " <td>22.000000</td>\n",166 " <td>0.995600</td>\n",167 " <td>3.210000</td>\n",168 " <td>0.550000</td>\n",169 " <td>9.500000</td>\n",170 " <td>5.000000</td>\n",171 " </tr>\n",172 " <tr>\n",173 " <th>50%</th>\n",174 " <td>7.900000</td>\n",175 " <td>0.520000</td>\n",176 " <td>0.260000</td>\n",177 " <td>2.200000</td>\n",178 " <td>0.079000</td>\n",179 " <td>14.000000</td>\n",180 " <td>38.000000</td>\n",181 " <td>0.996750</td>\n",182 " <td>3.310000</td>\n",183 " <td>0.620000</td>\n",184 " <td>10.200000</td>\n",185 " <td>6.000000</td>\n",186 " </tr>\n",187 " <tr>\n",188 " <th>75%</th>\n",189 " <td>9.200000</td>\n",190 " <td>0.640000</td>\n",191 " <td>0.420000</td>\n",192 " <td>2.600000</td>\n",193 " <td>0.090000</td>\n",194 " <td>21.000000</td>\n",195 " <td>62.000000</td>\n",196 " <td>0.997835</td>\n",197 " <td>3.400000</td>\n",198 " <td>0.730000</td>\n",199 " <td>11.100000</td>\n",200 " <td>6.000000</td>\n",201 " </tr>\n",202 " <tr>\n",203 " <th>max</th>\n",204 " <td>15.900000</td>\n",205 " <td>1.580000</td>\n",206 " <td>1.000000</td>\n",207 " <td>15.500000</td>\n",208 " <td>0.611000</td>\n",209 " <td>72.000000</td>\n",210 " <td>289.000000</td>\n",211 " <td>1.003690</td>\n",212 " <td>4.010000</td>\n",213 " <td>2.000000</td>\n",214 " <td>14.900000</td>\n",215 " <td>8.000000</td>\n",216 " </tr>\n",217 " </tbody>\n",218 "</table>\n",219 "</div>\n",220 " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-0bdcf199-7a2a-4ca2-b770-b67e10da4e05')\"\n",221 " title=\"Convert this dataframe to an interactive table.\"\n",222 " style=\"display:none;\">\n",223 " \n",224 " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",225 " width=\"24px\">\n",226 " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",227 " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",228 " </svg>\n",229 " </button>\n",230 " \n",231 " <style>\n",232 " .colab-df-container {\n",233 " display:flex;\n",234 " flex-wrap:wrap;\n",235 " gap: 12px;\n",236 " }\n",237 "\n",238 " .colab-df-convert {\n",239 " background-color: #E8F0FE;\n",240 " border: none;\n",241 " border-radius: 50%;\n",242 " cursor: pointer;\n",243 " display: none;\n",244 " fill: #1967D2;\n",245 " height: 32px;\n",246 " padding: 0 0 0 0;\n",247 " width: 32px;\n",248 " }\n",249 "\n",250 " .colab-df-convert:hover {\n",251 " background-color: #E2EBFA;\n",252 " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",253 " fill: #174EA6;\n",254 " }\n",255 "\n",256 " [theme=dark] .colab-df-convert {\n",257 " background-color: #3B4455;\n",258 " fill: #D2E3FC;\n",259 " }\n",260 "\n",261 " [theme=dark] .colab-df-convert:hover {\n",262 " background-color: #434B5C;\n",263 " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",264 " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",265 " fill: #FFFFFF;\n",266 " }\n",267 " </style>\n",268 "\n",269 " <script>\n",270 " const buttonEl =\n",271 " document.querySelector('#df-0bdcf199-7a2a-4ca2-b770-b67e10da4e05 button.colab-df-convert');\n",272 " buttonEl.style.display =\n",273 " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",274 "\n",275 " async function convertToInteractive(key) {\n",276 " const element = document.querySelector('#df-0bdcf199-7a2a-4ca2-b770-b67e10da4e05');\n",277 " const dataTable =\n",278 " await google.colab.kernel.invokeFunction('convertToInteractive',\n",279 " [key], {});\n",280 " if (!dataTable) return;\n",281 "\n",282 " const docLinkHtml = 'Like what you see? Visit the ' +\n",283 " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",284 " + ' to learn more about interactive tables.';\n",285 " element.innerHTML = '';\n",286 " dataTable['output_type'] = 'display_data';\n",287 " await google.colab.output.renderOutput(dataTable, element);\n",288 " const docLink = document.createElement('div');\n",289 " docLink.innerHTML = docLinkHtml;\n",290 " element.appendChild(docLink);\n",291 " }\n",292 " </script>\n",293 " </div>\n",294 " </div>\n",295 " "296 ],297 "text/plain": [298 " fixed acidity volatile acidity ... alcohol quality\n",299 "count 1599.000000 1599.000000 ... 1599.000000 1599.000000\n",300 "mean 8.319637 0.527821 ... 10.422983 5.636023\n",301 "std 1.741096 0.179060 ... 1.065668 0.807569\n",302 "min 4.600000 0.120000 ... 8.400000 3.000000\n",303 "25% 7.100000 0.390000 ... 9.500000 5.000000\n",304 "50% 7.900000 0.520000 ... 10.200000 6.000000\n",305 "75% 9.200000 0.640000 ... 11.100000 6.000000\n",306 "max 15.900000 1.580000 ... 14.900000 8.000000\n",307 "\n",308 "[8 rows x 12 columns]"309 ]310 },311 "metadata": {},312 "execution_count": 43313 }314 ]315 },316 {317 "cell_type": "code",318 "source": [319 "wine.head()"320 ],321 "metadata": {322 "id": "xuERkgD3UZlx",323 "colab": {324 "base_uri": "https://localhost:8080/",325 "height": 204326 },327 "outputId": "8376f32a-b09b-4c7a-be86-3413a770c3b5"328 },329 "execution_count": 25,330 "outputs": [331 {332 "output_type": "execute_result",333 "data": {334 "text/html": [335 "\n",336 " <div id=\"df-9c66c3b7-b0e1-46aa-8330-3d03c87c9b1b\">\n",337 " <div class=\"colab-df-container\">\n",338 " <div>\n",339 "<style scoped>\n",340 " .dataframe tbody tr th:only-of-type {\n",341 " vertical-align: middle;\n",342 " }\n",343 "\n",344 " .dataframe tbody tr th {\n",345 " vertical-align: top;\n",346 " }\n",347 "\n",348 " .dataframe thead th {\n",349 " text-align: right;\n",350 " }\n",351 "</style>\n",352 "<table border=\"1\" class=\"dataframe\">\n",353 " <thead>\n",354 " <tr style=\"text-align: right;\">\n",355 " <th></th>\n",356 " <th>fixed acidity</th>\n",357 " <th>volatile acidity</th>\n",358 " <th>citric acid</th>\n",359 " <th>residual sugar</th>\n",360 " <th>chlorides</th>\n",361 " <th>free sulfur dioxide</th>\n",362 " <th>total sulfur dioxide</th>\n",363 " <th>density</th>\n",364 " <th>pH</th>\n",365 " <th>sulphates</th>\n",366 " <th>alcohol</th>\n",367 " <th>quality</th>\n",368 " </tr>\n",369 " </thead>\n",370 " <tbody>\n",371 " <tr>\n",372 " <th>0</th>\n",373 " <td>7.4</td>\n",374 " <td>0.70</td>\n",375 " <td>0.00</td>\n",376 " <td>1.9</td>\n",377 " <td>0.076</td>\n",378 " <td>11.0</td>\n",379 " <td>34.0</td>\n",380 " <td>0.9978</td>\n",381 " <td>3.51</td>\n",382 " <td>0.56</td>\n",383 " <td>9.4</td>\n",384 " <td>5</td>\n",385 " </tr>\n",386 " <tr>\n",387 " <th>1</th>\n",388 " <td>7.8</td>\n",389 " <td>0.88</td>\n",390 " <td>0.00</td>\n",391 " <td>2.6</td>\n",392 " <td>0.098</td>\n",393 " <td>25.0</td>\n",394 " <td>67.0</td>\n",395 " <td>0.9968</td>\n",396 " <td>3.20</td>\n",397 " <td>0.68</td>\n",398 " <td>9.8</td>\n",399 " <td>5</td>\n",400 " </tr>\n",401 " <tr>\n",402 " <th>2</th>\n",403 " <td>7.8</td>\n",404 " <td>0.76</td>\n",405 " <td>0.04</td>\n",406 " <td>2.3</td>\n",407 " <td>0.092</td>\n",408 " <td>15.0</td>\n",409 " <td>54.0</td>\n",410 " <td>0.9970</td>\n",411 " <td>3.26</td>\n",412 " <td>0.65</td>\n",413 " <td>9.8</td>\n",414 " <td>5</td>\n",415 " </tr>\n",416 " <tr>\n",417 " <th>3</th>\n",418 " <td>11.2</td>\n",419 " <td>0.28</td>\n",420 " <td>0.56</td>\n",421 " <td>1.9</td>\n",422 " <td>0.075</td>\n",423 " <td>17.0</td>\n",424 " <td>60.0</td>\n",425 " <td>0.9980</td>\n",426 " <td>3.16</td>\n",427 " <td>0.58</td>\n",428 " <td>9.8</td>\n",429 " <td>6</td>\n",430 " </tr>\n",431 " <tr>\n",432 " <th>4</th>\n",433 " <td>7.4</td>\n",434 " <td>0.70</td>\n",435 " <td>0.00</td>\n",436 " <td>1.9</td>\n",437 " <td>0.076</td>\n",438 " <td>11.0</td>\n",439 " <td>34.0</td>\n",440 " <td>0.9978</td>\n",441 " <td>3.51</td>\n",442 " <td>0.56</td>\n",443 " <td>9.4</td>\n",444 " <td>5</td>\n",445 " </tr>\n",446 " </tbody>\n",447 "</table>\n",448 "</div>\n",449 " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9c66c3b7-b0e1-46aa-8330-3d03c87c9b1b')\"\n",450 " title=\"Convert this dataframe to an interactive table.\"\n",451 " style=\"display:none;\">\n",452 " \n",453 " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",454 " width=\"24px\">\n",455 " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",456 " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",457 " </svg>\n",458 " </button>\n",459 " \n",460 " <style>\n",461 " .colab-df-container {\n",462 " display:flex;\n",463 " flex-wrap:wrap;\n",464 " gap: 12px;\n",465 " }\n",466 "\n",467 " .colab-df-convert {\n",468 " background-color: #E8F0FE;\n",469 " border: none;\n",470 " border-radius: 50%;\n",471 " cursor: pointer;\n",472 " display: none;\n",473 " fill: #1967D2;\n",474 " height: 32px;\n",475 " padding: 0 0 0 0;\n",476 " width: 32px;\n",477 " }\n",478 "\n",479 " .colab-df-convert:hover {\n",480 " background-color: #E2EBFA;\n",481 " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",482 " fill: #174EA6;\n",483 " }\n",484 "\n",485 " [theme=dark] .colab-df-convert {\n",486 " background-color: #3B4455;\n",487 " fill: #D2E3FC;\n",488 " }\n",489 "\n",490 " [theme=dark] .colab-df-convert:hover {\n",491 " background-color: #434B5C;\n",492 " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",493 " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",494 " fill: #FFFFFF;\n",495 " }\n",496 " </style>\n",497 "\n",498 " <script>\n",499 " const buttonEl =\n",500 " document.querySelector('#df-9c66c3b7-b0e1-46aa-8330-3d03c87c9b1b button.colab-df-convert');\n",501 " buttonEl.style.display =\n",502 " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",503 "\n",504 " async function convertToInteractive(key) {\n",505 " const element = document.querySelector('#df-9c66c3b7-b0e1-46aa-8330-3d03c87c9b1b');\n",506 " const dataTable =\n",507 " await google.colab.kernel.invokeFunction('convertToInteractive',\n",508 " [key], {});\n",509 " if (!dataTable) return;\n",510 "\n",511 " const docLinkHtml = 'Like what you see? Visit the ' +\n",512 " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",513 " + ' to learn more about interactive tables.';\n",514 " element.innerHTML = '';\n",515 " dataTable['output_type'] = 'display_data';\n",516 " await google.colab.output.renderOutput(dataTable, element);\n",517 " const docLink = document.createElement('div');\n",518 " docLink.innerHTML = docLinkHtml;\n",519 " element.appendChild(docLink);\n",520 " }\n",521 " </script>\n",522 " </div>\n",523 " </div>\n",524 " "525 ],526 "text/plain": [527 " fixed acidity volatile acidity citric acid ... sulphates alcohol quality\n",528 "0 7.4 0.70 0.00 ... 0.56 9.4 5\n",529 "1 7.8 0.88 0.00 ... 0.68 9.8 5\n",530 "2 7.8 0.76 0.04 ... 0.65 9.8 5\n",531 "3 11.2 0.28 0.56 ... 0.58 9.8 6\n",532 "4 7.4 0.70 0.00 ... 0.56 9.4 5\n",533 "\n",534 "[5 rows x 12 columns]"535 ]536 },537 "metadata": {},538 "execution_count": 25539 }540 ]541 },542 {543 "cell_type": "code",544 "source": [545 "X = wine.drop('quality', axis = 1)\n",546 "y = wine['quality']"547 ],548 "metadata": {549 "id": "G2XlFDL1UuGU"550 },551 "execution_count": 26,552 "outputs": []553 },554 {555 "cell_type": "code",556 "source": [557 "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)"558 ],559 "metadata": {560 "id": "fwQiTgseUZ8t"561 },562 "execution_count": 27,563 "outputs": []564 },565 {566 "cell_type": "code",567 "source": [568 "rfc = RandomForestRegressor(n_estimators=200)\n",569 "rfc.fit(X_train, y_train)\n",570 "rfc.score(X_test, y_test)"571 ],572 "metadata": {573 "colab": {574 "base_uri": "https://localhost:8080/"575 },576 "id": "gfaWbU0XU8qx",577 "outputId": "c1360af2-235a-441b-89dc-ed8a1a3cd652"578 },579 "execution_count": 28,580 "outputs": [581 {582 "output_type": "execute_result",583 "data": {584 "text/plain": [585 "0.452940101720804"586 ]587 },588 "metadata": {},589 "execution_count": 28590 }591 ]592 },593 {594 "cell_type": "code",595 "source": [596 "preds = rfc.predict(X_test)"597 ],598 "metadata": {599 "id": "RS8QjOk6W3eW"600 },601 "execution_count": 31,602 "outputs": []603 },604 {605 "cell_type": "code",606 "source": [607 "df.iloc[0,:]"608 ],609 "metadata": {610 "colab": {611 "base_uri": "https://localhost:8080/"612 },613 "id": "p6A3L6kcYLg4",614 "outputId": "27042b35-0070-4a8f-dc21-10e30ea4f03a"615 },616 "execution_count": 34,617 "outputs": [618 {619 "output_type": "execute_result",620 "data": {621 "text/plain": [622 "fixed acidity 7.4000\n",623 "volatile acidity 0.7000\n",624 "citric acid 0.0000\n",625 "residual sugar 1.9000\n",626 "chlorides 0.0760\n",627 "free sulfur dioxide 11.0000\n",628 "total sulfur dioxide 34.0000\n",629 "density 0.9978\n",630 "pH 3.5100\n",631 "sulphates 0.5600\n",632 "alcohol 9.4000\n",633 "quality 5.0000\n",634 "Name: 0, dtype: float64"635 ]636 },637 "metadata": {},638 "execution_count": 34639 }640 ]641 },642 {643 "cell_type": "code",644 "source": [645 "df_pred = pd.DataFrame.from_dict({\n",646 " 'fixed acidity': 7.4, \n",647 " 'volatile acidity': 0.7, \n",648 " 'citric acid': 0, \n",649 " 'residual sugar': 1.9,\n",650 " 'chlorides': 0.076, \n",651 " 'free sulfur dioxide': 11, \n",652 " 'total sulfur dioxide': 34, \n",653 " 'density':0.9978,\n",654 " 'pH': 3.51, \n",655 " 'sulphates': 0.56, \n",656 " 'alcohol':9.4\n",657 "}, orient='index').T"658 ],659 "metadata": {660 "id": "YYRmAoyJYGKR"661 },662 "execution_count": 40,663 "outputs": []664 },665 {666 "cell_type": "code",667 "source": [668 "df_pred"669 ],670 "metadata": {671 "colab": {672 "base_uri": "https://localhost:8080/",673 "height": 80674 },675 "id": "fFCqmU6SY_S5",676 "outputId": "4606cb07-1eb0-4b4e-8e7b-03eb505481fc"677 },678 "execution_count": 41,679 "outputs": [680 {681 "output_type": "execute_result",682 "data": {683 "text/html": [684 "\n",685 " <div id=\"df-8ac8e971-1853-44d2-995f-b7f382067827\">\n",686 " <div class=\"colab-df-container\">\n",687 " <div>\n",688 "<style scoped>\n",689 " .dataframe tbody tr th:only-of-type {\n",690 " vertical-align: middle;\n",691 " }\n",692 "\n",693 " .dataframe tbody tr th {\n",694 " vertical-align: top;\n",695 " }\n",696 "\n",697 " .dataframe thead th {\n",698 " text-align: right;\n",699 " }\n",700 "</style>\n",701 "<table border=\"1\" class=\"dataframe\">\n",702 " <thead>\n",703 " <tr style=\"text-align: right;\">\n",704 " <th></th>\n",705 " <th>fixed acidity</th>\n",706 " <th>volatile acidity</th>\n",707 " <th>citric acid</th>\n",708 " <th>residual sugar</th>\n",709 " <th>chlorides</th>\n",710 " <th>free sulfur dioxide</th>\n",711 " <th>total sulfur dioxide</th>\n",712 " <th>density</th>\n",713 " <th>pH</th>\n",714 " <th>sulphates</th>\n",715 " <th>alcohol</th>\n",716 " </tr>\n",717 " </thead>\n",718 " <tbody>\n",719 " <tr>\n",720 " <th>0</th>\n",721 " <td>7.4</td>\n",722 " <td>0.7</td>\n",723 " <td>0.0</td>\n",724 " <td>1.9</td>\n",725 " <td>0.076</td>\n",726 " <td>11.0</td>\n",727 " <td>34.0</td>\n",728 " <td>0.9978</td>\n",729 " <td>3.51</td>\n",730 " <td>0.56</td>\n",731 " <td>9.4</td>\n",732 " </tr>\n",733 " </tbody>\n",734 "</table>\n",735 "</div>\n",736 " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-8ac8e971-1853-44d2-995f-b7f382067827')\"\n",737 " title=\"Convert this dataframe to an interactive table.\"\n",738 " style=\"display:none;\">\n",739 " \n",740 " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",741 " width=\"24px\">\n",742 " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",743 " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",744 " </svg>\n",745 " </button>\n",746 " \n",747 " <style>\n",748 " .colab-df-container {\n",749 " display:flex;\n",750 " flex-wrap:wrap;\n",751 " gap: 12px;\n",752 " }\n",753 "\n",754 " .colab-df-convert {\n",755 " background-color: #E8F0FE;\n",756 " border: none;\n",757 " border-radius: 50%;\n",758 " cursor: pointer;\n",759 " display: none;\n",760 " fill: #1967D2;\n",761 " height: 32px;\n",762 " padding: 0 0 0 0;\n",763 " width: 32px;\n",764 " }\n",765 "\n",766 " .colab-df-convert:hover {\n",767 " background-color: #E2EBFA;\n",768 " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",769 " fill: #174EA6;\n",770 " }\n",771 "\n",772 " [theme=dark] .colab-df-convert {\n",773 " background-color: #3B4455;\n",774 " fill: #D2E3FC;\n",775 " }\n",776 "\n",777 " [theme=dark] .colab-df-convert:hover {\n",778 " background-color: #434B5C;\n",779 " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",780 " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",781 " fill: #FFFFFF;\n",782 " }\n",783 " </style>\n",784 "\n",785 " <script>\n",786 " const buttonEl =\n",787 " document.querySelector('#df-8ac8e971-1853-44d2-995f-b7f382067827 button.colab-df-convert');\n",788 " buttonEl.style.display =\n",789 " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",790 "\n",791 " async function convertToInteractive(key) {\n",792 " const element = document.querySelector('#df-8ac8e971-1853-44d2-995f-b7f382067827');\n",793 " const dataTable =\n",794 " await google.colab.kernel.invokeFunction('convertToInteractive',\n",795 " [key], {});\n",796 " if (!dataTable) return;\n",797 "\n",798 " const docLinkHtml = 'Like what you see? Visit the ' +\n",799 " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",800 " + ' to learn more about interactive tables.';\n",801 " element.innerHTML = '';\n",802 " dataTable['output_type'] = 'display_data';\n",803 " await google.colab.output.renderOutput(dataTable, element);\n",804 " const docLink = document.createElement('div');\n",805 " docLink.innerHTML = docLinkHtml;\n",806 " element.appendChild(docLink);\n",807 " }\n",808 " </script>\n",809 " </div>\n",810 " </div>\n",811 " "812 ],813 "text/plain": [814 " fixed acidity volatile acidity citric acid ... pH sulphates alcohol\n",815 "0 7.4 0.7 0.0 ... 3.51 0.56 9.4\n",816 "\n",817 "[1 rows x 11 columns]"818 ]819 },820 "metadata": {},821 "execution_count": 41822 }823 ]824 },825 {826 "cell_type": "code",827 "source": [828 "rfc.predict(df_pred)"829 ],830 "metadata": {831 "colab": {832 "base_uri": "https://localhost:8080/"833 },834 "id": "TbLBRotEYBOf",835 "outputId": "6ac50cb8-147b-4c96-bc39-2261b736973e"836 },837 "execution_count": 42,838 "outputs": [839 {840 "output_type": "execute_result",841 "data": {842 "text/plain": [843 "array([5.025])"844 ]845 },846 "metadata": {},847 "execution_count": 42848 }849 ]850 },851 {852 "cell_type": "code",853 "source": [854 "from joblib import dump, load\n",855 "dump(rfc, 'wine_pred.joblib') "856 ],857 "metadata": {858 "colab": {859 "base_uri": "https://localhost:8080/"860 },861 "id": "Wh5wXQqbWHNK",862 "outputId": "84d59d4f-811b-4e1d-d182-267bbde56414"863 },864 "execution_count": 32,865 "outputs": [866 {867 "output_type": "execute_result",868 "data": {869 "text/plain": [870 "['wine_pred.joblib']"871 ]872 },873 "metadata": {},874 "execution_count": 32875 }876 ]877 },878 {879 "cell_type": "code",880 "source": [881 ""882 ],883 "metadata": {884 "id": "BkfTMO4AXi4o"885 },886 "execution_count": null,887 "outputs": []888 }889 ]890}