【问题标题】:Sklearn Preprocessing -- *** TypeError: No matching signature foundSklearn Preprocessing -- *** TypeError: No matching signature found
【发布时间】:2019-02-20 01:11:51
【问题描述】:

我正在尝试标准化 CSR 矩阵,

但我收到此错误:(*** TypeError: No matching signature found).

from sklearn.preprocessing import normalize
normalize(x_m, norm="l2", axis=1)

矩阵是'numpy.float16'类型的609186x849632稀疏矩阵 以压缩稀疏行格式存储 189140200 个元素

【问题讨论】:

  • 是的,看起来 np.float16 在 scipy 中不受支持。一位issue is here

标签: python numpy scikit-learn normalize


【解决方案1】:

其实我解决了这个问题。我认为这是因为数据类型。将np.float16 更改为np.float32,解决了问题。我不知道为什么,这个问题只发生在np.float16数据类型上。

【讨论】:

  • 使用 float16 而不是 float32 的 pandas 也会发生同样的错误。
【解决方案2】:
from sklearn.preprocessing import normalize

columns_changed = []

for col in df.columns:
    col_type = x_m[col].dtypes
    if col_type == 'float16':
      columns_changed.append(col)
      x_m[col] = x_m[col].astype(np.float32)

normalize(x_m, norm="l2", axis=1)

for col in columns_changed:
  x_m[col] = x_m[col].astype(np.float16)

x_m

【讨论】:

  • 欢迎来到 StackOverflow。感谢您抽出宝贵时间提供答案。虽然这段代码可以解决问题,including an explanation 解决问题的方式和原因确实有助于提高帖子的质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提出问题的人。请edit您的回答添加解释并说明适用的限制和假设。
猜你喜欢
  • 2014-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-16
  • 1970-01-01
  • 2019-05-07
  • 2014-12-20
相关资源
最近更新 更多