Sklearn分类模型返回TypeError:'>'在' str'的实例之间不支持。和' int'试图适应

发布于 2025-02-01 08:54:45 字数 690 浏览 3 评论 0原文

我是建筑模型的新手;所以请轻松:)。我正在尝试使用各种模型类型(SGD,决策树等)构建一个多分类模型,但是,每当我尝试适合任何一个模型,我都会收到一个TypeError:

TypeError: '>' not supported between instances of 'str' and 'int'

我使用的示例代码如下:

sgd = SGDClassifier(loss='modified_huber', shuffle=True, random_state=101, average='micro')

sgd.fit(X_train,Y_train)
y_pred = sgd.predict(X_test)

我以前曾确保这些列是相同的dtype:

for column in X_train.columns.tolist():
    X_train[column] = X_train[column].astype('float32')

Y_train = Y_train.astype('float32')

我可以验证使用时它们确实是float32:

X_train.dtypes
Y_train.dtypes

所以我不确定为什么它会看到“ str”的任何实例。有人可以建议吗?谢谢!

I am fairly new to building models; so please go easy :). I am trying to build a multi-classification model using various model types (SGD, Decision Tree, etc), however, whenever I try to fit any of them, I am receive a TypeError:

TypeError: '>' not supported between instances of 'str' and 'int'

An example code I am using is as below:

sgd = SGDClassifier(loss='modified_huber', shuffle=True, random_state=101, average='micro')

sgd.fit(X_train,Y_train)
y_pred = sgd.predict(X_test)

I had previously ensured that the columns were of the same dtype:

for column in X_train.columns.tolist():
    X_train[column] = X_train[column].astype('float32')

Y_train = Y_train.astype('float32')

And I can verify that they are indeed float32 when using:

X_train.dtypes
Y_train.dtypes

So I am not sure why it is seeing any instances of a 'str'. Could someone please advise? Thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文