Learn model from the base model .. note:: The attribute names of learned model should `not` start with '_'. So that the model could be dumped to disk. The following code example shows how to retrieve `x_train`, `y_train` and `w_train` from the `dat
(self, dataset: Dataset, reweighter: Reweighter)
| 23 | """Learnable Models""" |
| 24 | |
| 25 | def fit(self, dataset: Dataset, reweighter: Reweighter): |
| 26 | """ |
| 27 | Learn model from the base model |
| 28 | |
| 29 | .. note:: |
| 30 | |
| 31 | The attribute names of learned model should `not` start with '_'. So that the model could be |
| 32 | dumped to disk. |
| 33 | |
| 34 | The following code example shows how to retrieve `x_train`, `y_train` and `w_train` from the `dataset`: |
| 35 | |
| 36 | .. code-block:: Python |
| 37 | |
| 38 | # get features and labels |
| 39 | df_train, df_valid = dataset.prepare( |
| 40 | ["train", "valid"], col_set=["feature", "label"], data_key=DataHandlerLP.DK_L |
| 41 | ) |
| 42 | x_train, y_train = df_train["feature"], df_train["label"] |
| 43 | x_valid, y_valid = df_valid["feature"], df_valid["label"] |
| 44 | |
| 45 | # get weights |
| 46 | try: |
| 47 | wdf_train, wdf_valid = dataset.prepare(["train", "valid"], col_set=["weight"], |
| 48 | data_key=DataHandlerLP.DK_L) |
| 49 | w_train, w_valid = wdf_train["weight"], wdf_valid["weight"] |
| 50 | except KeyError as e: |
| 51 | w_train = pd.DataFrame(np.ones_like(y_train.values), index=y_train.index) |
| 52 | w_valid = pd.DataFrame(np.ones_like(y_valid.values), index=y_valid.index) |
| 53 | |
| 54 | Parameters |
| 55 | ---------- |
| 56 | dataset : Dataset |
| 57 | dataset will generate the processed data from model training. |
| 58 | |
| 59 | """ |
| 60 | raise NotImplementedError() |
| 61 | |
| 62 | @abc.abstractmethod |
| 63 | def predict(self, dataset: Dataset, segment: Union[Text, slice] = "test") -> object: |
no outgoing calls