How to add lstm regressor as estimator in paired_ttest_5x2cv function #1014
Replies: 4 comments 2 replies
-
Sorry i am comparing lstm with SVR. If i compare svr and KNN there is no issue, but wiht lstm i do not know how to fix the shape. |
Beta Was this translation helpful? Give feedback.
-
It looks like the LSTM is taking in a 3D input? I think you may have to write a custom wrapper to reshare the 2D into a 3D input. With that, I mean you need a class around the LSTM that takes care of the reshaping. |
Beta Was this translation helpful? Give feedback.
-
I have written a class. I am not sure whether this is the right approach. I am a beginner. Please excuse me for my coding skills. I am getting an error. lstm_model=lstm_create(X,y) class lstm_create:
t, p = paired_ttest_5x2cv(estimator1=svr_rbf, It is throwing an error as below: ~\anaconda3\lib\site-packages\mlxtend\evaluate\ttest.py in paired_ttest_5x2cv(estimator1, estimator2, X, y, scoring, random_seed) ~\anaconda3\lib\site-packages\mlxtend\evaluate\ttest.py in score_diff(X_1, X_2, y_1, y_2) TypeError: fit() takes 2 positional arguments but 3 were given. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Hi there, I think the issue in your case is that the your model doesn't support What would be required here is a class that has a fit function. The skeleton would be something like the following class MyLSTM():
def __init__(self, model, ...):
self.model = ...
...
def fit(self, X, y):
...
model.fit(...)
def predict(X):
...
model.predict(...) |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to compare lstm model to a knn, but the lstm model estimator is showing problems with the shape of the input. Can someone suggest how to pass the lstm model to the paired_ttest_5x2cv function.
cr_model():
n_timesteps=15
n_features=3
model = Sequential()
model.add(LSTM(16, input_shape=(n_timesteps,n_features)))
model.add(Dense(1, activation='relu'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
lstm_model=cr_model()
from sklearn.svm import SVR
svr_rbf = SVR(kernel= 'rbf', C= 1e2, gamma= 0.1)
t, p = paired_ttest_5x2cv(estimator1=svr_rbf,
estimator2=lstm_model,
X=X, y=y,
random_seed=1)
ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 15, 3), found shape=(None, 3)
How can I correct this error. Kindly help.
Regards,
Nikhitha.
Beta Was this translation helpful? Give feedback.
All reactions