<jupyter_start><jupyter_text>Load ForecastingblablablaWe're using Building 7 as a reference for this (large commercial, >50,000 ppl)**Sources:**https://openei.org/datasets/dataset/consumption-outdoor-air-temperature-11-commercial-buildings<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from mpl_toolkits import mplot3d
import datetime
%matplotlib inline

df = pd.read_csv('./data/building60preoffice.csv')
df.head()
df.shape
# Set Date as index
df['Date'] = pd.to_datetime(df['Date'])
df = df.set_index(pd.DatetimeIndex(df['Date']))

df['hour'] = df['Date'].dt.hour

df.head()
df.shape[0]
sns.set(rc={'figure.figsize':(11, 4)})

df['Building 6 kW'].plot(linewidth=1)
fig = plt.figure(figsize=(8,6))
ax = plt.axes(projection="3d")

# z_line = np.linspace(0, 15, 1000)
# x_line = np.cos(z_line)
# y_line = np.sin(z_line)
# ax.plot3D(x_line, y_line, z_line, 'gray')

xs = df['hour']
ys = df['OAT']
zs = df['Building 6 kW']
# ax.scatter3D(xs, ys, zs, c=ys, cmap='hsv');
ax.scatter3D(xs, ys, zs);
ax.view_init(0, 0)

# ax.plot_wireframe(xs, ys, zs, rstride=5, cstride=5)

ax.set_xlabel('Hour')
ax.set_ylabel('OAT')
ax.set_zlabel('Energy (kW)')

plt.show()

# rotate the axes and update
# for angle in range(0, 360):
#     ax.view_init(30, angle)
#     plt.draw()
#     plt.pause(.001)
plt.scatter(df['hour'], df['Building 6 kW'])
# plt.title("Hour VS Energy")
plt.show()
plt.scatter(df['OAT'], df['Building 6 kW'])

plt.scatter(df['hour'], df['OAT'])
# Check for empty rows
df.columns[df.isnull().mean() == 0]

# No empty values
from sklearn.linear_model import SGDRegressor
X = df.as_matrix(columns=['hour', 'OAT'])
y = df['Building 6 kW'].tolist()

n_iter = np.ceil(10**6 / len(y))

clf = SGDRegressor(loss="squared_loss", penalty=None, max_iter=n_iter, tol=1e-3, random_state=42)
clf.fit(X, y)
X_pred = pd.DataFrame({'hour': [13], 'OAT': [35]})

y_pred = clf.predict(X_pred)

print(y_pred)
clf2 = SGDRegressor(penalty='l2', alpha=0.15, max_iter=n_iter, tol=1e-3, random_state=42)

clf2.fit(X,y)

X_pred2 = pd.DataFrame({'hour': [13], 'OAT': [35]})
y_pred2 = clf2.predict(X_pred2)

print(y_pred2)
# def sgdRun(X, y, X_pred, max_iter=1000):
#     clf = SGDRegressor(loss="squared_loss", penalty=None, max_iter=max_iter, tol=1e-3)
#     clf.fit(X, y)
    
#     y_pred = clf.predict(X_pred)
    
#     print("Max Iter = " + str(max_iter))
#     print(round(y_pred[0], 2))
# for i in range(25):
#     sgdRun(X, y, X_pred, (i+1)*1000)
df_w = pd.read_csv('./data/austin_weather.csv')
df_w.head()
df_w2 = df_w.set_index("Date")

df_w2 = df_w2['2016-01-01':'2016-12-31']
df_w2['Month'] = df_w2.index.to_series().apply(lambda x: pd.to_datetime(x).month)

df_w2.head()
sns.set(rc={'figure.figsize': (11,4)})

df_w2['TempHighF'].plot(linewidth=2);
df_w2['TempAvgF'].plot(linewidth=2);
df_w2['TempLowF'].plot(linewidth=2);
plt.title("Average Temperature (Austin, TX)")
# plt.savefig("total_listings_time.png")
df_w2.index
plt.plot(df_w2['Month'], df_w2['TempAvgF'], 'o', color='black');
df_ausTempH = pd.DataFrame(columns=['Date', 'Hour', 'TempAvgF'])
for index,row in df_w2.iterrows():
    for h in range(23):
        hrStr = str(h+1)
        if len(hrStr) == 1:
            hrStr = "0" + hrStr
        
        datetimeStr = index + " " + hrStr
        
        df_ausTempH = df_ausTempH.append({'Date': datetime.datetime.strptime(datetimeStr, '%Y-%m-%d %H'), 'Hour': h+1, 'TempAvgF': row['TempAvgF']}, ignore_index=True)
print(df_ausTempH.shape)
df_ausTempH.head(48)
# pd.to_datetime(df['Date'] + ' ' + df['Time'])

df_ausTempH['Date'] = pd.to_datetime(df_ausTempH['Date'])
# df_ausTempH['Date'] = df_ausTempH['Date'].replace(hour=df_ausTempH['Hour'])

# df_ausTempH['Date'] = df_ausTempH['Date'].dt.normalize() + datetime.timedelta(hours=df_ausTempH['Hour'])
df_ausTempH['Date'] = df_ausTempH['Date'].dt.normalize() + df_ausTempH['Hour'].map(datetime.timedelta)


df_ausTempH = df_ausTempH.set_index(pd.DatetimeIndex(df_ausTempH['Date']))
df_ausTempH.head()
# df_ausTempH.to_csv('Austin_TempH.csv')
X_pred_F = df_ausTempH[['Hour', 'TempAvgF']]

y_pred3 = clf2.predict(X_pred_F)

print(y_pred3)
print(y_pred3.max())
print(y_pred3.min())
len(y_pred3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.195837275307474, 'fraction_numerical': 0.03358561967833491, 'mean_word_length': 5.51617873651772, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '228221', 'license': 'CNRI-Python', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1823, 'n_words': 298, 'path': 'old/.ipynb_checkpoints/Commercial Load Forecast-Copy1-checkpoint.ipynb', 'repo_name': 'nickbae91/commercial_storage_analysis', 'size': '4228'}