【发布时间】:2016-03-12 12:45:04
【问题描述】:
我有一个数据集以下列形式描述一些痕迹:
traceId1: event1 time1 event2 time2 ... eventN timeN
traceId2: event1 time1 event2 time2 ... eventM-1 timeM-1 eventM timeM
.
.
.
也就是说,这个文件包含几个痕迹。每个跟踪都包含几个事件以及这些事件发生的时间。每条迹线的长度可能会有所不同。因此我无法将数据转换为矩阵。
我写了一个类 Point 来保存每个跟踪作为一个对象。我还编写了一个自定义函数来计算每对轨迹之间的距离。当我尝试使用我的指标构建 BallTree 时,它给出:
File "/home/yangzhao/anaconda3/lib/python3.5/site-packages/numpy/core/numeric.py", line 474, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'Point'
基于post,看来 BallTree 只接受可以转换为浮点数的数据类型。由于这是在 2013 年发布的,现在有什么解决方法吗?比如在类定义中写一个float方法?
PS:我可以自己用 Python 写一个 BallTree,但它没有优化,所以运行缓慢。并且系统限制了递归的最大深度,因此它不能在我的完整数据集上工作。我还用 C++ 实现了 BallTree,用 Python 调用该函数是个好主意吗?
【问题讨论】:
标签: numpy machine-learning scikit-learn