Skip to content

Instantly share code, notes, and snippets.

@AtlasPilotPuppy
Created September 16, 2014 20:48
Show Gist options
  • Save AtlasPilotPuppy/4660f07e069c73ed18db to your computer and use it in GitHub Desktop.
Save AtlasPilotPuppy/4660f07e069c73ed18db to your computer and use it in GitHub Desktop.
Whiteman data joined with Vehicle data(2008- 2013)
import pandas as pd
import numpy as np
import statsmodels.formula.api as sm
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
whiteman_pems = pd.read_csv('whiteman_pems.csv')
whiteman_cleaned = whiteman_pems.fillna(0)
model = sm.OLS(whiteman_cleaned['h22'],whiteman_cleaned['VHT'])
fitted = model.fit()
summary_file = open('summary.txt', 'w')
summary_file.write(fitted.summary().as_text())
plt.plot(whiteman_cleaned['VHT'], whiteman_cleaned['h22'], 'ro')
plt.plot(whiteman_cleaned['VHT'], fitted.fittedvalues, 'b')
plt.legend(['Data', 'Fitted model'])
plt.xlabel('Vehicle Hours')
plt.ylabel('H22')
plt.title('H22 dependence on traffic')
pp = PdfPages('whiteman_traffic.pdf')
plt.savefig(pp, format='pdf')
pp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment