【问题标题】:Python: MemoryError for .corr(method='pearson').applymapPython:.corr(method='pearson').applymap 的 MemoryError
【发布时间】:2018-07-01 17:49:11
【问题描述】:

我正在尝试计算数据框中每对可能的两列的 pearsons 相关性。我有 57997 列。但是我遇到了内存错误。

t_logs = logs.T
print t_logs
results = t_logs.corr(method='pearson').applymap
print results[enter image description here][1]

这是回溯

---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-99-d0010a131d17> in <module>()
       5 print logs
       6 
 ----> 7 results = t_logs.corr(method='pearson')
       8 print results

C:\Users\nne1s\Anaconda2\lib\site-packages\pandas\core\frame.pyc in 
corr(self, method, min_periods)
   4938 
   4939         if method == 'pearson':
-> 4940             correl = libalgos.nancorr(_ensure_float64(mat), 
minp=min_periods)
4941         elif method == 'spearman':
4942             correl = libalgos.nancorr_spearman(_ensure_float64(mat),

pandas\_libs\algos.pyx in pandas._libs.algos.nancorr 
(pandas\_libs\algos.c:15501)()

MemoryError: 

picture of code linked here

【问题讨论】:

  • 你的开发环境有多少内存
  • 请不要张贴代码图片或错误信息。而是在 SO 上发布完整的回溯。 The reason for this is explained here.
  • @Piinthesky 我添加了回溯

标签: python vectorization data-analysis pearson-correlation


【解决方案1】:

我认为您不想计算 57997 系列的相关系数。

如果您尝试获取平均值的 Log2、STD 的 Log2 等的相关矩阵,请在运行 corr 之前转置数据帧

t_logs = t_logs.T
results = t_logs.corr(method='pearson')

我不确定你想在这里用applymap 做什么

【讨论】:

  • 你能发布整个回溯吗?
  • 当我在不转置的情况下执行此操作时,我不会收到错误消息。但是,我需要转置才能取正确的相关系数
  • 当您使用 corr 而不转置时,结果数据框的形状是什么?
  • 它是 4x4。但基本上我需要一个 57997x57997。也许它太大了
  • 帮我找出两个基因及其表达的关系。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-26
  • 2015-03-20
  • 1970-01-01
  • 2018-06-13
  • 1970-01-01
  • 1970-01-01
  • 2017-03-20
相关资源
最近更新 更多