【问题标题】:DECISION TREE /Bagging决策树/装袋
【发布时间】:2023-01-01 20:16:13
【问题描述】:

我对数据科学还是很陌生。 我在决策树上运行此代码时收到一条错误消息

#Fitting the model
d_tree = DecisionTreeClassifier(random_state=1)
d_tree.fit(X_train,y_train)

#Calculating different metrics
d_tree_model_train_perf=model_performance_classification_sklearn(d_tree,X_train,y_train)
print("Training performance:\n",d_tree_model_train_perf)
d_tree_model_test_perf=model_performance_classification_sklearn(d_tree,X_test,y_test)
print("Testing performance:\n",d_tree_model_test_perf)

#Creating confusion matrix
confusion_matrix_sklearn(d_tree,X_test,y_test)

我在下面收到此错误消息...请问我该怎么办

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-396204314fba> in <module>
      1 #Fitting the model
      2 d_tree = DecisionTreeClassifier(random_state=1)
----> 3 d_tree.fit(X_train,y_train)
      4 
      5 #Calculating different metrics

4 frames
/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py in __array__(self, dtype)
   1991 
   1992     def __array__(self, dtype: NpDtype | None = None) -> np.ndarray:
-> 1993         return np.asarray(self._values, dtype=dtype)
   1994 
   1995     def __array_wrap__(

ValueError: could not convert string to float: 'North America'

【问题讨论】:

标签: python


【解决方案1】:

该错误会准确地告诉您出了什么问题; “北美”不能转换为浮点数。

对于作为数据科学家的你来说,这意味着你输入算法的数据(我们不知道)不符合算法预期的结构。因此,请根据需要修复您的数据结构。这将需要阅读您使用的功能的文档。

【讨论】:

  • 请阅读How to Answer,不要试图回答明显缺乏适当调试细节的问题。他们应该关闭而不是回答。您拥有必要的声誉来投出势均力敌的选票并使用 cmets 来具体解释问题中缺少的内容。
猜你喜欢
  • 2019-04-12
  • 2021-03-01
  • 2012-08-20
  • 2015-02-06
  • 2013-08-29
  • 2018-05-04
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多