1

我使用模块 joblib 持久化了一个 TfidfVectorizer。我通过 fit_transform 方法运行的对象是一个字符串列表。生成的矩阵具有 263744 列的维度。

我正在通过 transform 方法运行一个字符串列表,我收到以下错误。

有什么线索吗?

File "/usr/local/lib/python2.7/dist-      packages/sklearn/feature_extraction/text.py", 
line 1334, in transform
return self._tfidf.transform(X, copy=False)
File "/usr/local/lib/python2.7/dist-packages/sklearn/feature_extraction/text.py", 
line 1037, in transform
X = X * self._idf_diag

File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/base.py", line    
318, in __mul__
return self._mul_sparse_matrix(other)
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/compressed.py",
line 487, in _mul_sparse_matrix
other = self.__class__(other)  # convert to this format
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/compressed.py",
line 31, in __init__
arg1 = arg1.asformat(self.format)
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/base.py", 
line 219, in asformat
return getattr(self,'to' + format)()
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/dia.py", 
line 241, in tocsr
return self.tocoo().tocsr()
File "/usr/local/lib/python2.7/dist-packages/scipy/sparse/dia.py", 
line 249, in tocoo

num_offsets, offset_len = self.data.shape
AttributeError: 'NDArrayWrapper' object has no attribute 'shape'
4

1 回答 1

0

假设您将经过训练的变压器或管道持久化到磁盘,然后在看到错误之前重新加载它,您可以:

  1. 尝试使用compress关键字参数参数将原始(工作)对象保存为joblib.dump大于 0 的整数值:

    _ = joblib.dump(python_object, persisted_file_name, compress=3)
    
  2. 如果将持久化文件移动到新位置,请确保复制所有文件片段。如果它很大,joblib 会将其拆分,例如:

    persisted_model.joblib.pkl
    persisted_model.joblib.pkl_01.npy
    persisted_model.joblib.pkl_02.npy
    

工作库文档

于 2016-08-15T17:53:27.753 回答