{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SLR - Minimal" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
OLS Regression Results
Dep. Variable: Income R-squared: 0.878
Model: OLS Adj. R-squared: 0.875
Method: Least Squares F-statistic: 238.4
Date: Tue, 25 Jan 2022 Prob (F-statistic): 1.17e-16
Time: 06:57:49 Log-Likelihood: -119.61
No. Observations: 35 AIC: 243.2
Df Residuals: 33 BIC: 246.3
Df Model: 1
Covariance Type: nonrobust
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
coef std err t P>|t| [0.025 0.975]
Intercept -23.1764 5.918 -3.917 0.000 -35.216 -11.137
Education 5.5742 0.361 15.440 0.000 4.840 6.309
\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "
Omnibus: 2.854 Durbin-Watson: 2.535
Prob(Omnibus): 0.240 Jarque-Bera (JB): 1.726
Skew: 0.502 Prob(JB): 0.422
Kurtosis: 3.420 Cond. No. 75.8


Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified." ], "text/plain": [ "\n", "\"\"\"\n", " OLS Regression Results \n", "==============================================================================\n", "Dep. Variable: Income R-squared: 0.878\n", "Model: OLS Adj. R-squared: 0.875\n", "Method: Least Squares F-statistic: 238.4\n", "Date: Tue, 25 Jan 2022 Prob (F-statistic): 1.17e-16\n", "Time: 06:57:49 Log-Likelihood: -119.61\n", "No. Observations: 35 AIC: 243.2\n", "Df Residuals: 33 BIC: 246.3\n", "Df Model: 1 \n", "Covariance Type: nonrobust \n", "==============================================================================\n", " coef std err t P>|t| [0.025 0.975]\n", "------------------------------------------------------------------------------\n", "Intercept -23.1764 5.918 -3.917 0.000 -35.216 -11.137\n", "Education 5.5742 0.361 15.440 0.000 4.840 6.309\n", "==============================================================================\n", "Omnibus: 2.854 Durbin-Watson: 2.535\n", "Prob(Omnibus): 0.240 Jarque-Bera (JB): 1.726\n", "Skew: 0.502 Prob(JB): 0.422\n", "Kurtosis: 3.420 Cond. No. 75.8\n", "==============================================================================\n", "\n", "Notes:\n", "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n", "\"\"\"" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# import libraries\n", "import pandas as pd\n", "from statsmodels.formula.api import ols\n", "\n", "# load dataset and create dataframe\n", "df = pd.read_csv('data/edincome.csv').round(1)\n", "\n", "\n", "# run regression\n", "slr = ols('Income ~ Education',df).fit()\n", "\n", "# print results\n", "slr.summary()\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EducationIncome
01243.7
11666.0
21877.2
\n", "
" ], "text/plain": [ " Education Income\n", "0 12 43.7\n", "1 16 66.0\n", "2 18 77.2" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# predict new points\n", "data = {'Education': [12,16,18]}\n", "df_predict = pd.DataFrame(data).round(1)\n", "\n", "df_predict['Income'] = slr.predict(df_predict).round(1)\n", "df_predict" ] } ], "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.8.11" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 4 }