online-ml / river

🌊 Online machine learning in Python
https://riverml.xyz
BSD 3-Clause "New" or "Revised" License
5.03k stars 540 forks source link

Per-label classifier #1408

Open MaxHalford opened 11 months ago

MaxHalford commented 11 months ago
apagliero commented 7 months ago

Hello @MaxHalford , very nice project. Congrats to you and all the contributors for the work done. @atroyanovsky and myself would like to contribute to the library and be assigned to this issue if possible.

MaxHalford commented 7 months ago

Hey @apagliero! Thanks for the enthusiasm. Knock yourself out!

tensor-works commented 4 months ago

How is this comming along? Currently interested in using a PerOutputClassifier

tensor-works commented 4 months ago

Should be relatively trivial I suggest: ` class PerLabelClassifier(base.Wrapper, base.Classifier):

def __init__(self, classifier):
    self.classifier = classifier
    new_clf = functools.partial(copy.deepcopy, classifier)
    self.classifiers = collections.defaultdict(new_clf)
    self.classes = set()

@property
def _wrapped_model(self):
    return self.classifier

@property
def _multiclass(self):
    return True

@classmethod
def _unit_test_params(cls):
    yield {"classifier": linear_model.LogisticRegression()}

def learn_one(self, x, y, **kwargs):
    for label_name, y_label in y.items():
        self.classes.add(label_name)
        self.classifiers[label_name].learn_one(x, y_label)

def predict_one(self, x, **kwargs):
    predictions = {}
    for label in self.classifiers:
        predictions[label] = self.classifiers[label].predict_one(x)

    return predictions

`

apagliero commented 4 months ago

Hi everyone. Sorry for the late update, unfortunately we've been too busy and haven't had time to progress on this issue.