ValueError: bad input shape (111, 3) import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset = pd.read_csv('iris.csv')
X = dataset.iloc[:,:4]
y = dataset.iloc[:,4]


from sklearn.preprocessing import OneHotEncoder

encoder = OneHotEncoder(sparse=False)
y=encoder.fit_transform(y.values.reshape(-1,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.25, random_state = 0)

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)


from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)


I am getting these small errors which hinder my projects. Can you please provide a solution to this error?
Also how can I avoid these mistakes?
You are getting error because of below-

y=encoder.fit_transform(y.values.reshape(-1,1))


This is changing the shape of the y. try print(y.shape)

You might want to handle you data once its labels and transformed. I am not sure if you are trying to "learn" to apply OneHotEncoding. If yes, you might wanna look at the documentation in detail. here-https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html

Let me know if you have tried it and still have problem.