导入sklearn.feature_extraction.text.TfidfVectorizer用于转换字符串 from sklearn.feature_extraction.text import TfidfVectorizer # 创建对象 tf = TfidfVectorizer() # 训练 tf.fit(data) # transform 转化 data_result = tf.transform(data).toarray() ga_NB = GaussianNB() ga_NB.fit(data_result, target)