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