Search code examples
pythonimbalanced-dataimblearn

'NearMiss' object has no attribute '_validate_data'


Detailed Image

This is the code below which shows the error.

from imblearn.under_sampling import NearMiss
nm = NearMiss()
X_res,y_res=nm.fit_sample(X,Y)

Solution

  • You are probably trying to under sample your imbalanced dataset. For this purpose, you can use RandomUnderSampler instead of NearMiss.

    Try the following code:

    from imblearn.under_sampling import RandomUnderSampler  
    
    under_sampler = RandomUnderSampler()
    X_res, y_res = under_sampler.fit_resample(X, y)
    

    Now, your dataset is balanced. You can verify it using y_res.value_counts().

    Cheers!