'''script to scrape and plot the temperatures for the year to date (2017)'''

from year import Year
from visualisation.scattergl_plot import plot_large_scatter

#plot temperatures of year to date (2017)
#initiate a 'year object' and load the data from the web
yeartwelve = Year('17')
yeartwelve.load_all_data()

#assign the temperature and date data into variables yeartemps and yeartimes
yeartemps = yeartwelve.get_all_temps()
yeartimes = yeartwelve.get_all_datetimes()

#plot using plotly
plot_large_scatter(yeartimes, yeartemps, 'Date', 'Temperature (C)',
                   'yeartemps')
Exemplo n.º 2
0
from sklearn import linear_model
from visualisation.scattergl_plot import plot_two_scatters
from linear_regression_ttest import get_slope_t_statistic, get_two_sided_p_value

#create list of dates in two character string format (corresponds to the format of the web files)
YEARINTS = range(2, 17)  #years from 2002 to 2016 inclusive
YEARLIST = [str(yr).zfill(2) for yr in YEARINTS]  # string format of years

#load all years' data
average_temperatures = []
year_names = []
for year_string in YEARLIST:
    print year_string
    year_object = Year(year_string)
    year_object.load_all_data()
    temperatures = year_object.get_all_temps()
    average_temperatures.append(np.average(temperatures))
    year_names.append(float(year_string) + 2000)
print average_temperatures

# Create linear regression object
regr = linear_model.LinearRegression()
x_values = np.reshape(YEARINTS, (len(YEARINTS), 1))

# Fit the data
regr.fit(x_values, average_temperatures)

# make the best-fit line ("prediction")
y_pred = regr.predict(x_values)
print y_pred