2
$\begingroup$

I have tried creating a pipeline like this but I am getting error

- AttributeError: 'Pipeline' object has no attribute 'compile'

scaler = StandardScaler()
model = Sequential()

model.add(Dense(120, input_dim=46,activation='relu'))
model.add(Dropout(0.1, noise_shape=None, seed=None))

model.add(Dense(80, activation='relu'))
model.add(Dropout(0.1, noise_shape=None, seed=None))

model.add(Dense(40, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

pipeline = make_pipeline(scaler,model)
pipeline.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])


pipeline.fit(X_train,y_train, epochs=50, batch_size=20, validation_data = (X_test,y_test))

# evaluate the model
scores = pipeline.evaluate(X_test,y_test)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
$\endgroup$
1
  • $\begingroup$ may i know the reason for down vote ? $\endgroup$ May 28, 2018 at 10:25

2 Answers 2

1
$\begingroup$

I am able to achieve this with below code

Thanks @JahKnows

scaler = StandardScaler()
model = Sequential()

model.add(Dense(120, input_dim=46,activation='relu'))
model.add(Dropout(0.1, noise_shape=None, seed=None))

model.add(Dense(80, activation='relu'))
model.add(Dropout(0.1, noise_shape=None, seed=None))

model.add(Dense(40, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

pipeline = Pipeline([("scaler",scaler),("model",model)])
pipeline.fit(X_train,y_train, model__epochs=50, model__batch_size=20, model__validation_data = (X_test,y_test))

# evaluate the model
nn_pred = grid_search.predict(X_test)

print('Accuracy of NN on test is:',accuracy_score(y_test,nn_pred))
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
$\endgroup$
0
$\begingroup$

You should compile your model before you put it into the pipeline.

scaler = StandardScaler()
model = Sequential()

model.add(Dense(120, input_dim=46,activation='relu'))
model.add(Dropout(0.1, noise_shape=None, seed=None))

model.add(Dense(80, activation='relu'))
model.add(Dropout(0.1, noise_shape=None, seed=None))

model.add(Dense(40, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

pipeline = make_pipeline(scaler,model)
pipeline.fit(X_train,y_train, epochs=50, batch_size=20, validation_data = (X_test,y_test))

# evaluate the model
scores = pipeline.evaluate(X_test,y_test)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
$\endgroup$
2
  • $\begingroup$ I am getting again some exception "not enough values to unpack (expected 2, got 1)" $\endgroup$ May 27, 2018 at 12:38
  • $\begingroup$ Can you put your entire code leading up to this and a snippet of your data? $\endgroup$
    – JahKnows
    May 27, 2018 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.