Update hmc_learner.py
Browse files- hmc_learner.py +8 -4
hmc_learner.py
CHANGED
|
@@ -50,8 +50,10 @@ def preprocess_data(df: pd.DataFrame) -> pd.DataFrame:
|
|
| 50 |
# risk_score as is (continuous)
|
| 51 |
df['risk_score'] = df['risk_score'].astype(float)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
# confidence
|
| 57 |
df['confidence'] = df['confidence'].astype(float)
|
|
@@ -73,7 +75,8 @@ def build_model(df: pd.DataFrame):
|
|
| 73 |
β_env = pm.Normal("β_env", mu=0, sigma=1)
|
| 74 |
β_role = pm.Normal("β_role", mu=0, sigma=1)
|
| 75 |
β_risk = pm.Normal("β_risk", mu=0, sigma=1)
|
| 76 |
-
β
|
|
|
|
| 77 |
β_conf = pm.Normal("β_conf", mu=0, sigma=1)
|
| 78 |
|
| 79 |
# Linear predictor
|
|
@@ -81,7 +84,8 @@ def build_model(df: pd.DataFrame):
|
|
| 81 |
β_env * df['env_prod'].values +
|
| 82 |
β_role * df['role_junior'].values +
|
| 83 |
β_risk * (df['risk_score'].values - 0.5) + # center risk around 0.5
|
| 84 |
-
β
|
|
|
|
| 85 |
β_conf * (df['confidence'].values - 0.5)) # center confidence
|
| 86 |
|
| 87 |
# Likelihood
|
|
|
|
| 50 |
# risk_score as is (continuous)
|
| 51 |
df['risk_score'] = df['risk_score'].astype(float)
|
| 52 |
|
| 53 |
+
# Cyclical encoding of hour
|
| 54 |
+
hours = df['hour_of_day'].values
|
| 55 |
+
df['hour_sin'] = np.sin(2 * np.pi * hours / 24)
|
| 56 |
+
df['hour_cos'] = np.cos(2 * np.pi * hours / 24)
|
| 57 |
|
| 58 |
# confidence
|
| 59 |
df['confidence'] = df['confidence'].astype(float)
|
|
|
|
| 75 |
β_env = pm.Normal("β_env", mu=0, sigma=1)
|
| 76 |
β_role = pm.Normal("β_role", mu=0, sigma=1)
|
| 77 |
β_risk = pm.Normal("β_risk", mu=0, sigma=1)
|
| 78 |
+
β_hour_sin = pm.Normal("β_hour_sin", mu=0, sigma=1)
|
| 79 |
+
β_hour_cos = pm.Normal("β_hour_cos", mu=0, sigma=1)
|
| 80 |
β_conf = pm.Normal("β_conf", mu=0, sigma=1)
|
| 81 |
|
| 82 |
# Linear predictor
|
|
|
|
| 84 |
β_env * df['env_prod'].values +
|
| 85 |
β_role * df['role_junior'].values +
|
| 86 |
β_risk * (df['risk_score'].values - 0.5) + # center risk around 0.5
|
| 87 |
+
β_hour_sin * df['hour_sin'].values +
|
| 88 |
+
β_hour_cos * df['hour_cos'].values +
|
| 89 |
β_conf * (df['confidence'].values - 0.5)) # center confidence
|
| 90 |
|
| 91 |
# Likelihood
|