major upload of (python) course material & solutions
This commit is contained in:
Executable
+681
File diff suppressed because one or more lines are too long
Executable
BIN
Binary file not shown.
Executable
+267
@@ -0,0 +1,267 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "03c68072-8fd9-4c26-9f8b-e6f6e24fd583",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\\vspace{-4cm}\n",
|
||||
"\\begin{center}\n",
|
||||
" \\LARGE{Machine Learning for Economics and Finance}\\\\[0.5cm]\n",
|
||||
" \\Large{\\textbf{01\\_Auto\\_data\\_1}}\\\\[1.0cm]\n",
|
||||
" \\large{Ole Wilms}\\\\[0.5cm]\n",
|
||||
" \\large{July 29, 2024}\\\\\n",
|
||||
"\\end{center}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "4e117807-3711-444b-838d-775303383d93",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\\setcounter{secnumdepth}{0}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e0c43ee7-0ede-4d7e-9966-f00493b33f0a",
|
||||
"metadata": {
|
||||
"tags": [],
|
||||
"user_expressions": []
|
||||
},
|
||||
"source": [
|
||||
"**Get and Set working directory**:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "57ab9acc-8d99-4165-8930-db6ae2be39a9",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/mnt/ds/home/UHH_MLSJ_2024/Code/Python/01_SupLearn_Regression\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import os # Package to access system related information \n",
|
||||
"print(os.getcwd()) # Prints the current working directory\n",
|
||||
"path = os.getcwd()\n",
|
||||
"os.chdir(path) # Set the working directory"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "4424246b-bee1-4b9e-a5ac-79c20e4b4c26",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"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>mpg</th>\n",
|
||||
" <th>cylinders</th>\n",
|
||||
" <th>displacement</th>\n",
|
||||
" <th>horsepower</th>\n",
|
||||
" <th>weight</th>\n",
|
||||
" <th>acceleration</th>\n",
|
||||
" <th>year</th>\n",
|
||||
" <th>origin</th>\n",
|
||||
" <th>name</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>18.0</td>\n",
|
||||
" <td>8</td>\n",
|
||||
" <td>307.0</td>\n",
|
||||
" <td>130</td>\n",
|
||||
" <td>3504</td>\n",
|
||||
" <td>12.0</td>\n",
|
||||
" <td>70</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>chevrolet chevelle malibu</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>15.0</td>\n",
|
||||
" <td>8</td>\n",
|
||||
" <td>350.0</td>\n",
|
||||
" <td>165</td>\n",
|
||||
" <td>3693</td>\n",
|
||||
" <td>11.5</td>\n",
|
||||
" <td>70</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>buick skylark 320</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>18.0</td>\n",
|
||||
" <td>8</td>\n",
|
||||
" <td>318.0</td>\n",
|
||||
" <td>150</td>\n",
|
||||
" <td>3436</td>\n",
|
||||
" <td>11.0</td>\n",
|
||||
" <td>70</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>plymouth satellite</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>16.0</td>\n",
|
||||
" <td>8</td>\n",
|
||||
" <td>304.0</td>\n",
|
||||
" <td>150</td>\n",
|
||||
" <td>3433</td>\n",
|
||||
" <td>12.0</td>\n",
|
||||
" <td>70</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>amc rebel sst</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>17.0</td>\n",
|
||||
" <td>8</td>\n",
|
||||
" <td>302.0</td>\n",
|
||||
" <td>140</td>\n",
|
||||
" <td>3449</td>\n",
|
||||
" <td>10.5</td>\n",
|
||||
" <td>70</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>ford torino</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" mpg cylinders displacement horsepower weight acceleration year \\\n",
|
||||
"0 18.0 8 307.0 130 3504 12.0 70 \n",
|
||||
"1 15.0 8 350.0 165 3693 11.5 70 \n",
|
||||
"2 18.0 8 318.0 150 3436 11.0 70 \n",
|
||||
"3 16.0 8 304.0 150 3433 12.0 70 \n",
|
||||
"4 17.0 8 302.0 140 3449 10.5 70 \n",
|
||||
"\n",
|
||||
" origin name \n",
|
||||
"0 1 chevrolet chevelle malibu \n",
|
||||
"1 1 buick skylark 320 \n",
|
||||
"2 1 plymouth satellite \n",
|
||||
"3 1 amc rebel sst \n",
|
||||
"4 1 ford torino "
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from ISLP import load_data # Package which contains the data\n",
|
||||
"Auto = load_data('Auto') # Loading the data\n",
|
||||
"Auto.head() # Showing the first 5 Lines of Data."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "141f0257-39a4-4e21-9be0-78dfd645445a",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import statsmodels.formula.api as smf\n",
|
||||
"\n",
|
||||
"# fit model on training data and calculate training MSE\n",
|
||||
"fit_lm = smf.ols(formula='mpg ~ horsepower', data = Auto).fit()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "4ae9bf59-3b73-4020-b039-885948f6cbbd",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"==============================================================================\n",
|
||||
" coef std err t P>|t| [0.025 0.975]\n",
|
||||
"------------------------------------------------------------------------------\n",
|
||||
"Intercept 39.9359 0.717 55.660 0.000 38.525 41.347\n",
|
||||
"horsepower -0.1578 0.006 -24.489 0.000 -0.171 -0.145\n",
|
||||
"==============================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(fit_lm.summary().tables[1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "77170717-6eb1-41fa-a2b6-fdbf5e9193cf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"date": " ",
|
||||
"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.7"
|
||||
},
|
||||
"title": " ",
|
||||
"toc-autonumbering": false,
|
||||
"toc-showcode": false,
|
||||
"toc-showmarkdowntxt": false,
|
||||
"toc-showtags": false
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
+562
File diff suppressed because one or more lines are too long
Executable
BIN
Binary file not shown.
+940
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
Reference in New Issue
Block a user