from textblob import TextBlob
from sklearn.model_selection import cross_val_score
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
from sklearn.datasets import fetch_20newsgroups
categories = ['alt.atheism', 'comp.graphics', 'sci.med', 'soc.religion.christian']
data = fetch_20newsgroups(categories=categories)
X = data.data
y = data.target
model = make_pipeline(CountVectorizer(), MultinomialNB())
scores = cross_val_score(model, X, y, cv=5, scoring='accuracy')
print("Cross-validation scores: ", scores)
print("Average score: ", scores.mean())
這樣,你就可以使用TextBlob進行交叉驗證了。