I want to build the Voting classification model for the following data as I have two different approaches and apply to vote for the same. The data are presented here.
labels New_data
0 0 [72.5, 83.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1 0 [61.5, 55.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2 0 [34.5, 38.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
3 0 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
4 0 [0.0, 17.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Here New_data is considered as an X_train data and labels should be 0 or 1 and considered as y_train data.
Another data for X_train is presented below and y_train is the same as the previous value 0 and 1.
array([[ 17, 37, 19, ..., 1, 167, 0],
[ 4, 133, 103, ..., 1, 58, 8],
[ 6, 18, 197, ..., 0, 0, 0],
...,
[ 75, 8, 17, ..., 6, 67, 6],
[155, 25, 11, ..., 0, 0, 0],
[ 2, 1, 23, ..., 223, 53, 54]], dtype=int32)
The DL model Architecture for both approach is given below.
Approach 1:
def create_model():
imp = keras.Input(shape=(len(data11["New_data"][0]), 1),dtype='int32')
x = LSTM(64, return_sequences=True,name='lstm_layer')(imp)
x = Conv1D(filters=128, kernel_size=3, padding='same', activation='relu')(x)
x = MaxPooling1D(pool_size=2)(x)
x = Dropout(0.1)(x)
x = Flatten() (x)
x = Dropout(0.1)(x)
x= Dense(250, activation='sigmoid')(x)
x= Dense(250, activation='sigmoid')(x)
preds = tf.keras.layers.Dense(1, activation='sigmoid')(x)
model = Model(inputs= imp, outputs = preds)
return model
NN_clf=KerasClassifier(build_fn = lambda: create_model(), epochs = 15, batch_size = 32, verbose = 0)
NN_clf._estimator_type = "classifier"
Approach 2:
def Create_model11():
embedding_vecor_length = 100
model1 = Sequential()
model1.add(Embedding(vocab_size, 32, input_length=maxlen))
model1.add(LSTM(32, return_sequences=True))
model1.add(Dense(1, activation='sigmoid'))
model1.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model1.summary()
return model1
NN=KerasClassifier(build_fn= lambda: Create_model11(), epochs = 15, batch_size = 32)
NN._estimator_type = "classifier"
I want to apply voting classification but am not able to perform this task can anyone please help me out? The voting classification code is written below.
voting_clf = VotingClassifier(estimators=[('Fusion', NN_clf), ('Normal', NN)])
voting_clf.fit(X_train, y_train)
Getting below error.
TypeError: Exception encountered when calling layer "lstm_layer" (type LSTM).
Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.
Call arguments received:
• inputs=tf.Tensor(shape=(None, 8, 1), dtype=int32)
• mask=None
• training=None
• initial_state=None