如何解决大熊猫scikit学习多维尺度始终运行

问题描述:

编辑 看来,它并不一定是在64行中的数据问题,而64号本身就是神奇而导致的问题。由于我一直在解决这个问题,我写了一个脚本,从DataFrame中随机抽取63个连续的行并绘制它们。它每次都运行得很快。但是,如果我将其更改为64行,它永远不会运行并永远运行。 End edit如何解决大熊猫scikit学习多维尺度始终运行

我正在尝试使用多维缩放对集群中的数据进行可视化。我创建了一个DataFrame,其维数为1000行,1964列。当我尝试对数据执行多维缩放时,该过程将永久运行。奇怪的是,我似乎无法通过按Ctrl + C结束该过程。

通过反复试验的过程,我发现了数据集的第64行有一些神奇的东西。如果我在63行上运行这个过程,整个过程几秒钟就完成了。如果我碰到64行,但它永远不会结束。

我真的不知道该如何解决这个问题。我经历了1964年的专栏,寻找第63行和第64行之间的区别,希望找到一个奇怪的值或什么,但是没有什么可以跳出来。任何其他方式,我可以知道为什么64行是如此神奇?

import pandas as pd 
from pandas import DataFrame as df 
from sklearn.metrics.pairwise import euclidean_distances 
from sklearn.metrics.pairwise import manhattan_distances 
from sklearn import manifold 
from matplotlib import pyplot as plt 
import prettyplotlib as ppl 

malware_df = df.from_csv('malware_features.csv') 

plottable = malware_df[[c for c in malware_df.columns if c != 'hash']] 
plottable = plottable.head(63) # change this to 64 and everything stops working 

euc = euclidean_distances(plottable) 
mds = manifold.MDS(n_jobs=-1, random_state=1337, dissimilarity='precomputed') 
pos_e = mds.fit(euc).embedding_ 

plottable['xpos'] = pos_e[:,0] 
plottable['ypos'] = pos_e[:,1] 
with ppl.pretty: 
    fig, ax = ppl.subplots(figsize=(6,8)) 
ppl.scatter(ax, plottable.xpos, plottable.ypos) 
plt.show() 

这里是一个链接,你可以下载我使用的文件,如果有帮助。 https://drive.google.com/file/d/0BxZZOOgLl7vSTUlxc1BmMUFmTVU/edit?usp=sharing

+0

如果删除其中一列,64仍然是魔术?我的假设是,你可能会遇到一些记忆边界和[thrashing](http://en.wikipedia.org/wiki/Thrashing_(computer_science))或类似 – 2014-09-05 08:40:59

+0

什么是pos_e? – 2014-09-08 02:29:31

+0

对不起,@AndyHayden我纠正了代码片段,以解释pos_e如何被初始化。它是基于欧氏距离的点的位置。 – 2014-09-08 16:01:56

这必须是版本。在我的电脑(2003年,1 AMD芯,2 GB RAM),该代码在〜3秒运行:

#import pandas as pd 
from pandas import DataFrame as df 
from sklearn.metrics.pairwise import euclidean_distances 
#from sklearn.metrics.pairwise import manhattan_distances 
from sklearn import manifold 
from matplotlib import pyplot as plt 
import prettyplotlib as ppl 

malware_df = df.from_csv('malware_features.csv') 

plottable = malware_df[[c for c in malware_df.columns if c != 'hash']] 
plottable = plottable.head(128) # change this to 64 and everything stops working 

euc = euclidean_distances(plottable) 
mds = manifold.MDS(n_jobs=-1, random_state=1337, dissimilarity='precomputed') 
pos_e = mds.fit(euc).embedding_ 

plottable['xpos'] = pos_e[:,0] 
plottable['ypos'] = pos_e[:,1] 

fig, ax = ppl.subplots(figsize=(6,8)) 

ppl.scatter(ax, plottable.xpos, plottable.ypos) 
plt.show() 

为了产生这种图形:

enter image description here

声明I与128尝试后试着64而不是失败,看看发生了什么,改变了引发错误的with ppl.pretty,并且一切运行良好。这是我的pip freeze

brewer2mpl==1.4 
matplotlib==1.4.0 
numpy==1.9.0 
pandas==0.14.1 
prettyplotlib==0.1.7 
reportlab==3.1.8 
scikit-learn==0.15.2 
scipy==0.14.0 

和python 2.7.3。

+0

完全就是这样。我没有想到要看看我的软件包是否过时。我只用2000行来运行它,它运行了7到10秒。 – 2014-09-10 14:59:09