-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.py
90 lines (60 loc) · 2.23 KB
/
main2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# # Importing libraries
# import pandas as pd
# import numpy as np
# import sklearn as sk
# from sklearn.linear_model import LinearRegression
# import matplotlib.pyplot as plt
# data = pd.read_csv("Austin_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)
# # sample input
# 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))
# import the libraries
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("Austin_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(3, 2, 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()