TypeError object of type ‘numpy.int64’ has no len() when working for prediction a model

我在尝试预测结果时遇到了一个错误。我的完整代码如下,并且我还附上了一张截图。

from sklearn.preprocessing import LabelBinarizerfrom sklearn.metrics import classification_reportbb = LabelBinarizer()train_y = bb.fit_transform(train_y)test_y = bb.transform(test_y)predictions = model.predict(test_x, batch_size=32)print(classification_report(test_y.argmax(axis=1), predictions.argmax(axis=1), target_names = bb.classes_))

错误:TypeError: object of type ‘numpy.int64’ has no len()

Screenshot


回答:

您的类名需要是字符串。我建议(暂时)将最后一行更改为:

class_names = ['Class '+str(i) for i in bb.classes_]print(classification_report(test_y.argmax(axis=1), predictions.argmax(axis=1), target_names = class_names))

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注