2017-04-13 11 views
0

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) 

을 실행하면

나는 나는이 살 수 ... 오류를

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).

+2

당신이 (-1 일) 그것을 다른 방법을 바꿀 시도? –

+0

예, 이미 시도했습니다. 내 의견을 존 Moutafis 대답을 참조하십시오. –

+1

(-1,1), scikit 0.18 –

답변

4

의 목록으로 변환됩니다

your_samples_list = map(lambda x:[x], your_samples_list) 

보십시오. 내가 편집 한 내용에서 설명한 바와 같이 fit()은 오류를 발생시키지 않고, score_samples()입니다.

두 기능 모두 다차원 배열을 압도합니다.

근무 코드 :

data = np.array(data).reshape(-1,1) 
clf = mixture.GaussianMixture(n_components=1, covariance_type='full') 
clf.fit(data) 

x = np.array(np.linspace(-8000,8000,32000)).reshape(-1,1) 
y = clf.score_samples(x) 

plt.plot(x, y) 
plt.show() 
+0

로 모양을 바꿀 때 오류가 발생하지 않습니다. 오, 찾았습니다 :) 내 대답을 편집 한 것처럼 !! –

2

당신은 단지 하나의 기능의 많은 샘플이있는 경우, 이것이 내가 오류 나 자신을 발견 목록

[a,b,c] -> [[a],[b],[c]]