gpt4 book ai didi

python - sk learn中的朴素贝叶斯函数无法识别

转载 作者:太空宇宙 更新时间:2023-11-03 16:02:43 30 4
gpt4 key购买 nike

使用以下代码,我尝试加载数据集并对其执行 NB 算法。

from sklearn.naive_bayes import MultinominalNB 
import pandas as pd
import numpy as np

data = pd.read_csv('spambase.data.txt').as_matrix()
np.random.shuffle(data)

x = data[:, :48]
y = data[:, -1]

Ytrain = x[:-100,]
Ytrain = y[:-100,]
Xtest = x[-100:,]
Ytest = y[-100:,]

model = MultinominalNB()
model.fit(X.train, Y.train)

print "Classification rate for NB: "

但是,当我尝试运行它时出现以下错误:

python sample.py

Traceback (most recent call last):
File "sample.py", line 1, in <module>
from sklearn.naive_bayes import MultinominalNB
ImportError: No module named sklearn.naive_bayes

对这里出了什么问题有什么想法吗?

打印数据

最佳答案

您有一个拼写错误,请尝试:

从 sklearn.naive_bayes 导入 MultinomialNB

关于python - sk learn中的朴素贝叶斯函数无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40174702/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com