Sklearn Preprocessing -- *** TypeError: No matching signature found

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)

矩阵是'numpy.float16'类型的609186x849632稀疏矩阵 具有 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