milia.recommend.baselines#
Baselines a retrieval method has to beat.
The population mean is scikit-learn’s DummyRegressor(strategy="mean").
GroupMean predicts the mean outcome of the query’s group, the groups
coming from a clusterer (archetypes) or from a column of X.
Classes
|
Mean outcome of the query's group, falling back to the overall mean for unseen groups. |
- class milia.recommend.baselines.GroupMean(clusterer=None, column=None)#
Bases:
RegressorMixin,BaseEstimatorMean outcome of the query’s group, falling back to the overall mean for unseen groups.
- Parameters:
clusterer (
BaseEstimator|None) – Clusterer whose labels define the groups (fitted on the training rows, thenpredictassigns queries). Used whencolumnis None; a 5-cluster k-means by default.column (
int|None) – Column ofXholding a group label, instead of a clusterer.
Examples
>>> X = np.array([[0.0], [0.2], [9.0], [9.2]]) >>> from milia import make >>> GroupMean(clusterer=make("clusterer", "kmeans", n_clusters=2)).fit(X, [1.0, 3.0, 10.0, 12.0]).predict( ... [[0.1]] ... ).tolist() [2.0]
- groups(X, fit=False)#
Group label of each row: a column of
Xor the fitted clusterer’s assignment.
- fit(X, y)#
Learn each group’s mean outcome.
- predict(X)#
Each row’s group mean, or the overall mean for a group not seen in
fit.Examples
>>> import numpy as np >>> model = GroupMean(column=0).fit(np.array([[0.0], [0.0], [1.0]]), np.array([1.0, 3.0, 10.0])) >>> model.predict(np.array([[0.0], [1.0], [7.0]])).round(2).tolist() [2.0, 10.0, 4.67]
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
- Return type: