<jupyter_start><jupyter_text>More Analysis of NEEP Heat Pump Data<jupyter_code>import math
import sys
import pandas as pd
import numpy as np

# import matplotlib pyplot commands
from matplotlib.pyplot import *
 
# Show Plots in the Notebook
%matplotlib inline
 
# 'style' the plot like fivethirtyeight.com website
style.use('bmh')

%load_ext autoreload
%autoreload 2
rcParams['figure.figsize']= (10, 8)   # set Chart Size
rcParams['font.size'] = 14            # set Font size in Chart
# Put the heat-pump-calc project in the path, so the library module
# can be accessed.
sys.path.insert(0, '../../heat-pump-calc')
import heatpump.library as library
dfht = library.df_heatpumps
dfht.head()<jupyter_output><empty_output><jupyter_text>Analyze Correlation between HSPF and COPs at Max Capacity<jupyter_code>from sklearn import linear_model
from sklearn.metrics import mean_squared_error, r2_score
regr = linear_model.LinearRegression()
X = dfht[['hspf']]
y = dfht.cop_17F_max
regr.fit(X, y)

y_pred = regr.predict(X)

# The coefficients
print('Coefficients: \n', regr.coef_)
print('Intercept: %.2f' % regr.intercept_)
# The mean squared error
print("Mean squared error: %.2f"
      % mean_squared_error(y, y_pred))
# Explained variance score: 1 is perfect prediction
print('R-squared: %.3f' % r2_score(y, y_pred))
plot(X.hspf, y, '.')
xlabel('HSPF')
ylabel('COP at 17 F, Max Capacity')<jupyter_output>Coefficients: 
 [-0.00819642]
Intercept: 2.49
Mean squared error: 0.12
R-squared: 0.001<jupyter_text>Look at Bins of HSPF and Plot COPs<jupyter_code>dfht['hspf_bin'] = dfht.hspf // 0.5
dfht_bin = dfht.groupby('hspf_bin').mean()
dfht_bin.drop(columns=['in_pwr_5F_max', 'capacity_5F_max', 'in_pwr_47F_min'], inplace=True)
dfht_bin.set_index('hspf', inplace=True)
dfht_bin.plot()
ylabel('COP')
xlabel('HSPF')
import altair as alt
alt.data_transformers.enable('json')
alt.Chart(dfht).mark_circle(size=60).encode(
    x=alt.X('hspf', type='quantitative', scale=alt.Scale(domain=[9.5, 15.5])),
    y=alt.Y(alt.repeat("row"), type='quantitative', scale=alt.Scale(domain=[1.5, 5])),
    color='zones',
    tooltip=['brand', 'outdoor_model']
).properties(
    width=350
).facet(
    column='zones:N'
).repeat(
    row=['cop_5F_max', 'cop_17F_max', 'cop_47F_max'],
).interactive()
alt.Chart(dfht).mark_tick(size=10, thickness=1.5).encode(
    x=alt.X('hspf', scale=alt.Scale(domain=[9.5, 15.5])),
    y=alt.Y('zones'),
    tooltip=['brand', 'outdoor_model', 'indoor_model', 'hspf', 'capacity_5F_max']
).interactive()
alt.Chart(dfht).mark_tick(size=10, thickness=2).encode(
    x=alt.X('hspf', scale=alt.Scale(domain=[9.5, 15.5])),
    y=alt.Y('brand'),
    color='zones',
    tooltip=['brand', 'outdoor_model', 'indoor_model', 'hspf', 'capacity_5F_max']
).properties(width=300).facet(column='zones').interactive()
dfht_grouped = dfht[['brand', 'zones', 'hspf']].groupby(['brand', 'zones'])
dfht_avg = dfht_grouped.agg([np.mean, np.min, np.max]).reset_index()
dfht_avg.columns = ['_'.join(col).strip().strip('_') for col in dfht_avg.columns.values]
dfht_avg.head()
cht = alt.Chart().mark_circle(size=50, color='blue').encode(
    x=alt.X('hspf_mean', type='quantitative', 
            scale=alt.Scale(domain=[10., 15]),
            axis=alt.Axis(title='HSPF')),
    y=alt.Y('brand', type='nominal'),
    color='zones',
    tooltip=['brand', 'hspf_mean']
).properties(width=270)
cht += alt.Chart().mark_rule(color='blue').encode(
    x='hspf_amin:Q',
    x2='hspf_amax:Q',
    y='brand:N',
    color='zones',
).properties(width=270)
cht.facet(column='zones:N', data=dfht_avg)
cht = alt.Chart(dfht, height=150).mark_bar().encode(
    alt.X('hspf', bin=alt.BinParams(maxbins=30), axis=alt.Axis(title='HSPF')),
    y=alt.Y('count(*):Q', axis=alt.Axis(title='Number of Models')),
    color='zones',
    row=alt.Row('zones', title='Number of Zones'),
)
cht.save('images/single_multi_hspf.png', scale_factor=1.5)
cht<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1823739174732552, 'fraction_numerical': 0.02598064187468161, 'mean_word_length': 5.577889447236181, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '458887', 'license': 'MIT', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1539, 'n_words': 280, 'path': 'general/neep_eda3.ipynb', 'repo_name': 'alanmitchell/heat-pump-study', 'size': '3926'}