【发布时间】: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'
【问题讨论】:
-
欢迎来到堆栈溢出。 “请问我该怎么做”你应该做的第一件事是阅读How to Ask和ericlippert.com/2014/03/05/how-to-debug-small-programs和minimal reproducible example,并确保在尝试将其用于复杂的数据科学任务之前了解 Python 编程的基础知识。
标签: python