Silly question: LabelEncoder #40

Closed
opened 2025-11-02 00:02:11 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @knosing on GitHub (Nov 23, 2022).

While creating the LabelEncoder class, I couldnt understand why return self in class method fit(self,y)?
My understanding is that when we call this method, the object variables are updated so no need for self?
Please correct me if I'm wrong, just trying to reason myself with each step of the code.

    def fit(self, y):
        classes = np.unique(y)
        for i, class_ in enumerate(classes):
            self.class_to_index[class_] = i
        self.index_to_class = {v: k for k,v in self.class_to_index.items()}
        self.classes = list(self.class_to_index.keys())
        return self #Why?
Originally created by @knosing on GitHub (Nov 23, 2022). While creating the `LabelEncoder` class, I couldnt understand why `return self` in class method `fit(self,y)`? My understanding is that when we call this method, the object variables are updated so no need for self? Please correct me if I'm wrong, just trying to reason myself with each step of the code. ```python def fit(self, y): classes = np.unique(y) for i, class_ in enumerate(classes): self.class_to_index[class_] = i self.index_to_class = {v: k for k,v in self.class_to_index.items()} self.classes = list(self.class_to_index.keys()) return self #Why? ```
Author
Owner

@knosing commented on GitHub (Nov 23, 2022):

I got it, for method chaining this is a standard form.
Anyways, thanks a lot for this course. Learning a lot of new things!

@knosing commented on GitHub (Nov 23, 2022): I got it, for method chaining this is a standard form. Anyways, thanks a lot for this course. Learning a lot of new things!
Author
Owner

@GokuMohandas commented on GitHub (Nov 25, 2022):

Hey @knosing, I apologize for delay (outside of the country this month). But yup you got it and glad you're enjoying the material! I should have some major additions (and standardizations as the space matures) by March/April next year so look out for those updates!

@GokuMohandas commented on GitHub (Nov 25, 2022): Hey @knosing, I apologize for delay (outside of the country this month). But yup you got it and glad you're enjoying the material! I should have some major additions (and standardizations as the space matures) by March/April next year so look out for those updates!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/Made-With-ML#40