我正在使用scikit-learn NearestNeighbors来查找最近的邻居,在人们维基数据上使用tfidf。
在我的.kneighbors()
方法调用
res = neigh.kneighbors(obama_tfidf, return_distance=False)
Multiprocessing
模块抛出了以下异常:
ValueError: UPDATEIFCOPY base is read-only
我已在我的github location here上传了我的完整代码和示例数据(大小为80 MB)以供参考。
以下是错误列表的一部分:
---------------------------------------------------------------------------
JoblibValueError Traceback (most recent call last)
<ipython-input-12-dbcbed49b042> in <module>()
1 obama_word_counts = count_vectorizer.transform(['obama'])
2 obama_tfidf = tfidf_transformer.transform(obama_word_counts)
----> 3 res = neigh.kneighbors(obama_tfidf, return_distance=False)
4 print res
/usr/local/lib/python2.7/dist-packages/sklearn/neighbors/base.pyc in kneighbors(self, X, n_neighbors, return_distance)
355 if self.effective_metric_ == 'euclidean':
356 dist = pairwise_distances(X, self._fit_X, 'euclidean',
--> 357 n_jobs=n_jobs, squared=True)
358 else:
359 dist = pairwise_distances(
/usr/local/lib/python2.7/dist-packages/sklearn/metrics/pairwise.pyc in pairwise_distances(X, Y, metric, n_jobs, **kwds)
1245 func = partial(distance.cdist, metric=metric, **kwds)
1246
-> 1247 return _parallel_pairwise(X, Y, func, n_jobs, **kwds)
1248
1249
/usr/local/lib/python2.7/dist-packages/sklearn/metrics/pairwise.pyc in _parallel_pairwise(X, Y, func, n_jobs, **kwds)
1094 ret = Parallel(n_jobs=n_jobs, verbose=0)(
1095 fd(X, Y[s], **kwds)
-> 1096 for s in gen_even_slices(Y.shape[0], n_jobs))
1097
1098 return np.hstack(ret)
/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/parallel.pyc in __call__(self, iterable)
787 # consumption.
788 self._iterating = False
--> 789 self.retrieve()
790 # Make sure that we get a last message telling us we are done
791 elapsed_time = time.time() - self._start_time
/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/parallel.pyc in retrieve(self)
738 exception = exception_type(report)
739
--> 740 raise exception
741
742 def __call__(self, iterable):
JoblibValueError: JoblibValueError
我无法粘贴整个多处理异常,因为它超出了S / O发布限制。
我在这里缺少什么?
答案 0 :(得分:1)
当n_jobs
等于-1时,则将作业数设置为CPU核心数,如ref中所述。
当sklearn NN函数调用_parallel_pairwise()
,然后尝试获取甚至切片时,会发生错误。
尝试将n_jobs
设置为偶数,当然小于CPU核心数。
正如您已经提到的,您可以在n_jobs
等于1的情况下运行此操作,这不会使代码并行化,从而不会暴露错误。