简体   繁体   中英

How can I get use of trained Keras model to make new predictions?

i am a newbee of Keras. When i am done with the Iris classification tutorial, i just confused with this, since we encoded those 3 kinds of iris flowers, for example, one-hot encoding. We should get 3 orthogonal vectors right?

setosa      [1 0 0]
versicolor  [0 1 0]
virginica   [0 0 1]

my model is the same as tutorial :

http://machinelearningmastery.com/multi-class-classification-tutorial-keras-deep-learning-library/

and my question is although i got the result:

Baseline: 95.33% (4.27%)

but when i call the trained deep network model:

prediction = baseline_model().predict(X)

where X is the orginal input when i trained the network

i got a very wired predictions such that:

print prediction
0,0,0
0,0,0
0,0,0
0,0,0

with all zero vectors, and i am supposed to get some one-hot encoded result right? to identify which class the flower should be.

so how can i make use of my trained Keras model while im inputting the same input X and get the classify result to plot a graph??

You need to train your network, and only then you can use it for prediction. Using the notations from the tutorial, you may do:

estimator = KerasClassifier(build_fn=baseline_model, nb_epoch=200, batch_size=5, verbose=0)
X_train, X_test, Y_train, Y_test = train_test_split(X, dummy_y, test_size=0.33, random_state=seed)
estimator.fit(X_train, Y_train)
predictions = estimator.predict(X)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM