Compute class weight function issue in ‘sklearn’ library when used in ‘Keras’ classification (Python 3.8, only in VS code)

We Are Going To Discuss About Compute class weight function issue in ‘sklearn’ library when used in ‘Keras’ classification (Python 3.8, only in VS code). So lets Start this Python Article.

Compute class weight function issue in ‘sklearn’ library when used in ‘Keras’ classification (Python 3.8, only in VS code)

  1. How to solve Compute class weight function issue in 'sklearn' library when used in 'Keras' classification (Python 3.8, only in VS code)

    After spending a lot of time, this is how I fixed it. I still don't know why but when the code is modified as follows, it works fine. I got the idea after seeing this solution for a similar but slightly different issue.
    class_weights = compute_class_weight( class_weight = "balanced", classes = np.unique(train_classes), y = train_classes ) class_weights = dict(zip(np.unique(train_classes), class_weights)) class_weights

  2. Compute class weight function issue in 'sklearn' library when used in 'Keras' classification (Python 3.8, only in VS code)

    After spending a lot of time, this is how I fixed it. I still don't know why but when the code is modified as follows, it works fine. I got the idea after seeing this solution for a similar but slightly different issue.
    class_weights = compute_class_weight( class_weight = "balanced", classes = np.unique(train_classes), y = train_classes ) class_weights = dict(zip(np.unique(train_classes), class_weights)) class_weights

Solution 1

After spending a lot of time, this is how I fixed it. I still don’t know why but when the code is modified as follows, it works fine. I got the idea after seeing this solution for a similar but slightly different issue.

class_weights = compute_class_weight(
                                        class_weight = "balanced",
                                        classes = np.unique(train_classes),
                                        y = train_classes                                                    
                                    )
class_weights = dict(zip(np.unique(train_classes), class_weights))
class_weights

Original Author edited Mar 27 at 23:14 Of This Content

Solution 2

I solved this problem with recode configuraiton.

from sklearn.utils.class_weight import compute_class_weight
class_weights = compute_class_weight(class_weight = "balanced", classes= np.unique(train_labels), y= train_labels)

Original Author M. Kutlu SENGUL Of This Content

Solution 3

You need to use older version of sklearn than you have.
for me it works fine with scikit-learn version 0.24.2.

Original Author Muhammad Al-Qurishi Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment