【问题标题】:(can only concatenate str (not "int") to str) when using One-hot encoding(只能将 str(不是“int”)连接到 str)使用 One-hot 编码时
【发布时间】:2021-06-03 08:48:38
【问题描述】:

我正在尝试从头开始构建多分类神经网络,但 One_hot 函数不起作用,您能帮我解决吗?

def one_hot(Y):
    one_hot_y=np.zeros((Y.size,Y.max() +1))
    one_hot_y[np.arange(Y.size), Y] = 1
    one_hot_y = one_hot_y.T
    return one_hot_y  

这是我在运行神经网络函数时遇到的错误类型

【问题讨论】:

  • 我猜Y 包含字符串。 Y.max() + 1 应该是什么?
  • 显然Y.max()是一个字符串
  • 试试int(Y.max()) + 1

标签: python machine-learning neural-network multiclass-classification


【解决方案1】:

检查 Y 中的数据类型,我敢打赌你那里有字符串。 Python 会阻止您执行“str + int”操作,从而导致第一行的Y.max() + 1 出现问题

【讨论】:

    猜你喜欢
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2021-11-07
    • 2020-09-18
    • 2020-08-19
    相关资源
    最近更新 更多