开始使用免费开始使用

预测蘑菇是否可食用

现在您已经探索过数据,是时候构建首个模型来预测蘑菇是否可食用了。

数据集以 mushrooms 提供。由于特征和目标变量都是类别型数据,已为您转换为"虚拟"二元变量。

我们先从朴素贝叶斯开始(使用 scikit-learnGaussianNB),看看该算法在此问题上的表现如何。

本练习是课程的一部分

Python 中的集成方法

查看课程

练习说明

  • 实例化一个名为 clf_nbGaussianNB 分类器。
  • clf_nb 拟合到训练数据 X_trainy_train
  • 在测试集上计算预测结果。随后将使用准确率来评估模型表现。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Instantiate a Naive Bayes classifier
clf_nb = ____

# Fit the model to the training set
____

# Calculate the predictions on the test set
pred = ____

# Evaluate the performance using the accuracy score
print("Accuracy: {:0.4f}".format(accuracy_score(y_test, pred)))
编辑并运行代码