187 lines
34 KiB
Plaintext
187 lines
34 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Algorytm najszybszego spadku dla regresji wielomianowej. \n",
|
||
|
"Zakładamy, że dysponujemy zbiorem składającym się z dwóch cech (x i y). Modelujemy zależność y od x za pomocą funkcji wielomianowej. Celem projektu jest implementacja metody najszybszego spadku dla tego problemu. Zakładamy kwadratową funkcję straty. Implementacja powinna umożliwiać podanie stopnia wielomianu, który ma być użyty do modelowania. Implementacja powinna zwracać wektor oszacowanych parametrów oraz pokazywać wizualnie zmiany wartości funkcji straty wraz z postępem uczenia."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Zbiór danych: https://www.kaggle.com/varpit94/apple-stock-data-updated-till-22jun2021?select=AAPL.csv\n",
|
||
|
"This dataset provides historical data of APPLE INC. stock (AAPL). The data is available at a daily level. Currency is USD."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 21,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import pandas as pd\n",
|
||
|
"import matplotlib.pyplot as plt"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 22,
|
||
|
"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>Date</th>\n",
|
||
|
" <th>Open</th>\n",
|
||
|
" <th>High</th>\n",
|
||
|
" <th>Low</th>\n",
|
||
|
" <th>Close</th>\n",
|
||
|
" <th>Adj Close</th>\n",
|
||
|
" <th>Volume</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>1980-12-12</td>\n",
|
||
|
" <td>0.128348</td>\n",
|
||
|
" <td>0.128906</td>\n",
|
||
|
" <td>0.128348</td>\n",
|
||
|
" <td>0.128348</td>\n",
|
||
|
" <td>0.100751</td>\n",
|
||
|
" <td>469033600</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1</th>\n",
|
||
|
" <td>1980-12-15</td>\n",
|
||
|
" <td>0.122210</td>\n",
|
||
|
" <td>0.122210</td>\n",
|
||
|
" <td>0.121652</td>\n",
|
||
|
" <td>0.121652</td>\n",
|
||
|
" <td>0.095495</td>\n",
|
||
|
" <td>175884800</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2</th>\n",
|
||
|
" <td>1980-12-16</td>\n",
|
||
|
" <td>0.113281</td>\n",
|
||
|
" <td>0.113281</td>\n",
|
||
|
" <td>0.112723</td>\n",
|
||
|
" <td>0.112723</td>\n",
|
||
|
" <td>0.088485</td>\n",
|
||
|
" <td>105728000</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3</th>\n",
|
||
|
" <td>1980-12-17</td>\n",
|
||
|
" <td>0.115513</td>\n",
|
||
|
" <td>0.116071</td>\n",
|
||
|
" <td>0.115513</td>\n",
|
||
|
" <td>0.115513</td>\n",
|
||
|
" <td>0.090676</td>\n",
|
||
|
" <td>86441600</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>4</th>\n",
|
||
|
" <td>1980-12-18</td>\n",
|
||
|
" <td>0.118862</td>\n",
|
||
|
" <td>0.119420</td>\n",
|
||
|
" <td>0.118862</td>\n",
|
||
|
" <td>0.118862</td>\n",
|
||
|
" <td>0.093304</td>\n",
|
||
|
" <td>73449600</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Date Open High Low Close Adj Close Volume\n",
|
||
|
"0 1980-12-12 0.128348 0.128906 0.128348 0.128348 0.100751 469033600\n",
|
||
|
"1 1980-12-15 0.122210 0.122210 0.121652 0.121652 0.095495 175884800\n",
|
||
|
"2 1980-12-16 0.113281 0.113281 0.112723 0.112723 0.088485 105728000\n",
|
||
|
"3 1980-12-17 0.115513 0.116071 0.115513 0.115513 0.090676 86441600\n",
|
||
|
"4 1980-12-18 0.118862 0.119420 0.118862 0.118862 0.093304 73449600"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df = pd.read_csv('AAPL.csv')\n",
|
||
|
"X = df['Low']\n",
|
||
|
"Y = df['Volume']\n",
|
||
|
"display(df.head(5))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 23,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABHcAAAJJCAYAAAAgD9v8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAABWpklEQVR4nO39f3Bl53kfeD4v0IAIdFNQiNYk2cgANCOWx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neko3Lnn/5RzfnNgIwEAAACga6ZlAQAAAFRYp+FOjoh/mFJ6PaW0WHSHlNJiSmk1pbT6xhtv9G+EAAAAAJTqNNx5KOf8wxHxcET81ZTSn2u+Q855Jec8n3Oef+9739vXQQIAAABQrKNwJ+f87+797x9GxOcj4s8OclAAAAAAdKZtuJNSOppSur/+3xHxf46IfzHogQEAAADQXierZf3xiPh8Sql+//9vzvkfDHRUAAAAAHSkbbiTc/7XEfHBPRgLAAAAAF2yFDoAAABAhQl3AAAAACpMuAMAAABQYcIdAAAAgAoT7gAAAABUmHAHAAAAoMKEOwAAAAAVJtwBAAAAqDDhDgAAAECFCXcAAAAAKky4AwAAAFBhwh0AAACAChPuAAAAAFSYcAcAAACgwoQ7AAAAABUm3AEAAACoMOEOAAAAQIUJdwAAAAAqTLgDAAAAUGHCHQAAAIAKE+4AAAAAVJhwBwAAAKDChDsAAAAAFSbcAQAAAKgw4Q4AAABAhQl3AAAAACpMuAMAAABQYcIdAAAAgAoT7gAAAABUmHAHAAAAoMKEOwAAAAAVJtwBAAAAqDDhDgAAAECFCXcAAAAAKky4AwA
|
||
|
"text/plain": [
|
||
|
"<Figure size 1440x720 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig = plt.figure(figsize=(20,10))\n",
|
||
|
"chart = fig.add_subplot()\n",
|
||
|
"chart.plot(X,Y ,\"go\")\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"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.5"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|