-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (47 loc) · 1.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pandas as pd
import numpy as np
import sklearn as sk
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
# read the cleaned data
data = pd.read_csv("data_final.csv")
X = data.drop(['PrecipitationSumInches'], axis=1)
Y = data['PrecipitationSumInches']
Y = Y.values.reshape(-1, 1)
day_index = 798
days = [i for i in range(Y.size)]
clf = LinearRegression()
clf.fit(X, Y)
inp = np.array([[74], [60], [45], [67], [49], [43], [33], [45],
[57], [29.68], [10], [7], [2], [0], [20], [4], [31]])
inp = inp.reshape(1, -1)
# Print output
print('The precipitation in inches for the input is:', clf.predict(inp))
print('The precipitation trend graph: ')
plt.scatter(days, Y, color='g')
plt.scatter(days[day_index], Y[day_index], color='r')
plt.title('Precipitation level')
plt.xlabel('Days')
plt.ylabel('Precipitation in inches')
# Plot a graph of precipitation levels vs n# of days
plt.show()
x_f = X.filter(['TempAvgF', 'DewPointAvgF', 'HumidityAvgPercent',
'SeaLevelPressureAvgInches', 'VisibilityAvgMiles',
'WindAvgMPH'], axis=1)
print('Preciptiation Vs Selected Attributes Graph: ')
for i in range(x_f.columns.size):
plt.subplot(2, 3, i+1)
plt.scatter(days, x_f[x_f.columns.values[i][:100]], color='g')
plt.scatter(days[day_index], x_f[x_f.columns.values[i]]
[day_index], color='r')
plt.title(x_f.columns.values[i])
# plot a graph with a few features vs precipitation to observe the trends
plt.show()
#read data in pandas dataframe
# data=pd.read_csv("rainfallcsv.csv")
#drop (delete) the unnecessary columns in the data
# data=data.drop(['Events','Date','SeaLevelPressureHighInches','SeaLevelPressureLowInches'],axis=1)
# data=data.replace('T',0.0)
# data=data.replace('-',0.0)
#save the data in csv file
# data.to_csv('data_final.csv')