Я пытаюсь предсказать цену закрытия (1 или 0), основываясь на функциях, присутствующих в 'input_data'.Но когда я пытаюсь запустить код, я получаю сообщение об ошибке ниже, я не уверен, как это исправить.Любая помощь очень ценится, спасибо
Traceback (most recent call last):
File "F:/Machine Learning/SK_Learn/SVM_Stock.py", line 71, in <module>
estimator.fit(x,y)
File "C:\Python35\lib\site-packages\keras\wrappers\scikit_learn.py", line 210, in fit
return super(KerasClassifier, self).fit(x, y, **kwargs)
File "C:\Python35\lib\site-packages\keras\wrappers\scikit_learn.py", line 139, in fit
**self.filter_sk_params(self.build_fn.__call__))
TypeError: __call__() missing 1 required positional argument: 'inputs'
Вот код:
class SVM_Stock:
def __init__(self):
pass
def create_model(self):
model = Sequential()
model.add(Dense(14, input_dim=16, kernel_initializer='normal', activation='relu'))
model.add(Dense(7, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal', activation='sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='rmsprop', metrics=['accuracy'])
return model
if __name__ == "__main__":
desired_width = 450
pd.set_option('display.width', desired_width)
pd.set_option('display.max_columns', 17)
ds = pd.read_csv('F:\\Machine Learning\\Linear Regression\\BIOCON-EQ.csv')
ds = ds[['Date','Open','High','Low','Close','Volume','Slow VWMA','Fast VWMA']][14:].sort_values('Date')
ds.loc[ds['Slow VWMA'] > ds['Fast VWMA'], 'Trend UP'] = 1
ds.loc[ds['Slow VWMA'] < ds['Fast VWMA'], 'Trend UP'] = 0
ds.loc[ds['Slow VWMA'] == ds['Fast VWMA'], 'Trend UP'] = -1
ds.loc[ds['Slow VWMA'] < ds['Fast VWMA'], 'Trend Down'] = 1
ds.loc[ds['Slow VWMA'] > ds['Fast VWMA'], 'Trend Down'] = 0
ds.loc[ds['Slow VWMA'] == ds['Fast VWMA'], 'Trend Down'] = -1
ds.loc[ds['Close'] > ds['Open'], 'Close Price'] = 1
ds.loc[ds['Close'] < ds['Open'], 'Close Price'] = 0
ds.loc[ds['Close'] == ds['Open'], 'Close Price'] = -1
input_data = ds[['Date','Open','High','Low','Close','Trend UP', 'Trend
Down']]
input_data.index = input_data.Date
input_data.drop('Date', axis=1, inplace=True)
target = ds[['Close Price']]
scaler = MinMaxScaler(feature_range=(0, 1))
x = scaler.fit_transform(input_data)
y = target.values.ravel()
# clf = svm.SVC(gamma=0.1, C=100)
# clf.fit(x[:400], y[:400])
# print(clf.score(x[:400], y[:400]))
#
# for i in range(420, len(x)):
# print("Prediction :", clf.predict(x[i].reshape(1, -1)))
# print(i, y[i])
SS = SVM_Stock()
estimator = KerasClassifier(build_fn=SS.create_model(), nb_epoch=10, verbose=0)
estimator.fit(x,y)
'''Cross Validate'''
cv_scores = cross_val_score(estimator, x, y, cv=10)
print(cv_scores.mean())