data
は、データの1次元配列です。ガウス混合モデルを単一フィーチャデータに適合させる正しい方法は何ですか?
data = [0.0, 7000.0, 0.0, 7000.0, -400.0, 0.0, 7000.0, -400.0, -7400.0, 7000.0, -400.0, -7000.0, -7000.0, 0.0, 0.0, 0.0, -7000.0, 7000.0, 7000.0, 7000.0, 0.0, -7000.0, 6600.0, -7400.0, -400.0, 6600.0, -400.0, -400.0, 6600.0, 6600.0, 6600.0, 7000.0, 6600.0, -7000.0, 0.0, 0.0, -7000.0, -7400.0, 6600.0, -400.0, 7000.0, -7000.0, -7000.0, 0.0, 0.0, -400.0, -7000.0, -7000.0, 7000.0, 7000.0, 0.0, -7000.0, 0.0, 0.0, 6600.0, 6600.0, 6600.0, -7400.0, -400.0, -2000.0, -7000.0, -400.0, -7400.0, 7000.0, 0.0, -7000.0, -7000.0, 0.0, -400.0, -7400.0, -7400.0, 0.0, 0.0, 0.0, -400.0, -400.0, -400.0, -400.0, 6600.0, 0.0, -400.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -400.0, -400.0, 0.0, 0.0, -400.0, -400.0, 0.0, -400.0, 0.0, -400.0]
私はこのデータにいくつかのガウス分布を当てはめてプロットしたいと思います。
私は
import numpy as np
from sklearn import mixture
x = np.array(data)
clf = mixture.GaussianMixture(n_components=2, covariance_type='full')
clf.fit(x)
を実行した場合、私は[OK]を...私はこれと一緒に暮らすことができ、エラーに
ValueError: Expected n_samples >= n_components but got n_components = 2, n_samples = 1
と
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
を取得します。警告は私に何をすべきかを伝えます。私は
x = np.array(data).reshape(-1,1)
clf = mixture.GaussianMixture(n_components=2, covariance_type='full')
clf.fit(x)
を実行する場合しかし、私はエラー
ValueError: Expected the input data X have 1 features, but got 32000 features
は私が間違って何をやってもらいますか?正しい方法は何ですか?
編集:私はちょうど私がエラーメッセージを読み違えることに気づい
。 fit()
ではエラーが発生していませんが、score_samples()
です。
私は後でガウス分布をプロットしようとしています。
x = np.linspace(-8000,8000,32000)
y = clf.score_samples(x)
plt.plot(x, y)
plt.show()
従ってx
が問題であるようです。しかし、いずれもx.reshape(-1,1)
は役に立ちません。x.reshape(1,-1)
。
は、あなたはそれを他の方法(1、-1)再構築しようとしましたか? –
はい、私はすでにこれを試しました。 John Moutafisへの私のコメントを参照してください。 –
(-1,1)、scikit 0.18 –