You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ML-For-Beginners/2-Regression/3-Linear/solution/notebook.ipynb

542 lines
219 KiB

4 years ago
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
4 years ago
"version": "3.7.0"
4 years ago
},
"orig_nbformat": 2,
"kernelspec": {
4 years ago
"name": "python37364bit8d3b438fb5fc4430a93ac2cb74d693a7",
"display_name": "Python 3.7.0 64-bit ('3.7')"
},
"metadata": {
"interpreter": {
"hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
}
4 years ago
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"source": [
"## Linear and Polynomial Regression for Pumpkin Pricing - Lesson 3\n",
4 years ago
"\n",
"Load up required libraries and dataset. Convert the data to a dataframe containing a subset of the data: \n",
"\n",
"- Only get pumpkins priced by the bushel\n",
"- Convert the date to a month\n",
"- Calculate the price to be an average of high and low prices\n",
"- Convert the price to reflect the pricing by bushel quantity"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 1,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" City Name Type Package Variety Sub Variety Grade Date \\\n",
"0 BALTIMORE NaN 24 inch bins NaN NaN NaN 4/29/17 \n",
"1 BALTIMORE NaN 24 inch bins NaN NaN NaN 5/6/17 \n",
"2 BALTIMORE NaN 24 inch bins HOWDEN TYPE NaN NaN 9/24/16 \n",
"3 BALTIMORE NaN 24 inch bins HOWDEN TYPE NaN NaN 9/24/16 \n",
"4 BALTIMORE NaN 24 inch bins HOWDEN TYPE NaN NaN 11/5/16 \n",
"\n",
" Low Price High Price Mostly Low ... Unit of Sale Quality Condition \\\n",
"0 270.0 280.0 270.0 ... NaN NaN NaN \n",
"1 270.0 280.0 270.0 ... NaN NaN NaN \n",
"2 160.0 160.0 160.0 ... NaN NaN NaN \n",
"3 160.0 160.0 160.0 ... NaN NaN NaN \n",
"4 90.0 100.0 90.0 ... NaN NaN NaN \n",
"\n",
" Appearance Storage Crop Repack Trans Mode Unnamed: 24 Unnamed: 25 \n",
"0 NaN NaN NaN E NaN NaN NaN \n",
"1 NaN NaN NaN E NaN NaN NaN \n",
"2 NaN NaN NaN N NaN NaN NaN \n",
"3 NaN NaN NaN N NaN NaN NaN \n",
"4 NaN NaN NaN N NaN NaN NaN \n",
"\n",
"[5 rows x 26 columns]"
],
"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>City Name</th>\n <th>Type</th>\n <th>Package</th>\n <th>Variety</th>\n <th>Sub Variety</th>\n <th>Grade</th>\n <th>Date</th>\n <th>Low Price</th>\n <th>High Price</th>\n <th>Mostly Low</th>\n <th>...</th>\n <th>Unit of Sale</th>\n <th>Quality</th>\n <th>Condition</th>\n <th>Appearance</th>\n <th>Storage</th>\n <th>Crop</th>\n <th>Repack</th>\n <th>Trans Mode</th>\n <th>Unnamed: 24</th>\n <th>Unnamed: 25</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>BALTIMORE</td>\n <td>NaN</td>\n <td>24 inch bins</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>4/29/17</td>\n <td>270.0</td>\n <td>280.0</td>\n <td>270.0</td>\n <td>...</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>E</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>1</th>\n <td>BALTIMORE</td>\n <td>NaN</td>\n <td>24 inch bins</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>5/6/17</td>\n <td>270.0</td>\n <td>280.0</td>\n <td>270.0</td>\n <td>...</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>E</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>2</th>\n <td>BALTIMORE</td>\n <td>NaN</td>\n <td>24 inch bins</td>\n <td>HOWDEN TYPE</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>9/24/16</td>\n <td>160.0</td>\n <td>160.0</td>\n <td>160.0</td>\n <td>...</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>N</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>3</th>\n <td>BALTIMORE</td>\n <td>NaN</td>\n <td>24 inch bins</td>\n <td>HOWDEN TYPE</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>9/24/16</td>\n <td>160.0</td>\n <td>160.0</td>\n <td>160.0</td>\n <td>...</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>N</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>4</th>\n <td>BALTIMORE</td>\n <td>NaN</td>\n <td>24 inch bins</td>\n <td>HOWDEN TYPE</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>11/5/16</td>\n <td>90.0</td>\n <td>100.0</td>\n <td>90.0</td>\n <td>...</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>N</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n </tbody>\n</table>\n<p>5 rows × 26 columns</p>\n</div>"
},
"metadata": {},
"execution_count": 1
4 years ago
}
],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"pumpkins = pd.read_csv('../../data/US-pumpkins.csv')\n",
"\n",
"pumpkins.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Month Variety City Package Low Price High Price Price\n",
"70 1 3 1 0 5 3 13.636364\n",
"71 1 3 1 0 10 7 16.363636\n",
"72 2 3 1 0 10 7 16.363636\n",
"73 2 3 1 0 9 6 15.454545\n",
"74 2 3 1 0 5 3 13.636364"
],
"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>Month</th>\n <th>Variety</th>\n <th>City</th>\n <th>Package</th>\n <th>Low Price</th>\n <th>High Price</th>\n <th>Price</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>70</th>\n <td>1</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>5</td>\n <td>3</td>\n <td>13.636364</td>\n </tr>\n <tr>\n <th>71</th>\n <td>1</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>10</td>\n <td>7</td>\n <td>16.363636</td>\n </tr>\n <tr>\n <th>72</th>\n <td>2</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>10</td>\n <td>7</td>\n <td>16.363636</td>\n </tr>\n <tr>\n <th>73</th>\n <td>2</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>9</td>\n <td>6</td>\n <td>15.454545</td>\n </tr>\n <tr>\n <th>74</th>\n <td>2</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>5</td>\n <td>3</td>\n <td>13.636364</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 2
4 years ago
}
],
"source": [
"from sklearn.preprocessing import LabelEncoder\n",
"\n",
"pumpkins = pumpkins[pumpkins['Package'].str.contains('bushel', case=True, regex=True)]\n",
"\n",
"new_columns = ['Package', 'Variety', 'City Name', 'Month', 'Low Price', 'High Price', 'Date']\n",
"\n",
"pumpkins = pumpkins.drop([c for c in pumpkins.columns if c not in new_columns], axis=1)\n",
"\n",
"price = (pumpkins['Low Price'] + pumpkins['High Price']) / 2\n",
"\n",
"month = pd.DatetimeIndex(pumpkins['Date']).month\n",
"\n",
"new_pumpkins = pd.DataFrame({'Month': month, 'Variety': pumpkins['Variety'], 'City': pumpkins['City Name'], 'Package': pumpkins['Package'], 'Low Price': pumpkins['Low Price'],'High Price': pumpkins['High Price'], 'Price': price})\n",
"\n",
"new_pumpkins.loc[new_pumpkins['Package'].str.contains('1 1/9'), 'Price'] = price/1.1\n",
"\n",
"new_pumpkins.loc[new_pumpkins['Package'].str.contains('1/2'), 'Price'] = price*2\n",
"\n",
"new_pumpkins.iloc[:, 0:-1] = new_pumpkins.iloc[:, 0:-1].apply(LabelEncoder().fit_transform)\n",
"\n",
"new_pumpkins.head()\n"
]
},
{
"source": [
"A scatterplot reminds us that we only have month data from August through December. We probably need more data to be able to draw conclusions in a linear fashion."
4 years ago
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 3,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x7fe57097e828>"
4 years ago
]
},
"metadata": {},
"execution_count": 3
4 years ago
},
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"248.518125pt\" version=\"1.1\" viewBox=\"0 0 368.925 248.518125\" width=\"368.925pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M -0 248.518125 \nL 368.925 248.518125 \nL 368.925 0 \nL -0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 26.925 224.64 \nL 361.725 224.64 \nL 361.725 7.2 \nL 26.925 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"PathCollection_1\">\n <defs>\n <path d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" id=\"m6e6fd13ccb\" style=\"stroke:#1f77b4;\"/>\n </defs>\n <g clip-path=\"url(#p5cb0483da8)\">\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"201.41676\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"188.144301\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"188.144301\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"192.568454\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"201.41676\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"188.144301\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"192.568454\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"189.250339\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"201.41676\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"192.568454\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"189.250339\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"201.41676\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"192.568454\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"189.250339\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"201.41676\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"194.780531\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"194.325\" xlink:href=\"#m6e6fd13ccb\" y=\"192.568454\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"188.144301\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"196.992607\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"188.144301\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"196.992607\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"196.992607\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"196.992607\"/>\n <use style=\"fill:#1f77b4;stroke:#1f77b4;\" x=\"118.573479\" xlink:href=\"#m6e6fd13ccb\" y=\"92.58
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAahUlEQVR4nO3df5Bd9Xnf8fdHawFrTCLLLIrQDwtjjZjWqiV7g8So08o4qhjw4A11W6vg4o5rJW08xUMqGwVNYndgIKME3DYZZ8B2rBSC7bHVhQKpqjHSZOIBOStLZsGgymB+LQraGMtgsgaxevrHPStWd+/VnrN77z0/7uc1s7P3PPdczjMHnWfP/Z7vD0UEZmZWPnPyTsDMzGbGBdzMrKRcwM3MSsoF3MyspFzAzcxK6m2dPNi5554by5Yt6+QhzcxKb//+/X8fEX318Y4W8GXLljE0NNTJQ5qZlZ6kZxvF3YRiZlZSLuBmZiXlAm5mVlIu4GZmJeUCbmZWU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WC845wz23bghp4zMixpXzOlmjLtpYGWHsym2ZkuBbd91yAv1NuFiXSy+A68Yz1eRnpcIs7JzAa+YZvPCeb64qbxEmJWdm1Aq5u1n9PDaG1P7fL/9DD/ErLdl4wo++82pKwF6ibDmtg0Oc8++5xmPoEdi05olbprLke/AK6ZR8T5dvJv9/uBwpni32zY4zF2PPHeyOW48grseeY5tPl+5cQG3ruVRq9l4SbXicQE3s1T8gLx4XMDNLBUvqVY8aZZUO0vS9yX9UNLjkr6YxC+QtE/SjyV9U5KHYxWAe6Gk51Gr2WxasyRT3NovzR3468ClEfF+YBVwmaS
4 years ago
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"plt.scatter('Month','Price',data=new_pumpkins)"
4 years ago
]
},
{
"source": [
"Try some different correlations"
],
"cell_type": "markdown",
"metadata": {}
},
4 years ago
{
"cell_type": "code",
"execution_count": 4,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
4 years ago
"0.3236397181608923\n0.6061712937226016\n"
4 years ago
]
}
],
"source": [
"print(new_pumpkins['City'].corr(new_pumpkins['Price']))\n",
"\n",
"print(new_pumpkins['Package'].corr(new_pumpkins['Price']))\n"
4 years ago
]
},
{
"source": [
"Drop unused columns"
],
"cell_type": "markdown",
"metadata": {}
},
4 years ago
{
"cell_type": "code",
"execution_count": 5,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"<class 'pandas.core.frame.DataFrame'>\nInt64Index: 415 entries, 70 to 1742\nData columns (total 7 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 Month 415 non-null int64 \n 1 Variety 415 non-null int64 \n 2 City 415 non-null int64 \n 3 Package 415 non-null int64 \n 4 Low Price 415 non-null int64 \n 5 High Price 415 non-null int64 \n 6 Price 415 non-null float64\ndtypes: float64(1), int64(6)\nmemory usage: 25.9 KB\n"
]
}
],
"source": [
"\n",
"new_pumpkins.dropna(inplace=True)\n",
"new_pumpkins.info()\n",
"\n",
"\n"
]
},
{
"source": [
"Create a new dataframe"
],
"cell_type": "markdown",
"metadata": {}
},
4 years ago
{
"cell_type": "code",
"execution_count": 6,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Package Price\n",
"70 0 13.636364\n",
"71 0 16.363636\n",
"72 0 16.363636\n",
"73 0 15.454545\n",
"74 0 13.636364\n",
4 years ago
"... ... ...\n",
"1738 2 30.000000\n",
"1739 2 28.750000\n",
"1740 2 25.750000\n",
"1741 2 24.000000\n",
"1742 2 24.000000\n",
4 years ago
"\n",
"[415 rows x 2 columns]"
],
"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>Package</th>\n <th>Price</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>70</th>\n <td>0</td>\n <td>13.636364</td>\n </tr>\n <tr>\n <th>71</th>\n <td>0</td>\n <td>16.363636</td>\n </tr>\n <tr>\n <th>72</th>\n <td>0</td>\n <td>16.363636</td>\n </tr>\n <tr>\n <th>73</th>\n <td>0</td>\n <td>15.454545</td>\n </tr>\n <tr>\n <th>74</th>\n <td>0</td>\n <td>13.636364</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>1738</th>\n <td>2</td>\n <td>30.000000</td>\n </tr>\n <tr>\n <th>1739</th>\n <td>2</td>\n <td>28.750000</td>\n </tr>\n <tr>\n <th>1740</th>\n <td>2</td>\n <td>25.750000</td>\n </tr>\n <tr>\n <th>1741</th>\n <td>2</td>\n <td>24.000000</td>\n </tr>\n <tr>\n <th>1742</th>\n <td>2</td>\n <td>24.000000</td>\n </tr>\n </tbody>\n</table>\n<p>415 rows × 2 columns</p>\n</div>"
4 years ago
},
"metadata": {},
"execution_count": 6
4 years ago
}
],
"source": [
"new_columns = ['Package', 'Price']\n",
"lin_pumpkins = new_pumpkins.drop([c for c in new_pumpkins.columns if c not in new_columns], axis='columns')\n",
4 years ago
"\n",
"lin_pumpkins\n"
4 years ago
]
},
{
"source": [
"Set X and y arrays to correspond to Package and Price"
],
"cell_type": "markdown",
"metadata": {}
},
4 years ago
{
"cell_type": "code",
"execution_count": 7,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"X = lin_pumpkins.values[:, :1]\n",
"y = lin_pumpkins.values[:, 1:2]\n"
4 years ago
]
},
{
"cell_type": "code",
"execution_count": 8,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
4 years ago
"Model Accuracy: 0.3315342327998989\n"
4 years ago
]
}
],
"source": [
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error\n",
4 years ago
"from sklearn.model_selection import train_test_split\n",
"\n",
"\n",
4 years ago
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)\n",
4 years ago
"lin_reg = LinearRegression()\n",
"lin_reg.fit(X_train,y_train)\n",
"\n",
"pred = lin_reg.predict(X_test)\n",
"\n",
"accuracy_score = lin_reg.score(X_train,y_train)\n",
4 years ago
"print('Model Accuracy: ', accuracy_score)"
4 years ago
]
},
{
"cell_type": "code",
"execution_count": 9,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"262.19625pt\" version=\"1.1\" viewBox=\"0 0 382.603125 262.19625\" width=\"382.603125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 262.19625 \nL 382.603125 262.19625 \nL 382.603125 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 40.603125 224.64 \nL 375.403125 224.64 \nL 375.403125 7.2 \nL 40.603125 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"PathCollection_1\">\n <defs>\n <path d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" id=\"m88dd73df7b\" style=\"stroke:#000000;\"/>\n </defs>\n <g clip-path=\"url(#p21e702bfe1)\">\n <use style=\"stroke:#000000;\" x=\"283.754646\" xlink:href=\"#m88dd73df7b\" y=\"37.110092\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"167.061394\"/>\n <use style=\"stroke:#000000;\" x=\"359.506166\" xlink:href=\"#m88dd73df7b\" y=\"174.318709\"/>\n <use style=\"stroke:#000000;\" x=\"359.506166\" xlink:href=\"#m88dd73df7b\" y=\"184.297517\"/>\n <use style=\"stroke:#000000;\" x=\"132.251604\" xlink:href=\"#m88dd73df7b\" y=\"187.472593\"/>\n <use style=\"stroke:#000000;\" x=\"132.251604\" xlink:href=\"#m88dd73df7b\" y=\"187.472593\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"192.008415\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"188.606548\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"196.544237\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"119.435262\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"59.562411\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"114.445858\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"119.435262\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"99.477645\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"69.541219\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"198.812148\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"210.151703\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"167.061394\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"192.008415\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"94.488241\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"59.562411\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m88dd73df7b\" y=\"119.435262\"/>\n <use style=\"stroke:#000000;\" x=\"283.754646\" xlink:href=\"#m88dd73df7b\" y=\"87.004134\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"202.214015\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"192.008415\"/>\n <use style=\"stroke:#000000;\" x=\"56.500084\" xlink:href=\"#m88dd73df7b\" y=\"187.472593\"/>\n <use style=\"stroke:#000000;\" x=\"208.00312
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAffUlEQVR4nO3de5BkZZnn8e+vq1qlhOFaMr1gVSIYS3Tj0ErJ4rgq0o3DKKE4ugZGobigKV2wq+HgtWJXd2NqZowYRdaJrjHlzqQDDurIos5INzCAoyzV0HJp3BW1q4Ro6eYuFgFW9rN/5Kmu6uqsqjzZefL6+0RkdOab5+R56kA+9dbznvO+igjMzKx7rGh2AGZm1lhO/GZmXcaJ38ysyzjxm5l1GSd+M7Mu09vsAKpxxBFHRC6Xa3YYZmZtZcuWLY9HRP/C9rZI/LlcjomJiWaHYWbWViRNVmp3qcfMrMs48ZuZdRknfjOzLuPEb2bWZZz4zcy6jBO/mWWuWCySy+VYsWIFuVyOYrHY7JC6Wltczmlm7atYLJLP55mengZgcnKSfD4PwPDwcDND61ru8ZtZpkZHR/ck/VnT09OMjo42KSLLtMcvaTvwW6AEzETEkKTDgOuBHLAdeF9EPJVlHGbWPFNTU6naLXuN6PG/NSLWRsRQ8vozwOaIeDWwOXltZh1qYGAgVbtlrxmlnncBVyfPrwbOakIMZtYgY2Nj9PX17dXW19fH2NhYkyKyrBN/AD+UtEVSPmk7MiJ2JM9/AxxZaUdJeUkTkiZ27dqVcZhmlpXh4WEKhQKDg4NIYnBwkEKh4IH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"light"
}
4 years ago
}
],
"source": [
"\n",
"plt.scatter(X_test, y_test, color='black')\n",
"plt.plot(X_test, pred, color='blue', linewidth=3)\n",
"\n",
"plt.xlabel('Package')\n",
"plt.ylabel('Price')\n",
4 years ago
"\n",
"plt.show()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
4 years ago
"array([[33.15655975]])"
]
},
"metadata": {},
"execution_count": 10
}
],
"source": [
4 years ago
"lin_reg.predict( np.array([ [2.75] ]) )"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Month Variety City Package Price\n",
"70 1 3 1 0 13.636364\n",
"71 1 3 1 0 16.363636\n",
"72 2 3 1 0 16.363636\n",
"73 2 3 1 0 15.454545\n",
"74 2 3 1 0 13.636364\n",
"... ... ... ... ... ...\n",
"1738 1 1 9 2 30.000000\n",
"1739 1 1 9 2 28.750000\n",
"1740 1 1 9 2 25.750000\n",
"1741 1 1 9 2 24.000000\n",
"1742 1 1 9 2 24.000000\n",
"\n",
"[415 rows x 5 columns]"
],
"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>Month</th>\n <th>Variety</th>\n <th>City</th>\n <th>Package</th>\n <th>Price</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>70</th>\n <td>1</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>13.636364</td>\n </tr>\n <tr>\n <th>71</th>\n <td>1</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>16.363636</td>\n </tr>\n <tr>\n <th>72</th>\n <td>2</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>16.363636</td>\n </tr>\n <tr>\n <th>73</th>\n <td>2</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>15.454545</td>\n </tr>\n <tr>\n <th>74</th>\n <td>2</td>\n <td>3</td>\n <td>1</td>\n <td>0</td>\n <td>13.636364</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>1738</th>\n <td>1</td>\n <td>1</td>\n <td>9</td>\n <td>2</td>\n <td>30.000000</td>\n </tr>\n <tr>\n <th>1739</th>\n <td>1</td>\n <td>1</td>\n <td>9</td>\n <td>2</td>\n <td>28.750000</td>\n </tr>\n <tr>\n <th>1740</th>\n <td>1</td>\n <td>1</td>\n <td>9</td>\n <td>2</td>\n <td>25.750000</td>\n </tr>\n <tr>\n <th>1741</th>\n <td>1</td>\n <td>1</td>\n <td>9</td>\n <td>2</td>\n <td>24.000000</td>\n </tr>\n <tr>\n <th>1742</th>\n <td>1</td>\n <td>1</td>\n <td>9</td>\n <td>2</td>\n <td>24.000000</td>\n </tr>\n </tbody>\n</table>\n<p>415 rows × 5 columns</p>\n</div>"
},
"metadata": {},
"execution_count": 11
}
],
"source": [
"new_columns = ['Variety', 'Package', 'City', 'Month', 'Price']\n",
"poly_pumpkins = new_pumpkins.drop([c for c in new_pumpkins.columns if c not in new_columns], axis='columns')\n",
"\n",
"poly_pumpkins"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<pandas.io.formats.style.Styler at 0x7fe5709abfd0>"
],
"text/html": "<style type=\"text/css\" >\n#T_374540ec_b1df_11eb_9c12_acde48001122row0_col0,#T_374540ec_b1df_11eb_9c12_acde48001122row1_col1,#T_374540ec_b1df_11eb_9c12_acde48001122row2_col2,#T_374540ec_b1df_11eb_9c12_acde48001122row3_col3,#T_374540ec_b1df_11eb_9c12_acde48001122row4_col4{\n background-color: #b40426;\n color: #f1f1f1;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row0_col1{\n background-color: #ead4c8;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row0_col2{\n background-color: #4961d2;\n color: #f1f1f1;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row0_col3{\n background-color: #9bbcff;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row0_col4{\n background-color: #bbd1f8;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row1_col0{\n background-color: #9fbfff;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row1_col2,#T_374540ec_b1df_11eb_9c12_acde48001122row1_col3,#T_374540ec_b1df_11eb_9c12_acde48001122row1_col4,#T_374540ec_b1df_11eb_9c12_acde48001122row2_col0,#T_374540ec_b1df_11eb_9c12_acde48001122row4_col1{\n background-color: #3b4cc0;\n color: #f1f1f1;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row2_col1{\n background-color: #a9c6fd;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row2_col3{\n background-color: #edd2c3;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row2_col4{\n background-color: #f5c0a7;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row3_col0{\n background-color: #455cce;\n color: #f1f1f1;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row3_col1{\n background-color: #6485ec;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row3_col2{\n background-color: #ccd9ed;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row3_col4{\n background-color: #f08a6c;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row4_col0{\n background-color: #445acc;\n color: #f1f1f1;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row4_col2{\n background-color: #d2dbe8;\n color: #000000;\n }#T_374540ec_b1df_11eb_9c12_acde48001122row4_col3{\n background-color: #f39778;\n color: #000000;\n }</style><table id=\"T_374540ec_b1df_11eb_9c12_acde48001122\" ><thead> <tr> <th class=\"blank level0\" ></th> <th class=\"col_heading level0 col0\" >Month</th> <th class=\"col_heading level0 col1\" >Variety</th> <th class=\"col_heading level0 col2\" >City</th> <th class=\"col_heading level0 col3\" >Package</th> <th class=\"col_heading level0 col4\" >Price</th> </tr></thead><tbody>\n <tr>\n <th id=\"T_374540ec_b1df_11eb_9c12_acde48001122level0_row0\" class=\"row_heading level0 row0\" >Month</th>\n <td id=\"T_374540ec_b1df_11eb_9c12_acde48001122row0_col0\" class=\"data row0 col0\" >1.000000</td>\n <td id=\"T_374540ec_b1df_11eb_9c12_acde48001122row0_col1\" class=\"data row0 col1\" >0.171330</td>\n <td id=\"T_374540ec_b1df_11eb_9c12_acde48001122row0_col2\" class=\"data row0 col2\" >-0.188728</td>\n <td id=\"T_374540ec_b1df_11eb_9c12_acde48001122row0_col3\" class=\"data row0 col3\" >-0.144847</td>\n <td id=\"T_374540ec_b1df_11eb_9c12_acde48001122row0_col4\" class=\"data row0 col4\" >-0.148783</td>\n </tr>\n <tr>\n <th id=\"T_374540ec_b1df_11eb_9c12_acde48001122level0_row1\" class=\"row_heading level0 row1\" >Variety</th>\n <td id=\"T_374540ec_b1d
},
"metadata": {},
"execution_count": 12
}
],
"source": [
"corr = poly_pumpkins.corr()\n",
"corr.style.background_gradient(cmap='coolwarm')"
]
},
{
"source": [
"Select the Package/Price columns"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"X=poly_pumpkins.iloc[:,3:4].values\n",
"y=poly_pumpkins.iloc[:,4:5].values\n"
]
},
{
"source": [
"Create Polynomial Regression model"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"262.19625pt\" version=\"1.1\" viewBox=\"0 0 382.603125 262.19625\" width=\"382.603125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 262.19625 \nL 382.603125 262.19625 \nL 382.603125 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 40.603125 224.64 \nL 375.403125 224.64 \nL 375.403125 7.2 \nL 40.603125 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"PathCollection_1\">\n <defs>\n <path d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" id=\"m903ea3a5b7\" style=\"stroke:#000000;\"/>\n </defs>\n <g clip-path=\"url(#p48264b39a0)\">\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"199.44082\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"186.475104\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"186.475104\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"190.79701\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"199.44082\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"186.475104\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"190.79701\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"187.555581\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"199.44082\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"190.79701\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"187.555581\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"199.44082\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"190.79701\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"187.555581\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"199.44082\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"192.957962\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"190.79701\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"186.475104\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"195.118915\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"186.475104\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"195.118915\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"195.118915\"/>\n <use style=\"stroke:#000000;\" x=\"58.76331\" xlink:href=\"#m903ea3a5b7\" y=\"195.118915\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m903ea3a5b7\" y=\"93.121949\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m903ea3a5b7\" y=\"121.646525\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m903ea3a5b7\" y=\"93.121949\"/>\n <use style=\"stroke:#000000;\" x=\"208.003125\" xlink:href=\"#m903ea3a5b7\" y=\"121.
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3deXxU1f3/8dcnCVsUCwpaiCXRilawLhVRq1VL61J3rTutC2qUYN2KG6lbK1+xRcXaokalxRrcKK61tVapWn9uuFAFW8Ul1CCLCm5BIMn5/XHucJOQkJkk997JzPv5eMwj95zMzP1kYD5z56zmnENERPJHQdIBiIhIvJT4RUTyjBK/iEieUeIXEckzSvwiInmmKOkA0jFgwABXVlaWdBgiIt3Kyy+//JFzbmDL+m6R+MvKypgzZ07SYYiIdCtmVtNavZp6RETyjBK/iEieUeIXEckzSvwiInlGiV9EJM8o8YuI5BklfhGRPKPELyKSZ5T4RSRS1dXVlJWVUVBQQFlZGdXV1UmHlPe6xcxdEemeqqurKS8vp66uDoCamhrKy8sBGD16dJKh5TVd8YtIZCorK9cm/Z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CqGESiEPcEroYGv+H5qaf6pZXBD2ucPRtGj47klN3KuHGwxx7+uL7eN/mkOruldUlcJ1wEnG9mC/Bt/tpRU7qduCZwff65n7E6eXJYt/32fjnl3XeP5JTdTkGB37SlVy9ffuWV5q+XrCuWxO+c+6dz7uDg+F3n3Ejn3FbOuaOdc+qOEWnF++/
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"from sklearn.preprocessing import PolynomialFeatures\n",
"from sklearn.pipeline import make_pipeline\n",
"\n",
"pipeline = make_pipeline(PolynomialFeatures(4), LinearRegression())\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)\n",
"\n",
"pipeline.fit(np.array(X_train), y_train)\n",
"\n",
"y_pred=pipeline.predict(X_test)\n",
"\n",
"df = pd.DataFrame({'x': X_test[:,0], 'y': y_pred[:,0]})\n",
"df.sort_values(by='x',inplace = True)\n",
"points = pd.DataFrame(df).to_numpy()\n",
"\n",
4 years ago
"plt.plot(points[:, 0], points[:, 1],color=\"blue\", linewidth=3)\n",
"plt.xlabel('Package')\n",
"plt.ylabel('Price')\n",
"\n",
"plt.scatter(X,y, color=\"black\")\n",
"\n",
"plt.show()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Model Accuracy: 0.8537946517073784\n"
]
}
],
"source": [
"accuracy_score = pipeline.score(X_train,y_train)\n",
"print('Model Accuracy: ', accuracy_score)\n",
"\n"
]
},
4 years ago
{
"cell_type": "code",
"execution_count": 16,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[46.34509342]])"
]
},
"metadata": {},
"execution_count": 16
4 years ago
}
],
"source": [
"pipeline.predict( np.array([ [2.75] ]) )"
]
},
4 years ago
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
]
}