【发布时间】:2021-01-13 02:15:40
【问题描述】:
我尝试从 Udacity 的机器学习入门课程中学习机器学习。
第 2 课 - 朴素贝叶斯测验 19:地形数据上的高斯 NB 部署
我必须在我添加的classifyNB.py文件中添加一些代码
def classify(features_train, labels_train):
### import the sklearn module for GaussianNB
### create classifier
### fit the classifier on the training features and labels
### return the fit classifier
### your code goes here!
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(features_train, labels_train)
return((features_train, labels_train)
但是代码没有编译并抛出一些错误。
知道我应该写什么来return the fit classifier
【问题讨论】:
-
试试这个:
return clf -
我这样写
return(clf)。我想得到一张照片,因为还有其他 .py 文件。这次添加 return(clf) 后,我既没有得到错误也没有得到任何输出。 -
谢谢 Vaziri。经过2分钟的等待,我得到了结果。谢谢。
-
你是否将函数体缩进了 1 个制表符?
标签: python machine-learning scikit-learn