noshot 0.4.0__py3-none-any.whl → 0.9.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.
- noshot/data/ML TS XAI/TS/10. Seasonal ARIMA Forecasting.ipynb +246 -0
- noshot/data/ML TS XAI/TS/11. Multivariate ARIMA Forecasting.ipynb +228 -0
- noshot/data/ML TS XAI/TS/6. ACF PACF.ipynb +77 -0
- noshot/data/ML TS XAI/TS/7. Differencing.ipynb +167 -0
- noshot/data/ML TS XAI/TS/8. ARMA Forecasting.ipynb +197 -0
- noshot/data/ML TS XAI/TS/9. ARIMA Forecasting.ipynb +220 -0
- noshot/main.py +18 -18
- noshot/utils/__init__.py +2 -2
- noshot/utils/shell_utils.py +56 -56
- {noshot-0.4.0.dist-info → noshot-0.9.0.dist-info}/METADATA +58 -55
- noshot-0.9.0.dist-info/RECORD +15 -0
- {noshot-0.4.0.dist-info → noshot-0.9.0.dist-info}/WHEEL +1 -1
- {noshot-0.4.0.dist-info → noshot-0.9.0.dist-info/licenses}/LICENSE.txt +20 -20
- noshot/data/ML TS XAI/CIA-1-Delhi Boy.ipynb +0 -535
- noshot/data/ML TS XAI/Football Player/4.ipynb +0 -395
- noshot/data/ML TS XAI/ML/1. PCA - EDA.ipynb +0 -207
- noshot/data/ML TS XAI/ML/2. KNN Classifier.ipynb +0 -287
- noshot/data/ML TS XAI/ML/3. Linear Discriminant Analysis.ipynb +0 -83
- noshot/data/ML TS XAI/ML/4. Linear Regression.ipynb +0 -117
- noshot/data/ML TS XAI/ML/5. Logistic Regression.ipynb +0 -151
- noshot/data/ML TS XAI/ML/6. Bayesian Classifier.ipynb +0 -89
- noshot/data/ML TS XAI/ML/data/balance-scale.csv +0 -626
- noshot/data/ML TS XAI/ML/data/balance-scale.txt +0 -625
- noshot/data/ML TS XAI/ML/data/machine-data.csv +0 -210
- noshot/data/ML TS XAI/ML/data/wine-dataset.csv +0 -179
- noshot/data/ML TS XAI/ML Additional/Bank.ipynb +0 -74
- noshot/data/ML TS XAI/ML Additional/LR.ipynb +0 -69
- noshot/data/ML TS XAI/ML Additional/ObesityDataSet_raw_and_data_sinthetic.csv +0 -2112
- noshot/data/ML TS XAI/ML Additional/Q4 LR.csv +0 -206
- noshot/data/ML TS XAI/ML Additional/Q7 BANK DETAILS.csv +0 -41189
- noshot/data/ML TS XAI/ML Additional/airfoil.ipynb +0 -69
- noshot/data/ML TS XAI/ML Additional/airfoil_self_noise.dat +0 -1503
- noshot/data/ML TS XAI/ML Additional/obesity.ipynb +0 -78
- noshot/data/ML TS XAI/ML Additional/voronoicode.ipynb +0 -81
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/1/1.ipynb +0 -133
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/1/Question.txt +0 -12
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/1/airfoil_self_noise.dat +0 -1503
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/2/2.ipynb +0 -139
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/2/Question.txt +0 -12
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/2/pop_failures.dat +0 -143
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/3/3.ipynb +0 -130
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/3/Qu.txt +0 -1
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/3/go_track_tracks.csv +0 -164
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/4/4.ipynb +0 -141
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/4/Wilt.csv +0 -4340
- noshot/data/ML TS XAI/ML Lab CIA - Healthy Class/4/qu.txt +0 -1
- noshot/data/ML TS XAI/ML Lab CIA - Our Class/AllinOne.ipynb +0 -1
- noshot/data/ML TS XAI/ML Lab CIA - Our Class/Heart-Disease-UCI-0.ipynb +0 -886
- noshot/data/ML TS XAI/ML Lab CIA - Our Class/Housing-0.ipynb +0 -292
- noshot/data/ML TS XAI/ML Lab CIA - Our Class/Lab Code Ex 1-4.ipynb +0 -1
- noshot/data/ML TS XAI/ML Lab CIA - Our Class/data/Housing.csv +0 -546
- noshot/data/ML TS XAI/ML Lab CIA - Our Class/data/heart_disease_uci.csv +0 -921
- noshot-0.4.0.dist-info/RECORD +0 -48
- {noshot-0.4.0.dist-info → noshot-0.9.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,167 @@
|
|
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
|
+
}
|
@@ -0,0 +1,197 @@
|
|
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
|
+
}
|
@@ -0,0 +1,220 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "6e3f5839-6844-42c3-a57c-5e6324c7ee43",
|
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.tsa.stattools import adfuller\n",
|
18
|
+
"from statsmodels.api import tsa\n",
|
19
|
+
"from sklearn.metrics import r2_score\n",
|
20
|
+
"from sklearn.model_selection import TimeSeriesSplit\n",
|
21
|
+
"import warnings\n",
|
22
|
+
"warnings.filterwarnings('ignore')"
|
23
|
+
]
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"cell_type": "code",
|
27
|
+
"execution_count": null,
|
28
|
+
"id": "f32d68f1-db8f-4b74-b23e-2f3ad3b56eed",
|
29
|
+
"metadata": {},
|
30
|
+
"outputs": [],
|
31
|
+
"source": [
|
32
|
+
"df = pd.read_csv('monthly-sunspots.csv', index_col = 'YEAR')\n",
|
33
|
+
"df"
|
34
|
+
]
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"cell_type": "code",
|
38
|
+
"execution_count": null,
|
39
|
+
"id": "500a40bd-7d8f-4d52-923a-ad76d590216f",
|
40
|
+
"metadata": {
|
41
|
+
"scrolled": true
|
42
|
+
},
|
43
|
+
"outputs": [],
|
44
|
+
"source": [
|
45
|
+
"df.plot(figsize=(15,8), color = 'purple')"
|
46
|
+
]
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"cell_type": "code",
|
50
|
+
"execution_count": null,
|
51
|
+
"id": "6dc6f56f-93bd-4506-b32a-e0f7361829b7",
|
52
|
+
"metadata": {},
|
53
|
+
"outputs": [],
|
54
|
+
"source": [
|
55
|
+
"result = adfuller(df['SUNACTIVITY'])\n",
|
56
|
+
"display(result)"
|
57
|
+
]
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"cell_type": "code",
|
61
|
+
"execution_count": null,
|
62
|
+
"id": "13ece976-8c18-4a2e-b44a-49fa6bc6ff85",
|
63
|
+
"metadata": {},
|
64
|
+
"outputs": [],
|
65
|
+
"source": [
|
66
|
+
"pvalue = result[1]\n",
|
67
|
+
"if pvalue < 0.05:\n",
|
68
|
+
" print(\"Stationary\")\n",
|
69
|
+
"else:\n",
|
70
|
+
" print(\"Non Stationary\")"
|
71
|
+
]
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"cell_type": "code",
|
75
|
+
"execution_count": null,
|
76
|
+
"id": "d83cf3f0-244b-4961-8ff4-dedf97e5a766",
|
77
|
+
"metadata": {},
|
78
|
+
"outputs": [],
|
79
|
+
"source": [
|
80
|
+
"plot_acf(df['SUNACTIVITY'], lags = 40)\n",
|
81
|
+
"plot_pacf(df['SUNACTIVITY'], lags = 40)\n",
|
82
|
+
"plt.show()"
|
83
|
+
]
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"cell_type": "code",
|
87
|
+
"execution_count": null,
|
88
|
+
"id": "5dacfe47-b35b-46e4-a06f-6001040a6405",
|
89
|
+
"metadata": {},
|
90
|
+
"outputs": [],
|
91
|
+
"source": [
|
92
|
+
"model = ARIMA(list(df['SUNACTIVITY']), order = (1,0,1))\n",
|
93
|
+
"result = model.fit()\n",
|
94
|
+
"pred = result.predict()\n",
|
95
|
+
"print(r2_score(df, pred))"
|
96
|
+
]
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"cell_type": "code",
|
100
|
+
"execution_count": null,
|
101
|
+
"id": "171168aa-f0a2-43f1-a195-72b9f3791a53",
|
102
|
+
"metadata": {},
|
103
|
+
"outputs": [],
|
104
|
+
"source": [
|
105
|
+
"plt.plot(list(df['SUNACTIVITY']))\n",
|
106
|
+
"plt.plot(pred, linestyle = '--')\n",
|
107
|
+
"plt.legend(['Actual Sunspots'], ['Predicted SUnspots'])\n",
|
108
|
+
"plt.xlabel('Timesteps')\n",
|
109
|
+
"plt.show()"
|
110
|
+
]
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"cell_type": "code",
|
114
|
+
"execution_count": null,
|
115
|
+
"id": "62e74f51-e0b4-4b22-856b-5a28838375b7",
|
116
|
+
"metadata": {},
|
117
|
+
"outputs": [],
|
118
|
+
"source": [
|
119
|
+
"ax = pd.Series(result.resid).hist()\n",
|
120
|
+
"ax.set_xlabel('Residual')\n",
|
121
|
+
"ax.set_ylabel('Number of Occurences')\n",
|
122
|
+
"plt.show()"
|
123
|
+
]
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"cell_type": "code",
|
127
|
+
"execution_count": null,
|
128
|
+
"id": "1cac3ae4-d8f2-49c4-a04d-fabf5290977a",
|
129
|
+
"metadata": {},
|
130
|
+
"outputs": [],
|
131
|
+
"source": [
|
132
|
+
"result.summary()"
|
133
|
+
]
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"cell_type": "code",
|
137
|
+
"execution_count": null,
|
138
|
+
"id": "e3ae6db1-4b9c-4a9b-8286-b6484fabb348",
|
139
|
+
"metadata": {},
|
140
|
+
"outputs": [],
|
141
|
+
"source": [
|
142
|
+
"data_array = df.values\n",
|
143
|
+
"avg_errors = []\n",
|
144
|
+
"for p in range(1):\n",
|
145
|
+
" for q in range(13):\n",
|
146
|
+
" errors = []\n",
|
147
|
+
" tscv = TimeSeriesSplit(test_size = 10)\n",
|
148
|
+
" for train_index, test_index in tscv.split(data_array):\n",
|
149
|
+
" x_train, x_test = data_array[train_index], data_array[test_index]\n",
|
150
|
+
" x_test_orig = x_test\n",
|
151
|
+
"\n",
|
152
|
+
" fcst = []\n",
|
153
|
+
" for stop in range(10):\n",
|
154
|
+
" try:\n",
|
155
|
+
" mod = ARIMA(x_train, order = (p,0,q))\n",
|
156
|
+
" res = mod.fit()\n",
|
157
|
+
" fcst.append(res.forecast(steps = 1))\n",
|
158
|
+
" except:\n",
|
159
|
+
" print(\"Error\")\n",
|
160
|
+
" fcst.append(-9999999.)\n",
|
161
|
+
" x_train = np.concatenate((x_train, x_test[0:1,]))\n",
|
162
|
+
" x_test = x_test[1:]\n",
|
163
|
+
" errors.append(r2_score(x_test_orig, fcst))\n",
|
164
|
+
" pq_result = [p, q, np.mean(errors)]\n",
|
165
|
+
" print(pq_result)\n",
|
166
|
+
" avg_errors.append(pq_result)\n",
|
167
|
+
"avg_errors = pd.DataFrame(avg_errors)\n",
|
168
|
+
"avg_errors.columns = ['p', 'q', 'error']\n",
|
169
|
+
"result = avg_errors.pivot(index = 'p', columns = 'q')"
|
170
|
+
]
|
171
|
+
},
|
172
|
+
{
|
173
|
+
"cell_type": "code",
|
174
|
+
"execution_count": null,
|
175
|
+
"id": "f0882bbd-e5de-4249-b74c-9f96c6777205",
|
176
|
+
"metadata": {},
|
177
|
+
"outputs": [],
|
178
|
+
"source": [
|
179
|
+
"dta_array = df.values\n",
|
180
|
+
"X_train, X_test = dta_array[:10], dta_array[-10:]\n",
|
181
|
+
"X_test_orig = X_test\n",
|
182
|
+
"\n",
|
183
|
+
"fcst = []\n",
|
184
|
+
"for step in range(10):\n",
|
185
|
+
" mod = ARIMA(X_train, order = (10,0,9))\n",
|
186
|
+
" res = mod.fit()\n",
|
187
|
+
" fcst.append(res.forecast(steps = 1))\n",
|
188
|
+
" X_train = np.concatenate((X_train, X_test[0:1,:]))\n",
|
189
|
+
" X_test = X_test[1:]\n",
|
190
|
+
"\n",
|
191
|
+
"plt.plot(X_test_orig)\n",
|
192
|
+
"plt.plot(fcst)\n",
|
193
|
+
"plt.legend(['Actual Sunspots', 'Predicted Sunspots'])\n",
|
194
|
+
"plt.xlabel('Time Steps of Test Data')\n",
|
195
|
+
"plt.show()"
|
196
|
+
]
|
197
|
+
}
|
198
|
+
],
|
199
|
+
"metadata": {
|
200
|
+
"kernelspec": {
|
201
|
+
"display_name": "Python 3 (ipykernel)",
|
202
|
+
"language": "python",
|
203
|
+
"name": "python3"
|
204
|
+
},
|
205
|
+
"language_info": {
|
206
|
+
"codemirror_mode": {
|
207
|
+
"name": "ipython",
|
208
|
+
"version": 3
|
209
|
+
},
|
210
|
+
"file_extension": ".py",
|
211
|
+
"mimetype": "text/x-python",
|
212
|
+
"name": "python",
|
213
|
+
"nbconvert_exporter": "python",
|
214
|
+
"pygments_lexer": "ipython3",
|
215
|
+
"version": "3.12.4"
|
216
|
+
}
|
217
|
+
},
|
218
|
+
"nbformat": 4,
|
219
|
+
"nbformat_minor": 5
|
220
|
+
}
|
noshot/main.py
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
from noshot.utils.shell_utils import get_folder
|
2
|
-
from noshot.utils.shell_utils import get_file
|
3
|
-
from noshot.utils.shell_utils import remove_folder
|
4
|
-
|
5
|
-
available = {'-1 ' : "ML TS XAI(Folder)",
|
6
|
-
'0 ' : "Remove Folder"}
|
7
|
-
|
8
|
-
def get(name = None, open = False):
|
9
|
-
try:
|
10
|
-
if name is not None:
|
11
|
-
name = str(name)
|
12
|
-
if name in ['-1'] : get_folder("ML TS XAI", loc = True)
|
13
|
-
elif name in ['0'] : remove_folder("ML TS XAI")
|
14
|
-
else:
|
15
|
-
for k, v in available.items():
|
16
|
-
sep = " : " if v else ""
|
17
|
-
print(k,v,sep = sep)
|
18
|
-
except Exception as error:
|
1
|
+
from noshot.utils.shell_utils import get_folder
|
2
|
+
from noshot.utils.shell_utils import get_file
|
3
|
+
from noshot.utils.shell_utils import remove_folder
|
4
|
+
|
5
|
+
available = {'-1 ' : "ML TS XAI(Folder)",
|
6
|
+
'0 ' : "Remove Folder"}
|
7
|
+
|
8
|
+
def get(name = None, open = False):
|
9
|
+
try:
|
10
|
+
if name is not None:
|
11
|
+
name = str(name)
|
12
|
+
if name in ['-1'] : get_folder("ML TS XAI", loc = True)
|
13
|
+
elif name in ['0'] : remove_folder("ML TS XAI")
|
14
|
+
else:
|
15
|
+
for k, v in available.items():
|
16
|
+
sep = " : " if v else ""
|
17
|
+
print(k,v,sep = sep)
|
18
|
+
except Exception as error:
|
19
19
|
print(error)
|
noshot/utils/__init__.py
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
from .shell_utils import get_file
|
2
|
-
from .shell_utils import get_folder
|
1
|
+
from .shell_utils import get_file
|
2
|
+
from .shell_utils import get_folder
|
3
3
|
from .shell_utils import remove_folder
|