noshot 0.9.0__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,228 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "8f9faf6e",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import numpy as np\n",
11
- "import pandas as pd\n",
12
- "import matplotlib.pyplot as plt\n",
13
- "from statsmodels.tsa.stattools import adfuller\n",
14
- "from statsmodels.tsa.stattools import grangercausalitytests\n",
15
- "from statsmodels.tsa.statespace.varmax import VARMAX\n",
16
- "from statsmodels.tsa.api import VAR\n",
17
- "import warnings\n",
18
- "warnings.filterwarnings('ignore')"
19
- ]
20
- },
21
- {
22
- "cell_type": "code",
23
- "execution_count": null,
24
- "id": "da824655",
25
- "metadata": {},
26
- "outputs": [],
27
- "source": [
28
- "custom_column_names = ['WSR0','WSR1']\n",
29
- "df = pd.read_csv('eighthr.csv', parse_dates=[0], na_values=['?'],\n",
30
- " index_col=0, names = (['WSR0', 'WSR1']+list(range(3, 74))))\n",
31
- "df = df.dropna()\n",
32
- "df.head()"
33
- ]
34
- },
35
- {
36
- "cell_type": "code",
37
- "execution_count": null,
38
- "id": "92bf562d",
39
- "metadata": {},
40
- "outputs": [],
41
- "source": [
42
- "df['WSR0'] = df['WSR0'].astype(float)\n",
43
- "df['WSR1'] = df['WSR1'].astype(float)"
44
- ]
45
- },
46
- {
47
- "cell_type": "code",
48
- "execution_count": null,
49
- "id": "f578482e",
50
- "metadata": {},
51
- "outputs": [],
52
- "source": [
53
- "fig,axes = plt.subplots(2,1,figsize=(14,8))\n",
54
- "df['WSR1'].plot(ax=axes[0],title='WSR0')\n",
55
- "df['WSR0'].plot(ax=axes[1],title='WSR1')\n",
56
- "plt.show()"
57
- ]
58
- },
59
- {
60
- "cell_type": "code",
61
- "execution_count": null,
62
- "id": "daac380f",
63
- "metadata": {},
64
- "outputs": [],
65
- "source": [
66
- "result = adfuller(df['WSR0'])\n",
67
- "print(result)\n",
68
- "if result[1]<0.05:\n",
69
- " print(\"It is Stationary\")\n",
70
- "else:\n",
71
- " print(\"It is not stationary\")"
72
- ]
73
- },
74
- {
75
- "cell_type": "code",
76
- "execution_count": null,
77
- "id": "e18f51f2",
78
- "metadata": {},
79
- "outputs": [],
80
- "source": [
81
- "result = adfuller(df['WSR1'])\n",
82
- "print(result)\n",
83
- "if result[1]<0.05:\n",
84
- " print(\"It is Stationary\")\n",
85
- "else:\n",
86
- " print(\"It is not stationary\")"
87
- ]
88
- },
89
- {
90
- "cell_type": "code",
91
- "execution_count": null,
92
- "id": "0b6419c1",
93
- "metadata": {},
94
- "outputs": [],
95
- "source": [
96
- "print('WSR0 causes WSR1')\n",
97
- "print('---------------------')\n",
98
- "granger1=grangercausalitytests(df[['WSR0','WSR1']],2)\n",
99
- "print('WSR1 causes WSR0')\n",
100
- "print('---------------------')\n",
101
- "granger1=grangercausalitytests(df[['WSR1','WSR0']],2)"
102
- ]
103
- },
104
- {
105
- "cell_type": "code",
106
- "execution_count": null,
107
- "id": "b37f4f93",
108
- "metadata": {},
109
- "outputs": [],
110
- "source": [
111
- "train = df[['WSR0','WSR1']]\n",
112
- "model = VAR(train)\n",
113
- "sortedmodel = model.select_order(maxlags=20)\n",
114
- "sortedmodel.summary()"
115
- ]
116
- },
117
- {
118
- "cell_type": "code",
119
- "execution_count": null,
120
- "id": "3da00920",
121
- "metadata": {},
122
- "outputs": [],
123
- "source": [
124
- "model = VARMAX(df[['WSR0', 'WSR1']], order=(10,0),enforce_stationarity=True)\n",
125
- "model_fit = model.fit()\n",
126
- "model_fit.summary()"
127
- ]
128
- },
129
- {
130
- "cell_type": "code",
131
- "execution_count": null,
132
- "id": "0b0cf16d",
133
- "metadata": {},
134
- "outputs": [],
135
- "source": [
136
- "n_forecast = 12\n",
137
- "pred = model_fit.get_prediction()\n",
138
- "preds = pred.predicted_mean"
139
- ]
140
- },
141
- {
142
- "cell_type": "code",
143
- "execution_count": null,
144
- "id": "56954749",
145
- "metadata": {},
146
- "outputs": [],
147
- "source": [
148
- "preds.columns = ['WSR0 Predictions','WSR1 Predictions']\n",
149
- "preds"
150
- ]
151
- },
152
- {
153
- "cell_type": "code",
154
- "execution_count": null,
155
- "id": "704c6372",
156
- "metadata": {},
157
- "outputs": [],
158
- "source": [
159
- "train = df[['WSR0','WSR1']]\n",
160
- "testvspread = pd.concat([train,preds],axis=1)\n",
161
- "testvspread"
162
- ]
163
- },
164
- {
165
- "cell_type": "code",
166
- "execution_count": null,
167
- "id": "d60e3508",
168
- "metadata": {},
169
- "outputs": [],
170
- "source": [
171
- "testvspread[['WSR0','WSR0 Predictions']].plot()"
172
- ]
173
- },
174
- {
175
- "cell_type": "code",
176
- "execution_count": null,
177
- "id": "28fb2660",
178
- "metadata": {},
179
- "outputs": [],
180
- "source": [
181
- "testvspread[['WSR1','WSR1 Predictions']].plot()"
182
- ]
183
- },
184
- {
185
- "cell_type": "code",
186
- "execution_count": null,
187
- "id": "35888acd",
188
- "metadata": {},
189
- "outputs": [],
190
- "source": [
191
- "from sklearn.metrics import mean_squared_error\n",
192
- "mean_squared_error(testvspread['WSR1'],testvspread['WSR1 Predictions'])"
193
- ]
194
- },
195
- {
196
- "cell_type": "code",
197
- "execution_count": null,
198
- "id": "41748e7e",
199
- "metadata": {},
200
- "outputs": [],
201
- "source": [
202
- "from sklearn.metrics import mean_squared_error\n",
203
- "mean_squared_error(testvspread['WSR0'],testvspread['WSR0 Predictions'])"
204
- ]
205
- }
206
- ],
207
- "metadata": {
208
- "kernelspec": {
209
- "display_name": "Python 3 (ipykernel)",
210
- "language": "python",
211
- "name": "python3"
212
- },
213
- "language_info": {
214
- "codemirror_mode": {
215
- "name": "ipython",
216
- "version": 3
217
- },
218
- "file_extension": ".py",
219
- "mimetype": "text/x-python",
220
- "name": "python",
221
- "nbconvert_exporter": "python",
222
- "pygments_lexer": "ipython3",
223
- "version": "3.12.4"
224
- }
225
- },
226
- "nbformat": 4,
227
- "nbformat_minor": 5
228
- }
@@ -1,77 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "97b25ae4-1eb7-4599-bad4-e959bbb9a275",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import pandas as pd\n",
11
- "import numpy as np\n",
12
- "import matplotlib.pyplot as plt\n",
13
- "from statsmodels.graphics.tsaplots import plot_acf, plot_pacf"
14
- ]
15
- },
16
- {
17
- "cell_type": "code",
18
- "execution_count": null,
19
- "id": "f70584ab-aa4d-4957-9315-3e884f66c559",
20
- "metadata": {},
21
- "outputs": [],
22
- "source": [
23
- "df = pd.read_csv('daily-min-temperatures.csv')\n",
24
- "print(df.shape)\n",
25
- "df.head()"
26
- ]
27
- },
28
- {
29
- "cell_type": "code",
30
- "execution_count": null,
31
- "id": "b6574dd0-e010-423b-bb26-ba2ca142e848",
32
- "metadata": {},
33
- "outputs": [],
34
- "source": [
35
- "df.plot(title = \"daily Minimum Temperature\" ,figsize = (14, 8), legend = None, color = 'green')\n",
36
- "plt.xlabel('Date')\n",
37
- "plt.ylabel('Temperature (°C)')\n",
38
- "plt.show()"
39
- ]
40
- },
41
- {
42
- "cell_type": "code",
43
- "execution_count": null,
44
- "id": "3ba0f2ea-069c-4aa2-aa4b-0d90a54ee21f",
45
- "metadata": {},
46
- "outputs": [],
47
- "source": [
48
- "fig, axs = plt.subplots(2, 1, figsize = (10,8))\n",
49
- "plot_acf(df['Temp'], lags = 30, ax = axs[0], title = 'Autocorrelation (ACF)', color = 'green')\n",
50
- "plot_pacf(df['Temp'], lags = 30, ax = axs[1], title = 'Partial Autocorrelation (PACF)', color = 'red')\n",
51
- "plt.tight_layout()\n",
52
- "plt.show()"
53
- ]
54
- }
55
- ],
56
- "metadata": {
57
- "kernelspec": {
58
- "display_name": "Python 3 (ipykernel)",
59
- "language": "python",
60
- "name": "python3"
61
- },
62
- "language_info": {
63
- "codemirror_mode": {
64
- "name": "ipython",
65
- "version": 3
66
- },
67
- "file_extension": ".py",
68
- "mimetype": "text/x-python",
69
- "name": "python",
70
- "nbconvert_exporter": "python",
71
- "pygments_lexer": "ipython3",
72
- "version": "3.12.4"
73
- }
74
- },
75
- "nbformat": 4,
76
- "nbformat_minor": 5
77
- }
@@ -1,167 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "0ac778c2-495b-4613-80ca-d6be2b71e598",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import pandas as pd\n",
11
- "import numpy as np\n",
12
- "import matplotlib.pyplot as plt"
13
- ]
14
- },
15
- {
16
- "cell_type": "code",
17
- "execution_count": null,
18
- "id": "a843538d-035e-4a90-b67b-1fa647c22f70",
19
- "metadata": {},
20
- "outputs": [],
21
- "source": [
22
- "df = pd.read_csv('daily-min-temperatures.csv', parse_dates = ['Date'], index_col = 'Date')\n",
23
- "df.head()"
24
- ]
25
- },
26
- {
27
- "cell_type": "code",
28
- "execution_count": null,
29
- "id": "c3aff0e1-9c54-474f-83ea-2b6bb632bd3f",
30
- "metadata": {},
31
- "outputs": [],
32
- "source": [
33
- "df.plot(title = 'Daily Minimum Temperatures', figsize = (14, 8), legend = None)\n",
34
- "plt.xlabel('Date')\n",
35
- "plt.ylabel('Temperature (°C)')\n",
36
- "plt.show()"
37
- ]
38
- },
39
- {
40
- "cell_type": "code",
41
- "execution_count": null,
42
- "id": "5d08b196-75c8-473d-b77e-85008048d590",
43
- "metadata": {},
44
- "outputs": [],
45
- "source": [
46
- "differenced_series = df.diff(periods=1) #lag-1 difference\n",
47
- "plt.subplot(2, 1, 1)\n",
48
- "plt.plot(df, label = \"Original Series\")\n",
49
- "plt.title(\"Original Daily Minimum Temperatures\")\n",
50
- "plt.grid()\n",
51
- "\n",
52
- "plt.subplot(2, 1, 2)\n",
53
- "plt.plot(differenced_series, label = \"Differneced Series\", color=\"green\")\n",
54
- "plt.title(\"Differneced Daily Minimum Temperatures\")\n",
55
- "plt.grid()\n",
56
- "\n",
57
- "plt.tight_layout()\n",
58
- "plt.show()"
59
- ]
60
- },
61
- {
62
- "cell_type": "code",
63
- "execution_count": null,
64
- "id": "800dd56a-1b3f-4cdd-8fac-802048d1160b",
65
- "metadata": {},
66
- "outputs": [],
67
- "source": [
68
- "X = df.values\n",
69
- "diff = []\n",
70
- "days_in_year = 365\n",
71
- "for i in range(days_in_year, len(X)):\n",
72
- " value = X[i] - X[i - days_in_year]\n",
73
- " diff.append(value)\n",
74
- "plt.plot(diff)\n",
75
- "plt.show()"
76
- ]
77
- },
78
- {
79
- "cell_type": "code",
80
- "execution_count": null,
81
- "id": "1dc499f8-4c1d-4d65-9e16-3439fe22ef13",
82
- "metadata": {},
83
- "outputs": [],
84
- "source": [
85
- "df['diff'] = df['Temp'].diff(periods=1)\n",
86
- "\n",
87
- "plt.plot(df.index, df['Temp'], label = 'Original')\n",
88
- "plt.plot(df.index, df['diff'], label = 'Differenced (lag-1)')\n",
89
- "plt.xlabel('Date')\n",
90
- "plt.ylabel('Temperature (°C)')\n",
91
- "plt.title(\"Temperature Time Series with Differencing\")\n",
92
- "plt.legend()\n",
93
- "plt.show()"
94
- ]
95
- },
96
- {
97
- "cell_type": "code",
98
- "execution_count": null,
99
- "id": "7f720228-762a-48e3-aa61-733846cca105",
100
- "metadata": {},
101
- "outputs": [],
102
- "source": [
103
- "df = pd.read_csv('daily-min-temperatures.csv', header=0, index_col = 0)\n",
104
- "X = [i%365 for i in range(0, len(df))]\n",
105
- "y = df.values"
106
- ]
107
- },
108
- {
109
- "cell_type": "code",
110
- "execution_count": null,
111
- "id": "87262e57-a216-422d-a768-2d2459df23ff",
112
- "metadata": {},
113
- "outputs": [],
114
- "source": [
115
- "degree = 4\n",
116
- "coef = np.polyfit(X, y, degree)\n",
117
- "print(\"Coefficients:\\n\", coef)"
118
- ]
119
- },
120
- {
121
- "cell_type": "code",
122
- "execution_count": null,
123
- "id": "daec417d-061a-4953-9d2b-206dbc0ba8e7",
124
- "metadata": {},
125
- "outputs": [],
126
- "source": [
127
- "curve = []\n",
128
- "for i in range(len(X)):\n",
129
- " value = coef[-1]\n",
130
- " for d in range(degree):\n",
131
- " value += (X[i]**(degree - d)) * coef[d]\n",
132
- " curve.append(value)\n",
133
- "\n",
134
- "values = df.values\n",
135
- "\n",
136
- "diff = []\n",
137
- "for i in range(len(values)):\n",
138
- " value = values[i] - curve[i]\n",
139
- " diff.append(value)\n",
140
- "\n",
141
- "plt.plot(diff)\n",
142
- "plt.show()"
143
- ]
144
- }
145
- ],
146
- "metadata": {
147
- "kernelspec": {
148
- "display_name": "Python 3 (ipykernel)",
149
- "language": "python",
150
- "name": "python3"
151
- },
152
- "language_info": {
153
- "codemirror_mode": {
154
- "name": "ipython",
155
- "version": 3
156
- },
157
- "file_extension": ".py",
158
- "mimetype": "text/x-python",
159
- "name": "python",
160
- "nbconvert_exporter": "python",
161
- "pygments_lexer": "ipython3",
162
- "version": "3.12.4"
163
- }
164
- },
165
- "nbformat": 4,
166
- "nbformat_minor": 5
167
- }
@@ -1,197 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "cb446765-5f1b-4827-8eb8-465f275c1821",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import pandas as pd\n",
11
- "import numpy as np\n",
12
- "import matplotlib.pyplot as plt\n",
13
- "from scipy import stats\n",
14
- "from statsmodels.graphics.tsaplots import plot_acf, plot_pacf\n",
15
- "from statsmodels.graphics.api import qqplot\n",
16
- "from statsmodels.tsa.arima.model import ARIMA\n",
17
- "from statsmodels.api import tsa\n",
18
- "import warnings\n",
19
- "warnings.filterwarnings('ignore')"
20
- ]
21
- },
22
- {
23
- "cell_type": "code",
24
- "execution_count": null,
25
- "id": "8166c848-99fb-4883-9534-372e66da163f",
26
- "metadata": {},
27
- "outputs": [],
28
- "source": [
29
- "df = pd.read_csv('monthly-sunspots.csv', index_col = 'YEAR')\n",
30
- "df"
31
- ]
32
- },
33
- {
34
- "cell_type": "code",
35
- "execution_count": null,
36
- "id": "5db24ed8-03ae-4136-9d39-b7315daa85a2",
37
- "metadata": {},
38
- "outputs": [],
39
- "source": [
40
- "df.plot(figsize=(15,8), color = 'purple')"
41
- ]
42
- },
43
- {
44
- "cell_type": "code",
45
- "execution_count": null,
46
- "id": "a9288a36-b6b8-4492-9dc7-276d9a185f63",
47
- "metadata": {},
48
- "outputs": [],
49
- "source": [
50
- "fig = plt.figure(figsize=(15,8))\n",
51
- "ax1 = fig.add_subplot(211)\n",
52
- "fig = plot_acf(df.values.squeeze(), lags=40, ax=ax1, color = 'r', title='Original Autocorrelation')\n",
53
- "ax2 = fig.add_subplot(212)\n",
54
- "fig = plot_pacf(df, lags=40, ax=ax2, color = 'g', title='Original Partial Autocorrelation')"
55
- ]
56
- },
57
- {
58
- "cell_type": "code",
59
- "execution_count": null,
60
- "id": "c4044bdd-d852-49af-882a-7cf238abd1b3",
61
- "metadata": {},
62
- "outputs": [],
63
- "source": [
64
- "arma20 = ARIMA(df, order=(2,0,0)).fit()\n",
65
- "display(arma20.params)\n",
66
- "display(arma20.aic, arma20.bic, arma20.hqic)"
67
- ]
68
- },
69
- {
70
- "cell_type": "code",
71
- "execution_count": null,
72
- "id": "653f3938-1703-4cac-969a-1d991aed2081",
73
- "metadata": {},
74
- "outputs": [],
75
- "source": [
76
- "arma30 = ARIMA(df, order=(3,0,0)).fit()\n",
77
- "display(arma30.params)\n",
78
- "display(arma30.aic, arma30.bic, arma30.hqic)"
79
- ]
80
- },
81
- {
82
- "cell_type": "code",
83
- "execution_count": null,
84
- "id": "d5f9d78e-9638-4c1f-bded-1d9a9a377543",
85
- "metadata": {},
86
- "outputs": [],
87
- "source": [
88
- "fig = plt.figure(figsize=(15,8))\n",
89
- "ax = fig.add_subplot(111)\n",
90
- "ax = arma30.resid.plot(ax=ax)"
91
- ]
92
- },
93
- {
94
- "cell_type": "code",
95
- "execution_count": null,
96
- "id": "790a3e2d-486d-4406-aa1b-58c1c50d904f",
97
- "metadata": {},
98
- "outputs": [],
99
- "source": [
100
- "resid = arma30.resid\n",
101
- "stats.normaltest(resid)"
102
- ]
103
- },
104
- {
105
- "cell_type": "code",
106
- "execution_count": null,
107
- "id": "20212ba9-efa8-4bb9-88b8-5bd8c1a99a3d",
108
- "metadata": {},
109
- "outputs": [],
110
- "source": [
111
- "fig = plt.figure(figsize=(15,8))\n",
112
- "ax = fig.add_subplot(111)\n",
113
- "fig = qqplot(resid, line='q', ax=ax, fit=True)"
114
- ]
115
- },
116
- {
117
- "cell_type": "code",
118
- "execution_count": null,
119
- "id": "e50e8ade-7027-4ed9-91f4-c4bd9119ad4a",
120
- "metadata": {},
121
- "outputs": [],
122
- "source": [
123
- "fig = plt.figure(figsize=(15,8))\n",
124
- "ax1 = fig.add_subplot(211)\n",
125
- "fig = plot_acf(resid.values.squeeze(), lags=40, ax=ax1, color='g', title='Residual Autocorrelation')\n",
126
- "ax2 = fig.add_subplot(212)\n",
127
- "fig = plot_pacf(resid, lags=40, ax=ax2, color='r', title='Residual Partial Autocorrelation')"
128
- ]
129
- },
130
- {
131
- "cell_type": "code",
132
- "execution_count": null,
133
- "id": "f6b5a13b-3ce6-4be3-9e6b-436435d79141",
134
- "metadata": {},
135
- "outputs": [],
136
- "source": [
137
- "r, q, p = tsa.acf(resid.values.squeeze(), fft=True, qstat=True)\n",
138
- "data = np.c_[np.arange(1, 25), r[1:], q, p]"
139
- ]
140
- },
141
- {
142
- "cell_type": "code",
143
- "execution_count": null,
144
- "id": "87267a9d-ebfa-4324-b5ae-45c5680af95a",
145
- "metadata": {},
146
- "outputs": [],
147
- "source": [
148
- "df2 = pd.DataFrame(data, columns = ['Lag', 'AC', 'Q', 'Prob(>Q)'])\n",
149
- "df2.set_index('Lag')"
150
- ]
151
- },
152
- {
153
- "cell_type": "code",
154
- "execution_count": null,
155
- "id": "6cccb84e-4a8e-4278-b8a5-ed592936d84b",
156
- "metadata": {},
157
- "outputs": [],
158
- "source": [
159
- "predict_sunspots = arma30.predict('1990', '2012', dynamic=True)\n",
160
- "predict_sunspots = predict_sunspots['1990-12-31':'2008-12-31']\n",
161
- "predict_sunspots = pd.DataFrame(predict_sunspots)\n",
162
- "predict_sunspots.head()"
163
- ]
164
- },
165
- {
166
- "cell_type": "code",
167
- "execution_count": null,
168
- "id": "74f236dc-3062-4395-a444-bbeb411e8460",
169
- "metadata": {},
170
- "outputs": [],
171
- "source": [
172
- "np.mean((df['1990-12-31':'2008-12-31':1]['SUNACTIVITY'].values - predict_sunspots['predicted_mean'].values))"
173
- ]
174
- }
175
- ],
176
- "metadata": {
177
- "kernelspec": {
178
- "display_name": "Python 3 (ipykernel)",
179
- "language": "python",
180
- "name": "python3"
181
- },
182
- "language_info": {
183
- "codemirror_mode": {
184
- "name": "ipython",
185
- "version": 3
186
- },
187
- "file_extension": ".py",
188
- "mimetype": "text/x-python",
189
- "name": "python",
190
- "nbconvert_exporter": "python",
191
- "pygments_lexer": "ipython3",
192
- "version": "3.12.4"
193
- }
194
- },
195
- "nbformat": 4,
196
- "nbformat_minor": 5
197
- }