Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feture] get label mean if reference is not None #41

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mqboost/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MQDataset:
data (pd.DataFrame | pd.Series | np.ndarray): The input features.
label (pd.Series | np.ndarray): The target labels (if provided).
model (str): The model type (LightGBM or XGBoost).
reference (MQBoost | None): Reference dataset for label encoding.
reference (MQBoost | None): Reference dataset for label encoding and label mean.

Property:
train_dtype: Returns the data type function for training data.
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
self._data = prepare_x(x=_data, alphas=self._alphas)
self._columns = self._data.columns
if label is not None:
self._label_mean = label.mean()
self._label_mean = reference.label_mean if reference else label.mean()
self._label = prepare_y(y=label - self._label_mean, alphas=self._alphas)
self._is_none_label = False

Expand Down
5 changes: 5 additions & 0 deletions mqboost/regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ def fit(
self,
dataset: MQDataset,
eval_set: MQDataset | None = None,
**kwargs,
) -> None:
"""
Fit the regressor to the dataset.
Args:
dataset (MQDataset): The dataset to fit the model on.
eval_set (Optional[MQDataset]):
The validation dataset. If None, the dataset is used for evaluation.
**kwargs:
train parameters.
"""
if eval_set:
_eval_set = eval_set.dtrain
Expand Down Expand Up @@ -92,6 +95,7 @@ def fit(
params=params,
feval=self._MQObj.feval,
valid_sets=[_eval_set],
**kwargs,
)
elif self.__is_xgb:
self.model = xgb.train(
Expand All @@ -101,6 +105,7 @@ def fit(
obj=self._MQObj.fobj,
custom_metric=self._MQObj.feval,
evals=[(_eval_set, "eval")],
**kwargs,
)
self._colnames = dataset.columns.to_list()
self._fitted = True
Expand Down
Loading