Skip to content

Commit

Permalink
Update python-linear-model-overfitting.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
vsyrgkanis committed Jun 28, 2024
1 parent e60fcef commit a4d5d6c
Showing 1 changed file with 101 additions and 1 deletion.
102 changes: 101 additions & 1 deletion PM1/python-linear-model-overfitting.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
{"cells":[{"cell_type":"markdown","metadata":{"_execution_state":"idle","_uuid":"051d70d956493feee0c6d64651c6a088724dca2a","id":"GC3FBi5L7OLq","papermill":{"duration":0.005457,"end_time":"2021-02-10T13:42:51.332609","exception":false,"start_time":"2021-02-10T13:42:51.327152","status":"completed"},"tags":[]},"source":["# Simple Exercise on Overfitting\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"YTaOmenI7TfT"},"outputs":[],"source":["import numpy as np\n","import statsmodels.api as sm\n","\n","def regression_stats(n,p):\n"," np.random.seed(123)\n"," X = np.random.normal(size=(n,p))\n"," y = np.random.normal(size=(n,1))\n"," print(f\"p/n is: {p/n if n != 0 else np.inf}\")\n"," print(f\"R^2 is {sm.OLS(y, X).fit().rsquared}\")\n"," print(f\"Adjusted R^2 is {sm.OLS(y, X).fit().rsquared_adj}\")"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"C57WYtYM7OL0","papermill":{"duration":0.998738,"end_time":"2021-02-10T13:42:52.344388","exception":false,"start_time":"2021-02-10T13:42:51.345650","status":"completed"},"tags":[]},"outputs":[],"source":["regression_stats(1000, 1000)\n","regression_stats(1000, 500)\n","regression_stats(1000, 50)"]}],"metadata":{"colab":{"provenance":[]},"kernelspec":{"display_name":"Python 3","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.8.7"},"papermill":{"default_parameters":{},"duration":4.940504,"end_time":"2021-02-10T13:42:53.102123","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2021-02-10T13:42:48.161619","version":"2.2.2"}},"nbformat":4,"nbformat_minor":0}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"_execution_state": "idle",
"_uuid": "051d70d956493feee0c6d64651c6a088724dca2a",
"id": "GC3FBi5L7OLq",
"papermill": {
"duration": 0.005457,
"end_time": "2021-02-10T13:42:51.332609",
"exception": false,
"start_time": "2021-02-10T13:42:51.327152",
"status": "completed"
},
"tags": []
},
"source": [
"# Simple Exercise on Overfitting\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YTaOmenI7TfT"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import statsmodels.api as sm\n",
"\n",
"\n",
"def regression_stats(n, p):\n",
" np.random.seed(123)\n",
" X = np.random.normal(size=(n, p))\n",
" y = np.random.normal(size=(n, 1))\n",
" print(f\"p/n is: {p/n if n != 0 else np.inf}\")\n",
" print(f\"R^2 is {sm.OLS(y, X).fit().rsquared}\")\n",
" print(f\"Adjusted R^2 is {sm.OLS(y, X).fit().rsquared_adj}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "C57WYtYM7OL0",
"papermill": {
"duration": 0.998738,
"end_time": "2021-02-10T13:42:52.344388",
"exception": false,
"start_time": "2021-02-10T13:42:51.345650",
"status": "completed"
},
"tags": []
},
"outputs": [],
"source": [
"regression_stats(1000, 1000)\n",
"regression_stats(1000, 500)\n",
"regression_stats(1000, 50)"
]
}
],
"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.11.5"
},
"papermill": {
"default_parameters": {},
"duration": 4.940504,
"end_time": "2021-02-10T13:42:53.102123",
"environment_variables": {},
"exception": null,
"input_path": "__notebook__.ipynb",
"output_path": "__notebook__.ipynb",
"parameters": {},
"start_time": "2021-02-10T13:42:48.161619",
"version": "2.2.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

0 comments on commit a4d5d6c

Please sign in to comment.