汇率预测模型误差

时间:2019-06-09 13:45:59

标签: scikit-learn decision-tree one-hot-encoding

我训练了以下模型来预测特定月份的汇率。使用标签编码器将文本即y转换为数字数据。后来在上面实现了一种热编码。但这最终会引发错误。请告知。

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

y_2 = np.reshape(y, (-1, 1))
#had to reshape otherwise it throws in an error of expected 2D array, got one 1D.

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

y_4 = np.reshape(y_3, (-1, 1))
#had to reshape y_3 as its a 1D array and onehotencoder does not accept 1D array.

from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder()
b = enc.fit_transform(y_4).toarray()

from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
from sklearn.model_selection import train_test_split

x_train,x_test,y_train,y_test = train_test_split(x,b,test_size=0.15)
c = DecisionTreeClassifier()
c.fit(x_train,y_train)

prediction = c.predict['august']
      ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-73-d8809b745822> in <module>
----> 1 prediction = c.predict['august']

TypeError: 'method' object is not subscriptable

1 个答案:

答案 0 :(得分:0)

您没有提供x_train输入,这就是发生此错误的原因。

预测= c.predict(x_test) 预测