This is my minimal reproducible example:
import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import cross_validate
x = np.array([
[1, 2],
[3, 4],
[5, 6],
[6, 7]
])
y = [1, 0, 0, 1]
model = GaussianNB()
scores = cross_validate(model, x, y, cv=2, scoring=("accuracy"))
model.predict([8,9])
What I intended to do is instantiating a Gaussian Naive Bayes Classifier and use sklearn.model_selection.cross_validate for cross validate my model (I am using cross_validate
instead of cross_val_score
since in my real project I need precision, recall and f1 as well).
I have read in the doc that cross_validate
does "evaluate metric(s) by cross-validation and also record fit/score times."
I expected that my model
would have been fitted on x
(features), y
(labels) data but when I invoke model.predict(.)
I get:
sklearn.exceptions.NotFittedError: This GaussianNB instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
Of course it says me about invoking model.fit(x,y)
before "using the estimator" (that is before invoking model.predict(.)
.
Shouldn't the model have been fitted cv=2
times when I invoke cross_validate(...)
?