2017-10-28 13 views
1

전처리 된 데이터를 다음 형식으로 처리해야하는 프로젝트 작업 중입니다."시퀀스가있는 배열 요소 설정"numpy 오류

Beginning

데이터 설명은 너무 이상 받고있다. 목표는 서면 자릿수가 해당 자릿수의 오디오와 일치하는지 여부를 예측하는 것입니다. 우선 같은 시간축 위에 수단 양식 가능 어레이 (N 13) 변환 : 음성 내에

Transformation

이것은 모든 어레이 (1,13)의 일정한 길이를 생성한다. 이것을 간단한 바닐라 알고리즘으로 테스트하기 위해 두 개의 배열을 압축하여 LogisticRegression 클래스의 fit 함수에 다음과 같은 오류를 던져 넣을 때 (45000, 2) 형식의 배열을 만듭니다. Error

내가 뭘 잘못하고 있니?

번호 :

import numpy as np 
from sklearn.linear_model import LogisticRegression 

match = np.load("/srv/digits/match_train.npy") 
spoken = np.load("/srv/digits/spoken_train.npy") 
written = np.load("/srv/digits/written_train.npy") 
print(match.shape, spoken.shape, written.shape) 
print(spoken[0].shape, spoken[1].shape) 

def features(signal, function): 
    new = np.copy(signal) 
    for i in range(len(signal)): 
     new[i] = function(new[i], axis=0) 
    return new 

spokenMean = features(spoken, np.mean) 
print(spokenMean.shape, spokenMean[0]) 

result = np.array(list(zip(spokenMean,written))) 
print(result.shape) 

X_train, X_val, y_train, y_val = train_test_split(result, match, test_size = 
0.33, random_state = 123) 
model = LogisticRegression() 
print(X_train.shape, y_train.shape) 
model.fit(X_train, y_train) 
yh_val = model.predict(X_val) 
+0

spokenMean 및 ytrain의 모양은 무엇입니까? – Siddharth

+0

@Siddharth spokenMean은 fit 함수에 있어서는 안됩니다. 물론 X_train이어야합니다. X_train의 모양은 (30150,2)입니다. y_train의 모양은 (30150,)입니다. –

+0

여전히 X_train에 오류가 있습니까? – Siddharth

답변

1

spokenMean 유형, 즉 그것은 작은 1D 배열을 유지하는 1 차원 배열이다, object이다. 가장 먼저해야 할 일은 convert it to a 2D float array입니다. 이것은 나를 위해 일한 :

spokenMean = features(spoken, np.mean) 
spokenMean = np.vstack(spokenMean[:]).astype(np.float32) 

그런 list(zip(...))이 두 배열을 연결하는 올바른 방법이 아니다. 대신, np.concatenate 전화 :

result = np.concatenate([spokenMean, written], axis=1) 

X_train 일반 2D 배열을 만들 것입니다.

+0

크기가 변경되면 작성된 모양을 변경하면 연결이 끊어지는 것처럼 보입니다. 그러나, 그 코드 줄을 제거하면 모든게 잘된 것처럼 보입니다. 당신의 도움을 주셔서 대단히 감사합니다! –