Skip to content

Commit

Permalink
Fix datetime type cast. Fix hinge loss
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmeissnercrm committed Sep 12, 2024
1 parent 8d8c38d commit 4c67b51
Show file tree
Hide file tree
Showing 3 changed files with 792 additions and 699 deletions.
15 changes: 12 additions & 3 deletions bluecast/conformal_prediction/nonconformity_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def hinge_loss(

for true_class, preds_arr in zip(y_true, y_hat):
hinge_losses.append(1 - preds_arr[true_class])
return np.asarray(hinge_losses)
try:
return np.asarray(hinge_losses, dtype="float64")
except ValueError:
return np.asarray(hinge_losses, dtype="object")


def margin_nonconformity_measure(
Expand Down Expand Up @@ -71,7 +74,10 @@ def margin_nonconformity_measure(
probas_y_false = np.delete(preds_arr, true_class)
prob_y_most_likely_false = np.max(probas_y_false)
mnm_losses.append(prob_y_true - prob_y_most_likely_false)
return np.asarray(mnm_losses)
try:
return np.asarray(mnm_losses, dtype="float64")
except ValueError:
return np.asarray(mnm_losses, dtype="object")


def brier_score(
Expand All @@ -94,4 +100,7 @@ def brier_score(
brier_losses = []
for true_class, preds_arr in zip(y_true, y_hat):
brier_losses.append((1 - preds_arr[true_class]) ** 2)
return np.asarray(brier_losses)
try:
return np.asarray(brier_losses, dtype="float64")
except ValueError:
return np.asarray(brier_losses, dtype="object")
12 changes: 6 additions & 6 deletions bluecast/preprocessing/datetime_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ def date_converter(

for c in date_columns:
if "year" in date_parts:
df[str(c) + "_year"] = df[c].dt.year.astype(int)
df[str(c) + "_year"] = df[c].dt.year.astype(float)
if "month" in date_parts:
df[str(c) + "_month"] = df[c].dt.month.astype(int)
df[str(c) + "_month"] = df[c].dt.month.astype(float)
if "week_of_year" in date_parts:
df[str(c) + "_week_of_year"] = df[c].dt.isocalendar().week.astype(int)
df[str(c) + "_week_of_year"] = df[c].dt.isocalendar().week.astype(float)
if "day" in date_parts:
df[str(c) + "_day"] = df[c].dt.day.astype(int)
df[str(c) + "_day"] = df[c].dt.day.astype(float)
if "dayofweek" in date_parts:
df[str(c) + "_dayofweek"] = df[c].dt.dayofweek.astype(int)
df[str(c) + "_dayofweek"] = df[c].dt.dayofweek.astype(float)
if "hour" in date_parts:
df[str(c) + "_hour"] = df[c].dt.hour.astype(int)
df[str(c) + "_hour"] = df[c].dt.hour.astype(float)
df = df.drop(c, axis=1)
return df
Loading

0 comments on commit 4c67b51

Please sign in to comment.