Today I am trying build ensemble model
. Where I am working with iris dataset. In my model I am using LogisticRegression, KNeighborsClassifier, RandomForestClassifier
. But when I am going run the program I get ValueError: Found input variables with inconsistent numbers of samples: [10, 150] error.
Below I am giving my code:
df = pd.read_csv('/kaggle/input/iriscsv/Iris.csv')
df.head()
df
output --->
Then I am deleting id collumn from this dataset
df = df.iloc[:, 1:]
After this I am used LabelEncoder on Species column
df['Species'] = encoder.fit_transform(df['Species'])
import seaborn as sns
sns.pairplot(df, hue = 'Species')
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
clf1 = LogisticRegression()
clf2 = RandomForestClassifier()
clf3 = KNeighborsClassifier()
estimators = [('lr',clf1),('rf',clf2),('knn',clf3)]
for estimator in estimators:
x = cross_val_score(estimator[1],x,y,cv=10,scoring='accuracy')
print(estimator[0],np.round(np.mean(x),2))
After running the last estimator I am getting these error.