-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from spaceappsgryffindor/Ishitara-patch-1
Add files via upload
- Loading branch information
Showing
1 changed file
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,327 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import matplotlib\n", | ||
"import scipy\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import sklearn.datasets\n", | ||
"import sklearn.cross_validation as cv\n", | ||
"import sklearn.linear_model as lm\n", | ||
"import scipy.io\n", | ||
"import sklearn.model_selection\n", | ||
"import pandas as pd\n", | ||
"#importing data\n", | ||
"file = 'data.csv'\n", | ||
"file1='test.csv'\n", | ||
"data=pandas.read_csv(file)\n", | ||
"data2=pandas.read_csv(file1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 108, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
" Longitude Latitude Population estimate 2015 \\\n", | ||
"0 42.251000 34.157110 815484 \n", | ||
"1 31.491310 30.589330 318335 \n", | ||
"2 40.769300 36.493910 1303724 \n", | ||
"3 -86.407580 38.586280 852385 \n", | ||
"4 -86.407580 38.586280 4197041 \n", | ||
"5 -81.792100 36.631340 2517464 \n", | ||
"6 36.186686 32.842770 838532 \n", | ||
"7 36.083850 34.944510 670683 \n", | ||
"8 36.718079 34.731899 1549477 \n", | ||
"9 36.276527 33.513800 1471348 \n", | ||
"10 -86.407580 38.586280 83601 \n", | ||
"\n", | ||
" Refugee Settlement Population \n", | ||
"0 121750 \n", | ||
"1 815 \n", | ||
"2 173100 \n", | ||
"3 1115 \n", | ||
"4 12384 \n", | ||
"5 16424 \n", | ||
"6 2570 \n", | ||
"7 2267 \n", | ||
"8 16287 \n", | ||
"9 250 \n", | ||
"10 770 \n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"X=data.iloc[:,1:5]\n", | ||
"print (X)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 116, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0 512.587139\n", | ||
"1 0.863306\n", | ||
"2 43.481147\n", | ||
"3 11.683241\n", | ||
"4 577.981331\n", | ||
"5 0.700724\n", | ||
"6 7.585724\n", | ||
"7 5.810037\n", | ||
"8 32.429709\n", | ||
"9 0.000000\n", | ||
"10 4.478992\n", | ||
"Name: Srface water area, dtype: float64\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"108.87285011281818" | ||
] | ||
}, | ||
"execution_count": 116, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"Y=data.iloc[:,5]\n", | ||
"print (Y)\n", | ||
"A=sum(Y)/len(Y)\n", | ||
"A" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 110, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0 0.000000\n", | ||
"1 0.000000\n", | ||
"2 0.000000\n", | ||
"3 0.000000\n", | ||
"4 0.000000\n", | ||
"5 0.000000\n", | ||
"6 2.370552\n", | ||
"7 1.752391\n", | ||
"8 0.000000\n", | ||
"9 0.000000\n", | ||
"10 0.000000\n", | ||
"11 0.000000\n", | ||
"12 0.000000\n", | ||
"13 0.323249\n", | ||
"14 0.000000\n", | ||
"15 0.000000\n", | ||
"16 0.000000\n", | ||
"17 8.373273\n", | ||
"18 0.000000\n", | ||
"19 0.000000\n", | ||
"20 0.000000\n", | ||
"21 0.000000\n", | ||
"22 0.000000\n", | ||
"23 0.731946\n", | ||
"24 6.407581\n", | ||
"25 3.193754\n", | ||
"26 4.780310\n", | ||
"27 3.430400\n", | ||
"28 3.605868\n", | ||
"29 5.660617\n", | ||
"30 10.390659\n", | ||
"31 4.424646\n", | ||
"32 4.152072\n", | ||
"33 4.960464\n", | ||
"34 0.000000\n", | ||
"35 5.550130\n", | ||
"36 8.468886\n", | ||
"37 14.963532\n", | ||
"Name: water, dtype: float64\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"Z=data2.iloc[:,4]\n", | ||
"print (Z)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 111, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 11.68324075 11.68324075 -246.46074629]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from sklearn.model_selection import train_test_split \n", | ||
"from sklearn.linear_model import LinearRegression\n", | ||
"from sklearn.model_selection import cross_val_predict\n", | ||
"from sklearn.model_selection import cross_val_score\n", | ||
"from sklearn.metrics import mean_squared_error\n", | ||
"from sklearn.metrics import r2_score\n", | ||
"\n", | ||
"\n", | ||
"X_train, X_test, y_train, y_test = train_test_split(X, Y)# splitting data into train and test set\n", | ||
"model =LinearRegression()#applying regression on each fold\n", | ||
"model.fit(X_train,y_train)#fitting the model on each fold\n", | ||
"predicted = cross_val_predict(model, X_test, y_test, cv=2)#performance on testset\n", | ||
"print(predicted) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 125, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"array([108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011, 108.87285011, 108.87285011,\n", | ||
" 108.87285011, 108.87285011])" | ||
] | ||
}, | ||
"execution_count": 125, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"arr=np.repeat(A, 38)\n", | ||
"arr" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 128, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mse2=(arr-Z)/100" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 129, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0 1.088729\n", | ||
"1 1.088729\n", | ||
"2 1.088729\n", | ||
"3 1.088729\n", | ||
"4 1.088729\n", | ||
"5 1.088729\n", | ||
"6 1.065023\n", | ||
"7 1.071205\n", | ||
"8 1.088729\n", | ||
"9 1.088729\n", | ||
"10 1.088729\n", | ||
"11 1.088729\n", | ||
"12 1.088729\n", | ||
"13 1.085496\n", | ||
"14 1.088729\n", | ||
"15 1.088729\n", | ||
"16 1.088729\n", | ||
"17 1.004996\n", | ||
"18 1.088729\n", | ||
"19 1.088729\n", | ||
"20 1.088729\n", | ||
"21 1.088729\n", | ||
"22 1.088729\n", | ||
"23 1.081409\n", | ||
"24 1.024653\n", | ||
"25 1.056791\n", | ||
"26 1.040925\n", | ||
"27 1.054424\n", | ||
"28 1.052670\n", | ||
"29 1.032122\n", | ||
"30 0.984822\n", | ||
"31 1.044482\n", | ||
"32 1.047208\n", | ||
"33 1.039124\n", | ||
"34 1.088729\n", | ||
"35 1.033227\n", | ||
"36 1.004040\n", | ||
"37 0.939093\n", | ||
"Name: water, dtype: float64" | ||
] | ||
}, | ||
"execution_count": 129, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"mse2\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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.6.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |