Add your own method¶
A transfer method receives TransferInputs, declares what fields it needs, and predicts scores for
cold items.
Minimal method¶
import numpy as np
import pandas as pd
from warmtransfer.columns import Columns as C
from warmtransfer.methods.base import ColdStartMethod, register_method
from warmtransfer.types import TransferInputs
@register_method("constant_zero")
class ConstantZero(ColdStartMethod):
requires = frozenset()
def _fit(self, inputs: TransferInputs, seed: int) -> None:
return None
def predict(self, user_ids: np.ndarray, cold_item_ids: np.ndarray) -> pd.DataFrame:
self._check_fitted()
return pd.DataFrame(
{
C.User: np.repeat(user_ids, len(cold_item_ids)),
C.Item: np.tile(cold_item_ids, len(user_ids)),
C.Score: 0.0,
}
)
Declare inputs¶
Set requires to the fields your method actually needs:
donor_scorescontentsimilarityembeddingstrain_interactionsitem_metaval
The base class validates them before _fit runs.
Make it discoverable¶
Import the module from warmtransfer.methods.__init__ so @register_method(...) runs. Then add a
unit test that fits the method on a tiny TransferInputs fixture and verifies the output columns and
shape.
Use it in benchmark config¶
methods:
- name: constant_zero