chore: bump version to 1.0.13

This commit is contained in:
2024-06-15 18:46:19 -04:00
parent eb4ad2a8c2
commit 945aa1e2b9
25 changed files with 22536 additions and 79 deletions
@@ -0,0 +1,284 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "ZbwpTMgRjUMS",
"outputId": "7fca63af-b277-4dad-bc59-44ad128cb10a"
},
"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>Sales</th>\n",
" <th>Temperature</th>\n",
" <th>Advertising</th>\n",
" <th>Discount</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>17235</td>\n",
" <td>33</td>\n",
" <td>15</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>19854</td>\n",
" <td>42</td>\n",
" <td>25</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>45786</td>\n",
" <td>58</td>\n",
" <td>40</td>\n",
" <td>10.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>49745</td>\n",
" <td>67</td>\n",
" <td>70</td>\n",
" <td>20.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>65894</td>\n",
" <td>73</td>\n",
" <td>75</td>\n",
" <td>20.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Sales Temperature Advertising Discount\n",
"0 17235 33 15 5.0\n",
"1 19854 42 25 5.0\n",
"2 45786 58 40 10.0\n",
"3 49745 67 70 20.0\n",
"4 65894 73 75 20.0"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from mlModelSaver import MlModelSaver\n",
"from helpers import add_constant_column\n",
"\n",
"mowersDf = pd.read_excel('https://www.dropbox.com/scl/fi/y2rktyoqb8rrshrnlpvw1/Mowers.xlsx?rlkey=e5bi1d8sx5hml4ylfkjv7cryh&dl=1')\n",
"mowersDf.head()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "SPmxr6rde0Od"
},
"outputs": [],
"source": [
"# https://www.statsmodels.org/stable/index.html\n",
"import statsmodels.api as sm\n",
"# Your answer"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "4jjcJF3SfX-h",
"outputId": "dac6566b-1320-48ca-db70-712d4a7ff82b"
},
"outputs": [],
"source": [
"modelPredictSaleByTemperatureAdvertisingDiscount = sm.OLS(\n",
" mowersDf[\"Sales\"],\n",
" add_constant_column(mowersDf[[\"Temperature\", \"Advertising\", \"Discount\"]])\n",
")\n",
"modelPredictSaleByTemperatureAdvertisingDiscountFit = modelPredictSaleByTemperatureAdvertisingDiscount.fit()\n",
"# print(modelPredictSaleByTemperatureAdvertisingDiscountFit.summary())"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<statsmodels.regression.linear_model.RegressionResultsWrapper at 0x12e499550>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from mlModelSaver import MlModelSaver\n",
"mlModelSaverInstance = MlModelSaver({\n",
" \"baseRelativePath\": \"..\",\n",
" \"modelsFolder\": \"~~tmp/testModels\"\n",
"})\n",
"\n",
"loadedModel = mlModelSaverInstance.exportModel(\n",
" modelPredictSaleByTemperatureAdvertisingDiscountFit,\n",
" {\n",
" \"modelName\": \"modelPredictSaleByTemperatureAdvertisingDiscountFit\",\n",
" \"description\": \"modelPredictSaleByTemperatureAdvertisingDiscountFit\",\n",
" \"modelType\": \"sm.OLS\",\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"Temperature\",\n",
" \"type\": \"float\",\n",
" },\n",
" {\n",
" \"name\": \"Advertising\",\n",
" \"type\": \"float\"\n",
" },\n",
" {\n",
" \"name\": \"Discount\",\n",
" \"type\": \"float\"\n",
" }\n",
" ],\n",
" \"transformer\": add_constant_column,\n",
" \"outputs\": [\n",
" {\n",
" \"name\": \"Sales\",\n",
" \"type\": \"float\"\n",
" }\n",
" ]\n",
" }\n",
")\n",
"loadedModel"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"\n",
"testData = [{\n",
" 'Temperature': 42,\n",
" 'Advertising': 15,\n",
" 'Discount': 5\n",
"}]\n",
"\n",
"# Create a DataFrame from the dictionary\n",
"testDf = pd.DataFrame(testData)\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 19590.46727\n",
"dtype: float64"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"modelPredictSaleByTemperatureAdvertisingDiscountFit.predict( add_constant_column(testDf))\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'Sales': 19590.467270313893}]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loadedModel.mlModelSavePredict(testDf)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4YoK17TkeGCw"
},
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
+284
View File
@@ -0,0 +1,284 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "ZbwpTMgRjUMS",
"outputId": "7fca63af-b277-4dad-bc59-44ad128cb10a"
},
"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>Sales</th>\n",
" <th>Temperature</th>\n",
" <th>Advertising</th>\n",
" <th>Discount</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>17235</td>\n",
" <td>33</td>\n",
" <td>15</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>19854</td>\n",
" <td>42</td>\n",
" <td>25</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>45786</td>\n",
" <td>58</td>\n",
" <td>40</td>\n",
" <td>10.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>49745</td>\n",
" <td>67</td>\n",
" <td>70</td>\n",
" <td>20.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>65894</td>\n",
" <td>73</td>\n",
" <td>75</td>\n",
" <td>20.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Sales Temperature Advertising Discount\n",
"0 17235 33 15 5.0\n",
"1 19854 42 25 5.0\n",
"2 45786 58 40 10.0\n",
"3 49745 67 70 20.0\n",
"4 65894 73 75 20.0"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from mlModelSaver import MlModelSaver\n",
"from helpers import add_constant_column\n",
"\n",
"mowersDf = pd.read_excel('https://www.dropbox.com/scl/fi/y2rktyoqb8rrshrnlpvw1/Mowers.xlsx?rlkey=e5bi1d8sx5hml4ylfkjv7cryh&dl=1')\n",
"mowersDf.head()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "SPmxr6rde0Od"
},
"outputs": [],
"source": [
"# https://www.statsmodels.org/stable/index.html\n",
"import statsmodels.api as sm\n",
"# Your answer"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "4jjcJF3SfX-h",
"outputId": "dac6566b-1320-48ca-db70-712d4a7ff82b"
},
"outputs": [],
"source": [
"modelPredictSaleByTemperatureAdvertisingDiscount = sm.OLS(\n",
" mowersDf[\"Sales\"],\n",
" add_constant_column(mowersDf[[\"Temperature\", \"Advertising\", \"Discount\"]])\n",
")\n",
"modelPredictSaleByTemperatureAdvertisingDiscountFit = modelPredictSaleByTemperatureAdvertisingDiscount.fit()\n",
"# print(modelPredictSaleByTemperatureAdvertisingDiscountFit.summary())"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<statsmodels.regression.linear_model.RegressionResultsWrapper at 0x12e499550>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from mlModelSaver import MlModelSaver\n",
"mlModelSaverInstance = MlModelSaver({\n",
" \"baseRelativePath\": \"..\",\n",
" \"modelsFolder\": \"~~tmp/testModels\"\n",
"})\n",
"\n",
"loadedModel = mlModelSaverInstance.exportModel(\n",
" modelPredictSaleByTemperatureAdvertisingDiscountFit,\n",
" {\n",
" \"modelName\": \"modelPredictSaleByTemperatureAdvertisingDiscountFit\",\n",
" \"description\": \"modelPredictSaleByTemperatureAdvertisingDiscountFit\",\n",
" \"modelType\": \"sm.OLS\",\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"Temperature\",\n",
" \"type\": \"float\",\n",
" },\n",
" {\n",
" \"name\": \"Advertising\",\n",
" \"type\": \"float\"\n",
" },\n",
" {\n",
" \"name\": \"Discount\",\n",
" \"type\": \"float\"\n",
" }\n",
" ],\n",
" \"transformer\": add_constant_column,\n",
" \"outputs\": [\n",
" {\n",
" \"name\": \"Sales\",\n",
" \"type\": \"float\"\n",
" }\n",
" ]\n",
" }\n",
")\n",
"loadedModel"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"\n",
"testData = [{\n",
" 'Temperature': 42,\n",
" 'Advertising': 15,\n",
" 'Discount': 5\n",
"}]\n",
"\n",
"# Create a DataFrame from the dictionary\n",
"testDf = pd.DataFrame(testData)\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 19590.46727\n",
"dtype: float64"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"modelPredictSaleByTemperatureAdvertisingDiscountFit.predict( add_constant_column(testDf))\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'Sales': 19590.467270313893}]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loadedModel.mlModelSavePredict(testDf)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4YoK17TkeGCw"
},
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
+4
View File
@@ -0,0 +1,4 @@
```
pip install jupyterlab
pip install notebook
```
+170
View File
@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"id": "1a33d2cd-5d9f-40a6-bc28-5b2e8026226c",
"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>A</th>\n",
" <th>B</th>\n",
" <th>C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>7</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1 4 7"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"# Example DataFrame\n",
"data = {\n",
" 'A': [1, 2, 3],\n",
" 'B': [4, 5, 6],\n",
" 'C': [7, 8, 9]\n",
"}\n",
"df = pd.DataFrame(data)\n",
"\n",
"# Create a new DataFrame with only the first row using .iloc[0:1]\n",
"first_row_df = df.iloc[0:1]\n",
"first_row_df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "51c38582-bccf-4e03-918f-9d65bbec1dda",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"New DataFrame with First Row:\n"
]
},
{
"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>A</th>\n",
" <th>B</th>\n",
" <th>C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>7</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1 4 7"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a new DataFrame with only the first row using .head(1)\n",
"first_row_df = df.head(1)\n",
"\n",
"print(\"New DataFrame with First Row:\")\n",
"first_row_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "664e8423-f560-4c23-8a94-242f8ec283cd",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+701
View File
@@ -0,0 +1,701 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xwFyEsosINqT"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "pKewSQysItJ-"
},
"outputs": [],
"source": [
"# https://www.statsmodels.org/stable/index.html\n",
"import statsmodels.api as sm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Lz-DyAtNWsJR"
},
"outputs": [],
"source": [
"# Download Dataset from https://www.dropbox.com/scl/fi/bkcdp9tpqqh6dfr6phtt8/AnnArbor.xlsx?rlkey=0agfqwc7f0kt7oqb3e2h6q3qs&dl=1\n",
"# and add it to colab"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0zM8FGMJXJ70"
},
"outputs": [],
"source": [
"# annArborDf = pd.read_excel(\"./AnnArbor.xlsx\")\n",
"annArborDf = pd.read_excel(\"https://www.dropbox.com/scl/fi/bkcdp9tpqqh6dfr6phtt8/AnnArbor.xlsx?rlkey=0agfqwc7f0kt7oqb3e2h6q3qs&dl=1\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "t0LUca0Myqw5",
"outputId": "249ab087-895f-4fa6-993e-e8dd50ef87c1"
},
"outputs": [],
"source": [
"annArborDf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "GQRNPIeyy6ub",
"outputId": "00211933-f2b1-40c6-d9cf-187560ffa305"
},
"outputs": [],
"source": [
"annArborDf.size"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "yumMybniy85d"
},
"outputs": [],
"source": [
"annArborDf.describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "aspq6hoPy_xZ",
"outputId": "96892272-a1d5-400e-a177-6c96746619d8"
},
"outputs": [],
"source": [
"annArborDf.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "z_hVTvPrzYJr"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"id": "pIniVuaIzaaZ",
"outputId": "6a061f6a-8bff-42c0-d705-0c2bd06eb5ff"
},
"outputs": [],
"source": [
"# Plotting\n",
"fig1 = plt.figure(\n",
" figsize=(8, 8)\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 449
},
"id": "VHdpDE7o42Pf",
"outputId": "ac876802-b6d1-4926-d069-0532ee9e7a0b"
},
"outputs": [],
"source": [
"plt.scatter(\n",
" annArborDf[\"Beds\"],\n",
" annArborDf[\"Rent\"],\n",
" color='blue',\n",
" alpha=0.9,\n",
" label='Data Points - scatter',\n",
")\n",
"\n",
"plt.xlabel('Beds')\n",
"plt.ylabel('Rent')\n",
"plt.legend()\n",
"plt.grid(True)\n",
"\n",
"\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 449
},
"id": "knAa4W9R47rZ",
"outputId": "81359d91-03b7-4f70-c381-c88172f800a9"
},
"outputs": [],
"source": [
"plt.scatter(\n",
" annArborDf[\"Baths\"],\n",
" annArborDf[\"Rent\"],\n",
" color='blue',\n",
" alpha=0.9,\n",
" label='Data Points - scatter',\n",
")\n",
"\n",
"plt.xlabel('Baths')\n",
"plt.ylabel('Rent')\n",
"plt.legend()\n",
"plt.grid(True)\n",
"\n",
"\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 449
},
"id": "dOnWJbFOzczV",
"outputId": "c6d6b86b-dd85-45d1-b543-928441c11dc4"
},
"outputs": [],
"source": [
"plt.scatter(\n",
" annArborDf[\"Sqft\"],\n",
" annArborDf[\"Rent\"],\n",
" color='blue',\n",
" alpha=0.9,\n",
" label='Data Points - scatter',\n",
")\n",
"\n",
"plt.xlabel('Sqft')\n",
"plt.ylabel('Rent')\n",
"plt.legend()\n",
"plt.grid(True)\n",
"\n",
"\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "alIhUPPUzvli",
"outputId": "8ed14c4b-a596-49ac-912a-0dcb4145df89"
},
"outputs": [],
"source": [
"rentSqftModel1 = sm.OLS(\n",
" annArborDf[\"Rent\"],\n",
" sm.add_constant(annArborDf[[\"Sqft\"]])\n",
")\n",
"rentSqftModel1Fit = rentSqftModel1.fit()\n",
"print(rentSqftModel1Fit.summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from functions.exportModel import exportModel\n",
"exportModel({\n",
" \"modelName\": \"rentSqftModel1Fit\",\n",
" \"model\": rentSqftModel1Fit,\n",
" \"description\": \"Predict Rent based on Sqft for annArborDf\",\n",
" \"modelType\": \"sm.OLS\",\n",
" \"baseRelativePath\": \"..\",\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"const\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Sqft\",\n",
" \"type\": \"float\"\n",
" }\n",
" ],\n",
" \"output\": {\n",
" \"name\": \"Rent\",\n",
" \"type\": \"float\"\n",
" }\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "S-AyfiLN0Due",
"outputId": "aacd248d-5a72-4ce0-ab0a-048f30d398ca"
},
"outputs": [],
"source": [
"predictedRent1 = rentSqftModel1Fit.predict(sm.add_constant(annArborDf[\"Sqft\"]))\n",
"annArborDf['predictedRent1'] = predictedRent1\n",
"annArborDf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "9ouX-mzz4sl-"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 454
},
"id": "L55GN8hZ4wXi",
"outputId": "712ace2c-5a04-48e0-acf0-cc42430f2aa9"
},
"outputs": [],
"source": [
"plt.scatter(\n",
" annArborDf[\"Rent\"],\n",
" annArborDf[\"Sqft\"],\n",
" color='blue',\n",
" alpha=0.5,\n",
" label='Data Points - scatter',\n",
")\n",
"\n",
"intercept = rentSqftModel1Fit.params['const']\n",
"sqFtSlope = rentSqftModel1Fit.params['Sqft']\n",
"x_values = np.linspace(500, 4500, 200)\n",
"y_values = intercept + sqFtSlope * x_values\n",
"\n",
"plt.plot(\n",
" x_values,\n",
" y_values,\n",
" color='red',\n",
" label='rentSqftModel1Fit - predictedRent1'\n",
")\n",
"plt.xlabel('Sqft')\n",
"plt.ylabel('Rent')\n",
"plt.legend()\n",
"plt.grid(True)\n",
"\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "swSVnmy44Ddg",
"outputId": "251afab3-0563-4eb7-e23a-b526238c7584"
},
"outputs": [],
"source": [
"rentBedsBathsSqftModel = sm.OLS(\n",
" annArborDf[\"Rent\"],\n",
" sm.add_constant(annArborDf[[\"Beds\", \"Baths\", \"Sqft\"]])\n",
")\n",
"rentBedsBathsSqftModelFit = rentBedsBathsSqftModel.fit()\n",
"print(rentBedsBathsSqftModelFit.summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from functions.exportModel import exportModel\n",
"exportModel({\n",
" \"modelName\": \"rentBedsBathsSqftModelFit\",\n",
" \"model\": rentBedsBathsSqftModelFit,\n",
" \"description\": \"Predict Rent based on Beds,Baths,Sqft for annArborDf\",\n",
" \"modelType\": \"sm.OLS\",\n",
" \"baseRelativePath\": \"..\",\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"const\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Beds\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Baths\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Sqft\",\n",
" \"type\": \"float\"\n",
" }\n",
" \n",
" ],\n",
" \"output\": {\n",
" \"name\": \"Rent\",\n",
" \"type\": \"float\"\n",
" }\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "6lKEw7Wt57Px"
},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "da3o51IG5u7r",
"outputId": "abe849ba-7689-468c-f327-b183c4d3f70a"
},
"outputs": [],
"source": [
"from functions.transformers import transformersDict\n",
"# annArborDf['log(Sqft)'] = annArborDf.apply(lambda row: math.log(row['Sqft']), axis=1)\n",
"annArborDf['log(Sqft)'] = annArborDf.apply(transformersDict.get('Sqft_log'), axis=1)\n",
"annArborDf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "lYYrtI0O5lSG",
"outputId": "6a980e88-5630-4e5e-f887-875ab5f1d748"
},
"outputs": [],
"source": [
"rentBedsBathsLogSqftModel= sm.OLS(\n",
" annArborDf[\"Rent\"],\n",
" sm.add_constant(annArborDf[[\"Beds\", \"Baths\", \"log(Sqft)\"]])\n",
")\n",
"rentBedsBathsLogSqftModelFit = rentBedsBathsLogSqftModel.fit()\n",
"print(rentBedsBathsLogSqftModelFit.summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from functions.exportModel import exportModel\n",
"exportModel({\n",
" \"modelName\": \"rentBedsBathsLogSqftModelFit\",\n",
" \"model\": rentBedsBathsLogSqftModelFit,\n",
" \"description\": \"Predict Rent based on Beds,Baths,log(Sqft) for annArborDf\",\n",
" \"modelType\": \"sm.OLS\",\n",
" \"baseRelativePath\": \"..\",\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"const\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Beds\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Baths\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Sqft\",\n",
" \"type\": \"float\"\n",
" }\n",
" \n",
" ],\n",
" \"transformers\":[\n",
" {\n",
" \"name\": \"log(Sqft)\",\n",
" \"transformer\": \"Sqft_log\"\n",
" }\n",
" ],\n",
" \"output\": {\n",
" \"name\": \"Rent\",\n",
" \"type\": \"float\"\n",
" }\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "amUWG6386dyn"
},
"outputs": [],
"source": [
"annArborDf['log(Rent)'] = annArborDf.apply(lambda row: math.log(row['Rent']), axis=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "LxcjPBLn6iAq",
"outputId": "f827bc12-0083-4fb9-ea95-53a58cc0999b"
},
"outputs": [],
"source": [
"rentSqftModel4 = sm.OLS(\n",
" annArborDf[\"log(Rent)\"],\n",
" sm.add_constant(annArborDf[[\"Beds\", \"Baths\", \"Sqft\"]])\n",
")\n",
"rentSqftModel4Fit = rentSqftModel4.fit()\n",
"print(rentSqftModel4Fit.summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WM5h3QnN60IY",
"outputId": "56dd02c1-b8a8-4fcc-951f-676d574e6a62"
},
"outputs": [],
"source": [
"logRentBedsBathsLogSqftModel = sm.OLS(\n",
" annArborDf[\"log(Rent)\"],\n",
" sm.add_constant(annArborDf[[\"Beds\", \"Baths\", \"log(Sqft)\"]])\n",
")\n",
"logRentBedsBathsLogSqftModelFit = logRentBedsBathsLogSqftModel.fit()\n",
"print(logRentBedsBathsLogSqftModelFit.summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from functions.exportModel import exportModel\n",
"exportModel({\n",
" \"modelName\": \"logRentBedsBathsLogSqftModelFit\",\n",
" \"model\": logRentBedsBathsLogSqftModelFit,\n",
" \"description\": \"Predict log(Rent) based on Beds,Baths,log(Sqft) for annArborDf\",\n",
" \"modelType\": \"sm.OLS\",\n",
" \"baseRelativePath\": \"..\",\n",
" \"inputs\": [\n",
" {\n",
" \"name\": \"const\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Beds\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Baths\",\n",
" \"type\": \"int\"\n",
" },\n",
" {\n",
" \"name\": \"Sqft\",\n",
" \"type\": \"float\"\n",
" }\n",
" \n",
" ],\n",
" \"transformers\":[\n",
" {\n",
" \"name\": \"log(Sqft)\",\n",
" \"transformer\": \"Sqft_log\"\n",
" }\n",
" ],\n",
" \"output\": {\n",
" \"name\": \"log(Rent)\",\n",
" \"type\": \"float\"\n",
" }\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "1PHrUcM6694a",
"outputId": "7b463d70-25d1-4073-bf7e-4e93f31c5fb2"
},
"outputs": [],
"source": [
"rentSqftModel6 = sm.OLS(\n",
" annArborDf[\"log(Rent)\"],\n",
" sm.add_constant(annArborDf[[\"Beds\", \"log(Sqft)\"]])\n",
")\n",
"rentSqftModel6Fit = rentSqftModel6.fit()\n",
"print(rentSqftModel6Fit.summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 430
},
"id": "BybWTp_k7hzc",
"outputId": "335b1499-534c-47d2-bdb6-7c0f3b456160"
},
"outputs": [],
"source": [
"# plt.scatter(\n",
"# annArborDf[\"Sqft\"],\n",
"# annArborDf[\"Rent\"],\n",
"# color='blue',\n",
"# alpha=0.9,\n",
"# label='Data Points - scatter',\n",
"# )\n",
"\n",
"plt.scatter(\n",
" annArborDf[\"log(Sqft)\"],\n",
" annArborDf[\"Rent\"],\n",
" color='red',\n",
" alpha=0.9,\n",
" label='Data Points - scatter',\n",
")\n",
"\n",
"# plt.scatter(\n",
"# annArborDf[\"log(Sqft)\"],\n",
"# annArborDf[\"log(Rent)\"],\n",
"# color='Green',\n",
"# alpha=0.9,\n",
"# label='Data Points - scatter',\n",
"# )\n",
"\n",
"# plt.scatter(\n",
"# annArborDf[\"Sqft\"],\n",
"# annArborDf[\"log(Rent)\"],\n",
"# color='Yellow',\n",
"# alpha=0.9,\n",
"# label='Data Points - scatter',\n",
"# )\n",
"\n",
"\n",
"\n",
"# plt.xlabel('Sqft')\n",
"plt.ylabel('Rent')\n",
"plt.legend()\n",
"plt.grid(True)\n",
"\n",
"\n",
"\n",
"plt.show()"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long