Python –Gaussian Naive Bayes classifier
How can I resolve this Error
“TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information “
CODE:
from sklearn.datasets import load_svmlight_file
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.naive_bayes import GaussianNB
# Load the data from a libsvm file
X, y = load_svmlight_file(‘a9a.txt’)
# Convert feature data into dense array
X = X.todense()
# Split the data into train/test parts
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# a machine learning pipeline
pipe = make_pipeline(StandardScaler(), GaussianNB())
# Fit the pipeline to the training data
pipe.fit(X_train, y_train)
# Evaluate the accuracy on the test set
accuracy = pipe.score(X_test, y_test)
print(“Accuracy: {:.2f}%”.format(accuracy*100))