Неправильная форма ввода при обучении модели прогнозирования - PullRequest
0 голосов
/ 04 июня 2019

Я использовал следующий код для обучения модели прогнозирования обменного курса с использованием sklearn, но получил ошибку:

import numpy as np
x = [[30],[40],[50],[60],[70],[80],[90],[100],[120],[130],[140],[150]] 
y = ['jan','febuary,'march','april','may','june','july','august','september','october','november','december']

y_2 = np.reshape(y, (-1, 2))
#reshaping because it throws in an error to reshape

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y_3 = le.fit_transform(y_2)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-144-c98a5b8bd15a> in <module>
----> 1 y_3 = le.fit_transform(y_2)

c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages\sklearn\preprocessing\label.py in fit_transform(self, y)
233         y : array-like of shape [n_samples]
234         """
--> 235         y = column_or_1d(y, warn=True)
236         self.classes_, y = _encode(y, encode=True)
237         return y

c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages\sklearn\utils\validation.py in column_or_1d(y, warn)
795         return np.ravel(y)
796 
--> 797     raise ValueError("bad input shape {0}".format(shape))
798 
799 

ValueError: bad input shape (6, 2)

Что мне нужно сделать, чтобы исправить эту ошибку?

1 Ответ

1 голос
/ 04 июня 2019

Нет необходимости выполнять reshape() на y, который вы делаете. Следующего достаточно.

import numpy as np
x = [[30],[40],[50],[60],[70],[80],[90],[100],[120],[130],[140],[150]]
y = ['jan','febuary','march','april','may','june','july','august','september','october','november','december']

#y_2 = np.reshape(y, (-1, 2)) --> This is not needed
#reshaping because it throws in an error to reshape

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y2 = le.fit_transform(y)
print("LabelEncoder classes =", le.classes_)
# LabelEncoder classes = ['april' 'august' 'december' 'febuary' 'jan' 'july' 'june' 'march' 'may' 'november' 'october' 'september']
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...