擅长:python、mysql、java
<p><code>vq.whiten</code>和<code>vq.kmeans</code>需要一个形状数组<code>(M, N)</code>,其中<em>每行</em>是一个观察值。所以把你的<code>data_array</code>转置:</p>
<pre><code>import numpy as np
import scipy.cluster.vq as vq
np.random.seed(2013)
data_without_x = [
[0, 0, 0, 0, 0, 0, 0, 20.0, 1.0, 48.0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1224.0, 125.5, 3156.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 22.5, 56.0, 41.5, 85.5, 0, 0, 0, 0, 0, 0, 0, 0, 1495.0,
3496.5, 2715.0, 5566.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
data_array = np.array(data_without_x).T
whitened = vq.whiten(data_array)
centroids, distortion = vq.kmeans(whitened, 5)
print(centroids)
</code></pre>
<p>收益率</p>
<pre><code>[[ 1.22649791e+00 2.69573144e+00]
[ 3.91943108e-03 5.57406434e-03]
[ 5.73668382e+00 4.83161524e+00]
[ 0.00000000e+00 1.29763133e+00]]
</code></pre>