Skip to content

Commit

Permalink
apply weights on evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock committed Dec 23, 2024
1 parent 6471636 commit 4fa1d69
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/fsrs_optimizer/fsrs_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,11 @@ def evaluate(self, save_to_file=True):
lambda row: -np.log(row["p"]) if row["y"] == 1 else -np.log(1 - row["p"]),
axis=1,
)
self.dataset["log_loss"] = (
self.dataset["log_loss"]
* self.dataset["weights"]
/ self.dataset["weights"].mean()
)
loss_before = self.dataset["log_loss"].mean()

my_collection = Collection(self.w, self.float_delta_t)
Expand All @@ -1555,6 +1560,11 @@ def evaluate(self, save_to_file=True):
lambda row: -np.log(row["p"]) if row["y"] == 1 else -np.log(1 - row["p"]),
axis=1,
)
self.dataset["log_loss"] = (
self.dataset["log_loss"]
* self.dataset["weights"]
/ self.dataset["weights"].mean()
)
loss_after = self.dataset["log_loss"].mean()
if save_to_file:
tmp = self.dataset.copy()
Expand Down Expand Up @@ -2101,10 +2111,10 @@ def count_lapse(r_history, t_history):
)
tmp = (
tmp.groupby(["delta_t", "i", "lapse"])
.agg({"y": "mean", "p": "mean", "card_id": "count"})
.agg({"y": "mean", "p": "mean", "weights": "sum"})
.reset_index()
)
return root_mean_squared_error(tmp["y"], tmp["p"], sample_weight=tmp["card_id"])
return root_mean_squared_error(tmp["y"], tmp["p"], sample_weight=tmp["weights"])


def wrap_short_term_ratings(r_history, t_history):
Expand Down

0 comments on commit 4fa1d69

Please sign in to comment.