我有一个大数据框架,其中其索引为movie_id,列标题表示tag_id。每一行都代表电影标记相关性
639755209030196 691838465332800
46126718359 0.042 0.245
46130382440 0.403 0.3
46151724544 0.032 0.04
然后我遵循:
data = df.values
similarity_matrix = 1 - pairwise_distances(data, data, 'cosine', -2)
它具有接近8000个唯一标签,因此数据的形状为42588 * 8000。而且我在拥有40个内存的机器中遇到了这个错误。
Exception in thread Thread-4:
Traceback (most recent call last):
File "~/anaconda/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "~/anaconda/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "~/anaconda/lib/python2.7/multiprocessing/pool.py", line 326, in _handle_workers
pool._maintain_pool()
File "~/anaconda/lib/python2.7/multiprocessing/pool.py", line 230, in _maintain_pool
self._repopulate_pool()
File "~/anaconda/lib/python2.7/multiprocessing/pool.py", line 223, in _repopulate_pool
w.start()
File "~/anaconda/lib/python2.7/multiprocessing/process.py", line 130, in start
self._popen = Popen(self)
File "~/anaconda/lib/python2.7/multiprocessing/forking.py", line 121, in __init__
self.pid = os.fork()
OSError: [Errno 12] Cannot allocate memory
原因是什么?矩阵太大吗?我避免此内存问题有什么选择?
我目前正在使用:
python 2.7
scikit-learn 0.15.2 np19py27_0
Red-Hat Linux with 4X4 cores x86_64
您正在使用哪种版本的scikit-learn?它是否使用n_jobs = 1运行?结果应适合内存,为8 * 42588 ** 2/1024 ** 3 = 13 GB。但是数据大约为2GB,并将复制到每个核心。因此,如果您有16个内核,您将遇到麻烦。