Anjith
Anjith

Reputation: 2308

Does sparse matrix work with MultinomialNB?

I have a BoW vectors of shape (100000, 56000) and I want to use MultinomialNB from scikit-learn for a classification task.

Does MultinomialNB take sparse matrix for fitting the data?

I can't seem to convert it into dense matrixtoarray() due to memory error. If NB classifier doesn't take sparse matrix are there any alternatives I could use for fitting the data without converting it into dense matrix?

Upvotes: 0

Views: 709

Answers (1)

desertnaut
desertnaut

Reputation: 60390

From the documentation of MultinomialNB.fit (emphasis added):

fit(X, y, sample_weight=None)

Parameters:

X : {array-like, sparse matrix}, shape = [n_samples, n_features]

Training vectors, where n_samples is the number of samples and n_features is the number of features.

Upvotes: 2

Related Questions