值错误:无法将字符串转换为浮点数:“好”

发布于 2025-01-14 10:33:19 字数 746 浏览 3 评论 0原文

我正在尝试将决策树模型与训练数据集进行拟合。但发现这个错误

credit_df=pd.read_csv('credit.csv')
credit_df.head()

[! 数据框]1

X = credit_df.drop("default" , axis=1)
Y=credit_df.pop("default")
from sklearn.model_selection import train_test_split

X_train, X_test, train_labels, test_labels = train_test_split(X, y, test_size=.30, random_state=1)

dt_model = DecisionTreeClassifier(criterion = 'gini' )
dt_model.fit(X_train, train_labels)

错误消息

I am trying to fit a decision tree model with the training dataset. But finding this error

credit_df=pd.read_csv('credit.csv')
credit_df.head()

[! dataframe]1

X = credit_df.drop("default" , axis=1)
Y=credit_df.pop("default")
from sklearn.model_selection import train_test_split

X_train, X_test, train_labels, test_labels = train_test_split(X, y, test_size=.30, random_state=1)

dt_model = DecisionTreeClassifier(criterion = 'gini' )
dt_model.fit(X_train, train_labels)

error message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

另类 2025-01-21 10:33:19

我尝试了下面的代码,现在错误已修复。有一些对象数据类型,我将它们转换为分类值

for feature in credit_df.columns: 
    if credit_df[feature].dtype == 'object': 
        credit_df[feature] = pd.Categorical(credit_df[feature]).codes

I tried the code below and now the error is fixed. There were some object data types and i converted them into categorical values

for feature in credit_df.columns: 
    if credit_df[feature].dtype == 'object': 
        credit_df[feature] = pd.Categorical(credit_df[feature]).codes
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文