Reputation: 1
i am working on an imbalanced multi-class dataset, i am trying to pass it into a balancedBaggingClassifier but i keep getting the error below :
code:
import pandas as pd
dataframe = pd.read_excel('mergedDataset.xlsx')
from sklearn import model_selection
from sklearn.tree import DecisionTreeClassifier
X = dataframe.iloc[:,:-1]
y = dataframe.iloc[:,-1:]
from sklearn.model_selection import train_test_split
X_train,X_test, y_train,y_test = \
train_test_split(X, y,test_size=0.3,random_state=10)
seed = 8
kfold = model_selection.KFold(n_splits = 3,shuffle=True,random_state = seed)
# initialize the base classifier
base_cls = DecisionTreeClassifier()
# no. of base classifier
num_trees = 500
from imblearn.ensemble import BalancedBaggingClassifier
# bagging classifier
model = BalancedBaggingClassifier(base_estimator=DecisionTreeClassifier(),
sampling_strategy='auto',
replacement=False,
random_state=0,max_features=1.0)
model.fit(X_train, y_train)
results = model_selection.cross_val_score(model, X, y, cv = kfold)
print("accuracy :")
print(results.mean())
error :
AttributeError Traceback (most recent call last) in () 13 replacement=False, 14 random_state=0,max_features=1.0) ---> 15 model.fit(X_train, y_train) 16 17 results = model_selection.cross_val_score(model, X, y, cv = kfold)
1 frames /usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_bagging.py in fit(self, X, y, max_samples, max_depth, sample_weight) 335 max_features = self.max_features 336 elif isinstance(self.max_features, float): --> 337 max_features = self.max_features * self.n_features_in 338 else: 339 raise ValueError("max_features must be int or float")
AttributeError: 'BalancedBaggingClassifier' object has no attribute 'n_features_in_'
Upvotes: 0
Views: 2085
Reputation: 11
This can be solved by upgrading the imblearn to >= 0.9. I had the same issue, I upgraded and the issue was resolved.
Upvotes: 0
Reputation: 9
I think it's a issue from sickit learn the only solution it's to dowgrade sklearn https://github.com/scikit-learn/scikit-learn/issues/17353
Upvotes: 0