我是scikit learn的新手,我对这个程序试图预测的内容感到困惑。
import numpy as np
X = np.array([[-1, -1],
[-2, -1],
[-3, -2],
[1, 1],
[2, 1],
[3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
print(clf.predict([[-0.8, -1]]))
如果我运行这个程序,我会得到:
[1]
据我所知" X"是培训数据,我不确定是什么" Y"是。如果我改变:
([[-0.8, -1]])
到
([[-0.8, 1]])
我得到了
[2]
我只需要一点定义。
答案 0 :(得分:2)
Y
是一个培训标签。
函数predict
返回预测标签。
答案 1 :(得分:-1)
clf = GaussianNB() #creating the naive bayes classifier object
clf.fit(X, Y) #fitting the classifier to the training data points x providing
## their already known classes in the list y which is of same
#length as X and every element is the class of the
#corresponding element (datapoint) in x
clf.predict([[-0.8, -1]]) #predicting the class of the testing datapoint[-0.8, -1]