You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an optimized version of your program. The main area to optimize is the `_classify` method: using `sum()` is already efficient, but `[val for _ in features]` can be replaced with list multiplication, which is faster in Python. We also avoid recalculating `total % self.num_classes` for every element.
This runs faster, especially for large lists of `features`, because the modulo is computed just once and the resultant list is constructed in a single step.
0 commit comments