繁体   English   中英

Sklearn 预处理 -- *** TypeError: 找不到匹配的签名

[英]Sklearn Preprocessing -- *** TypeError: No matching signature found

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

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

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

该矩阵是 609186x849632 类型为 'numpy.float16' 的稀疏矩阵,其中包含 189140200 个以压缩稀疏行格式存储的元素

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM