from imblearn.over_sampling import SMOTE
from imblearn.under_sampling import RandomUnderSampler
from imblearn.pipeline import Pipeline
# Define features and target
X = df.drop('infected', axis=1)
y = df['infected']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Define the resampling strategy
over = SMOTE(sampling_strategy=0.5) # Oversample the minority class to 50% of the majority class
under = RandomUnderSampler(sampling_strategy=0.8) # Undersample the majority class to 80% of its original size
pipeline = Pipeline(steps=[('o', over), ('u', under)])
# Apply the resampling
X_resampled, y_resampled = pipeline.fit_resample(X_train, y_train)
# Show the new class distribution
print("Resampled class distribution:", pd.Series(y_resampled).value_counts())
THIS IS MY CODEE
AND
THIS IS THE ERROR I AM GETTING
AttributeError Traceback (most recent call last)
Cell In[7], line 19
16 pipeline = Pipeline(steps=[('o', over), ('u', under)])
18 # Apply the resampling
---> 19 X_resampled, y_resampled = pipeline.fit_resample(X_train, y_train)
21 # Show the new class distribution
22 print("Resampled class distribution:", pd.Series(y_resampled).value_counts())
File ~anaconda3Libsite-packagesimblearnpipeline.py:372, in Pipeline.fit_resample(self, X, y, **fit_params)
342 """Fit the model and sample with the final estimator.
343
344 Fits all the transformers/samplers one after the other and
(...)
369 Transformed target.
370 """
371 self._validate_params()
--> 372 fit_params_steps = self._check_fit_params(**fit_params)
373 Xt, yt = self._fit(X, y, **fit_params_steps)
374 last_step = self._final_estimator
AttributeError: 'Pipeline' object has no attribute '_check_fit_params'
I HAVE TRIED EVERYTHING. ALL MY PACKAGES ARE UPDATED. AND ALL THE METHODS I HAVE TRIED TO USE LOOKING AT SKLEARN AND IMBLEARN BOTH THE WEBSITES. SOMEBODY PLEASE HELP.. URGENT
New contributor
Varutri Parihar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.