-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvisualize.py
More file actions
65 lines (50 loc) · 1.72 KB
/
Copy pathvisualize.py
File metadata and controls
65 lines (50 loc) · 1.72 KB
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
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 07:57:44 2015
@author: Steve Elston
This file contains code to visualize the CA Milk data set
"""
def azureml_main(frame1):
# Set backend
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import milkutilities as mu
from sklearn import linear_model
Azure = False
X = frame1[['Month.Count', 'monthNumCubed']].as_matrix()
Y = frame1['Milk.Prod'].as_matrix()
regr = linear_model.LinearRegression()
regr.fit(X, Y)
frame1['Predicted'] = regr.predict(X).tolist()
frame1['Resid'] = frame1['Milk.Prod'] - frame1['Predicted']
## Add a time index to the data frame
frame1 = mu.add_time_index(frame1)
fig1 = plt.figure(1, figsize = (12,9))
ax = fig1.gca()
frame1[['Milk.Prod', 'Predicted']].plot(ax = ax)
plt.xlabel("Date")
plt.ylabel("Log CA milk production")
plt.title("Log of milk produciton vs. date")
plt.show()
if(Azure == True): fig1.savefig('scatter1.png')
fig2 = plt.figure(1, figsize = (12,9))
fig2.clf()
ax = fig2.gca()
frame1['Resid'].plot(ax = ax)
plt.xlabel("Date")
plt.ylabel("Residuals of linear model")
plt.title("Residuals of linear model vs. date")
plt.show()
if(Azure == True): fig2.savefig('scatter2.png')
fig3 = plt.figure(1, figsize = (12,9))
fig3.clf()
ax = fig3.gca()
frame1.boxplot( column = ['Resid'], ax = ax,
by = ['Month.Number','Month'])
plt.xlabel("Month of year")
plt.ylabel("Residuals of linear model")
plt.title("Residuals of linear model by Month")
plt.show()
if(Azure == True): fig3.savefig('scatter3.png')
return frame1