Labels for Keras Model Predicting Multi-Classification Problem
If I have a set of targets a.k.a y's as [1,0,9,9,7,5,4,0,4,1]
and I use model.predict(X)
Keras returns a 6 item array for each of the 10 samples. It returns 6 items because there are 6 possible targets (0,1,4,5,7,9) and keras returns a decimal/float (for each label) representing likelihood of any one of those being the correct target. For the first sample, for example - where y=1 Keras returns an array that looks like this: [.1, .4,.003,.001,.5,.003]
.
I want to know which value matches to which target (does .1 refer to 1 because it's first in the dataset or 0 because it's the lowest number or 9 because it's the last number, etc). How does Keras order it's predictions? The documentation does not seem to articulate this; it only says
"Generates output predictions for the input samples."
So I'm not sure how to match the labels to the prediction results.
EDIT:
Here is my model and training code:
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.25, random_state=42)
Y_train = to_categorical(y_train)
Y_test = to_categorical(y_test)
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
x = Conv1D(64, 5, activation='relu')(embedded_sequences)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x) # global max pooling
x = Flatten()(x)
x = Dense(64, activation='relu')(x)
preds = Dense(labels_Index, activation='softmax')(x)
model = Model(sequence_input, preds)
model.fit(X_train, Y_train, epochs=10, verbose = 1)
python keras label predict
add a comment |
If I have a set of targets a.k.a y's as [1,0,9,9,7,5,4,0,4,1]
and I use model.predict(X)
Keras returns a 6 item array for each of the 10 samples. It returns 6 items because there are 6 possible targets (0,1,4,5,7,9) and keras returns a decimal/float (for each label) representing likelihood of any one of those being the correct target. For the first sample, for example - where y=1 Keras returns an array that looks like this: [.1, .4,.003,.001,.5,.003]
.
I want to know which value matches to which target (does .1 refer to 1 because it's first in the dataset or 0 because it's the lowest number or 9 because it's the last number, etc). How does Keras order it's predictions? The documentation does not seem to articulate this; it only says
"Generates output predictions for the input samples."
So I'm not sure how to match the labels to the prediction results.
EDIT:
Here is my model and training code:
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.25, random_state=42)
Y_train = to_categorical(y_train)
Y_test = to_categorical(y_test)
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
x = Conv1D(64, 5, activation='relu')(embedded_sequences)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x) # global max pooling
x = Flatten()(x)
x = Dense(64, activation='relu')(x)
preds = Dense(labels_Index, activation='softmax')(x)
model = Model(sequence_input, preds)
model.fit(X_train, Y_train, epochs=10, verbose = 1)
python keras label predict
add a comment |
If I have a set of targets a.k.a y's as [1,0,9,9,7,5,4,0,4,1]
and I use model.predict(X)
Keras returns a 6 item array for each of the 10 samples. It returns 6 items because there are 6 possible targets (0,1,4,5,7,9) and keras returns a decimal/float (for each label) representing likelihood of any one of those being the correct target. For the first sample, for example - where y=1 Keras returns an array that looks like this: [.1, .4,.003,.001,.5,.003]
.
I want to know which value matches to which target (does .1 refer to 1 because it's first in the dataset or 0 because it's the lowest number or 9 because it's the last number, etc). How does Keras order it's predictions? The documentation does not seem to articulate this; it only says
"Generates output predictions for the input samples."
So I'm not sure how to match the labels to the prediction results.
EDIT:
Here is my model and training code:
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.25, random_state=42)
Y_train = to_categorical(y_train)
Y_test = to_categorical(y_test)
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
x = Conv1D(64, 5, activation='relu')(embedded_sequences)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x) # global max pooling
x = Flatten()(x)
x = Dense(64, activation='relu')(x)
preds = Dense(labels_Index, activation='softmax')(x)
model = Model(sequence_input, preds)
model.fit(X_train, Y_train, epochs=10, verbose = 1)
python keras label predict
If I have a set of targets a.k.a y's as [1,0,9,9,7,5,4,0,4,1]
and I use model.predict(X)
Keras returns a 6 item array for each of the 10 samples. It returns 6 items because there are 6 possible targets (0,1,4,5,7,9) and keras returns a decimal/float (for each label) representing likelihood of any one of those being the correct target. For the first sample, for example - where y=1 Keras returns an array that looks like this: [.1, .4,.003,.001,.5,.003]
.
I want to know which value matches to which target (does .1 refer to 1 because it's first in the dataset or 0 because it's the lowest number or 9 because it's the last number, etc). How does Keras order it's predictions? The documentation does not seem to articulate this; it only says
"Generates output predictions for the input samples."
So I'm not sure how to match the labels to the prediction results.
EDIT:
Here is my model and training code:
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.25, random_state=42)
Y_train = to_categorical(y_train)
Y_test = to_categorical(y_test)
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
x = Conv1D(64, 5, activation='relu')(embedded_sequences)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x) # global max pooling
x = Flatten()(x)
x = Dense(64, activation='relu')(x)
preds = Dense(labels_Index, activation='softmax')(x)
model = Model(sequence_input, preds)
model.fit(X_train, Y_train, epochs=10, verbose = 1)
python keras label predict
python keras label predict
edited Jan 3 at 21:58
Liam Hanninen
asked Jan 2 at 22:11


Liam HanninenLiam Hanninen
329315
329315
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Keras doesn't order anything, it all depend on how the classes in the data you used to train the model are defined and one-hot encoded.
You can usually recover the integer class label by taking the argmax
of the class probability array for each sample.
From your example, 0.1 is class 0, 0.4 is class 1, 0.003 is class 2, 0.001 is class 3, 0.5 is class 4, and 0.003 is class 5 (6 classes in total).
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013853%2flabels-for-keras-model-predicting-multi-classification-problem%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Keras doesn't order anything, it all depend on how the classes in the data you used to train the model are defined and one-hot encoded.
You can usually recover the integer class label by taking the argmax
of the class probability array for each sample.
From your example, 0.1 is class 0, 0.4 is class 1, 0.003 is class 2, 0.001 is class 3, 0.5 is class 4, and 0.003 is class 5 (6 classes in total).
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
|
show 1 more comment
Keras doesn't order anything, it all depend on how the classes in the data you used to train the model are defined and one-hot encoded.
You can usually recover the integer class label by taking the argmax
of the class probability array for each sample.
From your example, 0.1 is class 0, 0.4 is class 1, 0.003 is class 2, 0.001 is class 3, 0.5 is class 4, and 0.003 is class 5 (6 classes in total).
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
|
show 1 more comment
Keras doesn't order anything, it all depend on how the classes in the data you used to train the model are defined and one-hot encoded.
You can usually recover the integer class label by taking the argmax
of the class probability array for each sample.
From your example, 0.1 is class 0, 0.4 is class 1, 0.003 is class 2, 0.001 is class 3, 0.5 is class 4, and 0.003 is class 5 (6 classes in total).
Keras doesn't order anything, it all depend on how the classes in the data you used to train the model are defined and one-hot encoded.
You can usually recover the integer class label by taking the argmax
of the class probability array for each sample.
From your example, 0.1 is class 0, 0.4 is class 1, 0.003 is class 2, 0.001 is class 3, 0.5 is class 4, and 0.003 is class 5 (6 classes in total).
answered Jan 2 at 22:50
Matias ValdenegroMatias Valdenegro
32.2k45782
32.2k45782
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
|
show 1 more comment
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Thanks for taking a stab at this! I don't want to find the integer class label (for this question). I want to find what the integer class label that ties to my labels. All Keras knows is the data I trained it on. Imagine I didn't even encode - and that these (0,1,4,5,7,9) are just discrete integers that identify my classes. (0,1,2,3,4,5) are the very same classes but are meaningless to me because I don't know which one of my labels tie to them.
– Liam Hanninen
Jan 2 at 23:03
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
Keras does not store that information, the semantic meaning of thr labels is something defined at model training and has to be saved separately.
– Matias Valdenegro
Jan 2 at 23:07
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
How? That might be the answer I'm looking for.
– Liam Hanninen
Jan 3 at 14:18
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
@LiamHanninen You should include the training script in your question for that to be answerable.
– Matias Valdenegro
Jan 3 at 14:25
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
Good point. I just added it.
– Liam Hanninen
Jan 3 at 21:58
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013853%2flabels-for-keras-model-predicting-multi-classification-problem%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown