Sakrit123 commited on
Commit
10f9d6f
·
verified ·
1 Parent(s): 5666526

Upload gdp-forecaster (1).ipynb

Browse files
Files changed (1) hide show
  1. gdp-forecaster (1).ipynb +328 -0
gdp-forecaster (1).ipynb ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "8a37d8d9",
7
+ "metadata": {
8
+ "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
9
+ "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
10
+ "execution": {
11
+ "iopub.execute_input": "2025-01-09T23:35:10.269591Z",
12
+ "iopub.status.busy": "2025-01-09T23:35:10.269195Z",
13
+ "iopub.status.idle": "2025-01-09T23:35:10.658005Z",
14
+ "shell.execute_reply": "2025-01-09T23:35:10.656632Z"
15
+ },
16
+ "papermill": {
17
+ "duration": 0.395174,
18
+ "end_time": "2025-01-09T23:35:10.659966",
19
+ "exception": false,
20
+ "start_time": "2025-01-09T23:35:10.264792",
21
+ "status": "completed"
22
+ },
23
+ "tags": []
24
+ },
25
+ "outputs": [
26
+ {
27
+ "name": "stdout",
28
+ "output_type": "stream",
29
+ "text": [
30
+ "/kaggle/input/africa-gdp/Africa_GDP.csv\n"
31
+ ]
32
+ }
33
+ ],
34
+ "source": [
35
+ "# This Python 3 environment comes with many helpful analytics libraries installed\n",
36
+ "# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n",
37
+ "# For example, here's several helpful packages to load\n",
38
+ "\n",
39
+ "import numpy as np # linear algebra\n",
40
+ "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
41
+ "\n",
42
+ "# Input data files are available in the read-only \"../input/\" directory\n",
43
+ "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
44
+ "\n",
45
+ "import os\n",
46
+ "for dirname, _, filenames in os.walk('/kaggle/input'):\n",
47
+ " for filename in filenames:\n",
48
+ " print(os.path.join(dirname, filename))\n",
49
+ "\n",
50
+ "# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n",
51
+ "# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 2,
57
+ "id": "3f865c92",
58
+ "metadata": {
59
+ "execution": {
60
+ "iopub.execute_input": "2025-01-09T23:35:10.666585Z",
61
+ "iopub.status.busy": "2025-01-09T23:35:10.666100Z",
62
+ "iopub.status.idle": "2025-01-09T23:35:10.683517Z",
63
+ "shell.execute_reply": "2025-01-09T23:35:10.682542Z"
64
+ },
65
+ "papermill": {
66
+ "duration": 0.022595,
67
+ "end_time": "2025-01-09T23:35:10.685442",
68
+ "exception": false,
69
+ "start_time": "2025-01-09T23:35:10.662847",
70
+ "status": "completed"
71
+ },
72
+ "tags": []
73
+ },
74
+ "outputs": [],
75
+ "source": [
76
+ "data = pd.read_csv('/kaggle/input/africa-gdp/Africa_GDP.csv')"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 3,
82
+ "id": "6079ebb6",
83
+ "metadata": {
84
+ "execution": {
85
+ "iopub.execute_input": "2025-01-09T23:35:10.691660Z",
86
+ "iopub.status.busy": "2025-01-09T23:35:10.691313Z",
87
+ "iopub.status.idle": "2025-01-09T23:35:10.710088Z",
88
+ "shell.execute_reply": "2025-01-09T23:35:10.709239Z"
89
+ },
90
+ "papermill": {
91
+ "duration": 0.024075,
92
+ "end_time": "2025-01-09T23:35:10.712108",
93
+ "exception": false,
94
+ "start_time": "2025-01-09T23:35:10.688033",
95
+ "status": "completed"
96
+ },
97
+ "tags": []
98
+ },
99
+ "outputs": [],
100
+ "source": [
101
+ "data.fillna(data.mean(),inplace=True)"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": 4,
107
+ "id": "2683890c",
108
+ "metadata": {
109
+ "execution": {
110
+ "iopub.execute_input": "2025-01-09T23:35:10.718525Z",
111
+ "iopub.status.busy": "2025-01-09T23:35:10.718111Z",
112
+ "iopub.status.idle": "2025-01-09T23:35:10.733589Z",
113
+ "shell.execute_reply": "2025-01-09T23:35:10.732439Z"
114
+ },
115
+ "papermill": {
116
+ "duration": 0.020627,
117
+ "end_time": "2025-01-09T23:35:10.735403",
118
+ "exception": false,
119
+ "start_time": "2025-01-09T23:35:10.714776",
120
+ "status": "completed"
121
+ },
122
+ "tags": []
123
+ },
124
+ "outputs": [],
125
+ "source": [
126
+ "data.drop_duplicates(inplace=True)"
127
+ ]
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "execution_count": 5,
132
+ "id": "5eff6792",
133
+ "metadata": {
134
+ "execution": {
135
+ "iopub.execute_input": "2025-01-09T23:35:10.741486Z",
136
+ "iopub.status.busy": "2025-01-09T23:35:10.741132Z",
137
+ "iopub.status.idle": "2025-01-09T23:35:12.076529Z",
138
+ "shell.execute_reply": "2025-01-09T23:35:12.075251Z"
139
+ },
140
+ "papermill": {
141
+ "duration": 1.340317,
142
+ "end_time": "2025-01-09T23:35:12.078262",
143
+ "exception": false,
144
+ "start_time": "2025-01-09T23:35:10.737945",
145
+ "status": "completed"
146
+ },
147
+ "tags": []
148
+ },
149
+ "outputs": [
150
+ {
151
+ "name": "stdout",
152
+ "output_type": "stream",
153
+ "text": [
154
+ " Year Algeria Benin Botswana Burkina Faso Burundi \\\n",
155
+ "0 1960 2.723615e+09 226195578.4 30411413.66 330442815.8 195999990.0 \n",
156
+ "1 1961 2.434747e+09 235668220.5 32902612.87 350247234.3 202999992.0 \n",
157
+ "2 1962 2.001445e+09 236434954.0 35644956.64 379567099.2 213500006.0 \n",
158
+ "3 1963 2.702982e+09 253927697.3 38091842.85 394040667.1 232749998.0 \n",
159
+ "4 1964 2.909316e+09 269819005.9 41616347.79 410321645.0 260750008.0 \n",
160
+ "\n",
161
+ " Cameroon Central African Republic Chad Eswatini ... \\\n",
162
+ "0 614206068.5 112155598.5 313582728.1 35076845.97 ... \n",
163
+ "1 652777608.3 123134583.5 333975336.1 43026042.79 ... \n",
164
+ "2 694247864.4 124482773.8 357635713.4 45927961.63 ... \n",
165
+ "3 718320845.0 129379123.8 371767002.2 54129438.35 ... \n",
166
+ "4 776650176.9 142025078.7 392247517.7 64980554.01 ... \n",
167
+ "\n",
168
+ " Seychelles Sierra Leone Somalia South Africa Sudan \\\n",
169
+ "0 12012024.62 322151470.6 180459936.8 8.748597e+09 1.127011e+09 \n",
170
+ "1 11592023.76 327979248.4 191659914.4 9.225996e+09 1.223563e+09 \n",
171
+ "2 12642025.92 342872712.4 203531927.5 9.813996e+09 1.329023e+09 \n",
172
+ "3 13923028.54 348700653.6 216145935.9 1.085420e+10 1.352011e+09 \n",
173
+ "4 15393031.56 372012091.5 229529912.7 1.195600e+10 1.389080e+09 \n",
174
+ "\n",
175
+ " Tanzania Togo Uganda Zambia Zimbabwe \n",
176
+ "0 2.651730e+09 171057069.1 423008385.7 713000000.0 1.052990e+09 \n",
177
+ "1 2.826179e+09 178497098.3 441524109.0 696285714.3 1.096647e+09 \n",
178
+ "2 3.101590e+09 186745757.9 449012578.6 693142857.1 1.117602e+09 \n",
179
+ "3 3.456579e+09 202305865.2 516147798.7 718714285.7 1.159512e+09 \n",
180
+ "4 3.748841e+09 234572186.5 589056603.8 839428571.4 1.217138e+09 \n",
181
+ "\n",
182
+ "[5 rows x 34 columns]\n"
183
+ ]
184
+ }
185
+ ],
186
+ "source": [
187
+ "from sklearn.model_selection import train_test_split\n",
188
+ "print(data.head())\n",
189
+ "X = data.drop('Algeria',axis=1)\n",
190
+ "y = data['Algeria']\n",
191
+ "\n",
192
+ "X_train, X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42)\n"
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "execution_count": 6,
198
+ "id": "4d2ecbca",
199
+ "metadata": {
200
+ "execution": {
201
+ "iopub.execute_input": "2025-01-09T23:35:12.084723Z",
202
+ "iopub.status.busy": "2025-01-09T23:35:12.084288Z",
203
+ "iopub.status.idle": "2025-01-09T23:35:12.211636Z",
204
+ "shell.execute_reply": "2025-01-09T23:35:12.210433Z"
205
+ },
206
+ "papermill": {
207
+ "duration": 0.132424,
208
+ "end_time": "2025-01-09T23:35:12.213399",
209
+ "exception": false,
210
+ "start_time": "2025-01-09T23:35:12.080975",
211
+ "status": "completed"
212
+ },
213
+ "tags": []
214
+ },
215
+ "outputs": [
216
+ {
217
+ "data": {
218
+ "text/html": [
219
+ "<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LinearRegression()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">LinearRegression</label><div class=\"sk-toggleable__content\"><pre>LinearRegression()</pre></div></div></div></div></div>"
220
+ ],
221
+ "text/plain": [
222
+ "LinearRegression()"
223
+ ]
224
+ },
225
+ "execution_count": 6,
226
+ "metadata": {},
227
+ "output_type": "execute_result"
228
+ }
229
+ ],
230
+ "source": [
231
+ "from sklearn.linear_model import LinearRegression\n",
232
+ "from sklearn.metrics import mean_squared_error , mean_absolute_error, r2_score\n",
233
+ "\n",
234
+ "model = LinearRegression()\n",
235
+ "model.fit(X_train,y_train)"
236
+ ]
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "execution_count": 7,
241
+ "id": "447cddae",
242
+ "metadata": {
243
+ "execution": {
244
+ "iopub.execute_input": "2025-01-09T23:35:12.220052Z",
245
+ "iopub.status.busy": "2025-01-09T23:35:12.219685Z",
246
+ "iopub.status.idle": "2025-01-09T23:35:12.230343Z",
247
+ "shell.execute_reply": "2025-01-09T23:35:12.229397Z"
248
+ },
249
+ "papermill": {
250
+ "duration": 0.015608,
251
+ "end_time": "2025-01-09T23:35:12.231921",
252
+ "exception": false,
253
+ "start_time": "2025-01-09T23:35:12.216313",
254
+ "status": "completed"
255
+ },
256
+ "tags": []
257
+ },
258
+ "outputs": [
259
+ {
260
+ "name": "stdout",
261
+ "output_type": "stream",
262
+ "text": [
263
+ "Mean Squared error:9.904758040019183e+19\n",
264
+ "Mean Absolute Error:5989398763.378249\n",
265
+ "r2:0.9849119641737768\n"
266
+ ]
267
+ }
268
+ ],
269
+ "source": [
270
+ "y_pred = model.predict(X_test)\n",
271
+ "mse = mean_squared_error(y_test,y_pred)\n",
272
+ "mae = mean_absolute_error(y_test,y_pred)\n",
273
+ "r2 = r2_score(y_test,y_pred)\n",
274
+ "print(f\"Mean Squared error:{mse}\")\n",
275
+ "print(f\"Mean Absolute Error:{mae}\")\n",
276
+ "print(f\"r2:{r2}\")"
277
+ ]
278
+ }
279
+ ],
280
+ "metadata": {
281
+ "kaggle": {
282
+ "accelerator": "none",
283
+ "dataSources": [
284
+ {
285
+ "datasetId": 6455551,
286
+ "sourceId": 10415885,
287
+ "sourceType": "datasetVersion"
288
+ }
289
+ ],
290
+ "dockerImageVersionId": 30822,
291
+ "isGpuEnabled": false,
292
+ "isInternetEnabled": true,
293
+ "language": "python",
294
+ "sourceType": "notebook"
295
+ },
296
+ "kernelspec": {
297
+ "display_name": "Python 3",
298
+ "language": "python",
299
+ "name": "python3"
300
+ },
301
+ "language_info": {
302
+ "codemirror_mode": {
303
+ "name": "ipython",
304
+ "version": 3
305
+ },
306
+ "file_extension": ".py",
307
+ "mimetype": "text/x-python",
308
+ "name": "python",
309
+ "nbconvert_exporter": "python",
310
+ "pygments_lexer": "ipython3",
311
+ "version": "3.10.12"
312
+ },
313
+ "papermill": {
314
+ "default_parameters": {},
315
+ "duration": 4.759216,
316
+ "end_time": "2025-01-09T23:35:12.854678",
317
+ "environment_variables": {},
318
+ "exception": null,
319
+ "input_path": "__notebook__.ipynb",
320
+ "output_path": "__notebook__.ipynb",
321
+ "parameters": {},
322
+ "start_time": "2025-01-09T23:35:08.095462",
323
+ "version": "2.6.0"
324
+ }
325
+ },
326
+ "nbformat": 4,
327
+ "nbformat_minor": 5
328
+ }