confusion matrix in keras cnn model without xtrain xtest ytrain ytest
up vote
1
down vote
favorite
I am currently trying to implement a confusion matrix into my cnn model code. All the examples that I've been watching includes using x_train, x_test, y_train, y_test
, but I don't know how to do that on my code, or if I will be able to do it from my_model.h5 file. Hoping you could help me. Thanks.
I leave my model code below here:
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(64, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Flatten())
classifier.add(Dense(256, activation = 'relu'))
classifier.add(Dropout(0.5))
classifier.add(Dense(26, activation = 'softmax'))
classifier.compile(
optimizer = optimizers.SGD(lr = 0.01),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
classifier.summary()
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'mydata/training_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
test_set = test_datagen.flow_from_directory(
'mydata/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
model = classifier.fit_generator(
training_set,
steps_per_epoch=int(steps_per_epoch_user),
epochs=int(epochs_user),
validation_data = test_set,
validation_steps = int(validation_steps_user)
)
import h5py
classifier.save('my_model.h5')
print(model.history.keys())
import matplotlib.pyplot as plt
plt.plot(model.history['acc'])
plt.plot(model.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('acc')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
plt.plot(model.history['loss'])
plt.plot(model.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
tensorflow keras conv-neural-network confusion-matrix
add a comment |
up vote
1
down vote
favorite
I am currently trying to implement a confusion matrix into my cnn model code. All the examples that I've been watching includes using x_train, x_test, y_train, y_test
, but I don't know how to do that on my code, or if I will be able to do it from my_model.h5 file. Hoping you could help me. Thanks.
I leave my model code below here:
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(64, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Flatten())
classifier.add(Dense(256, activation = 'relu'))
classifier.add(Dropout(0.5))
classifier.add(Dense(26, activation = 'softmax'))
classifier.compile(
optimizer = optimizers.SGD(lr = 0.01),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
classifier.summary()
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'mydata/training_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
test_set = test_datagen.flow_from_directory(
'mydata/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
model = classifier.fit_generator(
training_set,
steps_per_epoch=int(steps_per_epoch_user),
epochs=int(epochs_user),
validation_data = test_set,
validation_steps = int(validation_steps_user)
)
import h5py
classifier.save('my_model.h5')
print(model.history.keys())
import matplotlib.pyplot as plt
plt.plot(model.history['acc'])
plt.plot(model.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('acc')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
plt.plot(model.history['loss'])
plt.plot(model.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
tensorflow keras conv-neural-network confusion-matrix
Does your dataset have the labels?
– Sandhiya
Nov 12 at 4:48
They're just files in labeled folders. For example:mydata/training_set/icecream
,mydata/training_set/pizza
,mydata/training_set/hotdog
and so on.
– J. Dav
Nov 12 at 12:39
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am currently trying to implement a confusion matrix into my cnn model code. All the examples that I've been watching includes using x_train, x_test, y_train, y_test
, but I don't know how to do that on my code, or if I will be able to do it from my_model.h5 file. Hoping you could help me. Thanks.
I leave my model code below here:
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(64, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Flatten())
classifier.add(Dense(256, activation = 'relu'))
classifier.add(Dropout(0.5))
classifier.add(Dense(26, activation = 'softmax'))
classifier.compile(
optimizer = optimizers.SGD(lr = 0.01),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
classifier.summary()
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'mydata/training_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
test_set = test_datagen.flow_from_directory(
'mydata/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
model = classifier.fit_generator(
training_set,
steps_per_epoch=int(steps_per_epoch_user),
epochs=int(epochs_user),
validation_data = test_set,
validation_steps = int(validation_steps_user)
)
import h5py
classifier.save('my_model.h5')
print(model.history.keys())
import matplotlib.pyplot as plt
plt.plot(model.history['acc'])
plt.plot(model.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('acc')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
plt.plot(model.history['loss'])
plt.plot(model.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
tensorflow keras conv-neural-network confusion-matrix
I am currently trying to implement a confusion matrix into my cnn model code. All the examples that I've been watching includes using x_train, x_test, y_train, y_test
, but I don't know how to do that on my code, or if I will be able to do it from my_model.h5 file. Hoping you could help me. Thanks.
I leave my model code below here:
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Conv2D(64, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size =(2,2)))
classifier.add(Flatten())
classifier.add(Dense(256, activation = 'relu'))
classifier.add(Dropout(0.5))
classifier.add(Dense(26, activation = 'softmax'))
classifier.compile(
optimizer = optimizers.SGD(lr = 0.01),
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
classifier.summary()
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'mydata/training_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
test_set = test_datagen.flow_from_directory(
'mydata/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
model = classifier.fit_generator(
training_set,
steps_per_epoch=int(steps_per_epoch_user),
epochs=int(epochs_user),
validation_data = test_set,
validation_steps = int(validation_steps_user)
)
import h5py
classifier.save('my_model.h5')
print(model.history.keys())
import matplotlib.pyplot as plt
plt.plot(model.history['acc'])
plt.plot(model.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('acc')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
plt.plot(model.history['loss'])
plt.plot(model.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
tensorflow keras conv-neural-network confusion-matrix
tensorflow keras conv-neural-network confusion-matrix
edited Nov 12 at 12:42
asked Nov 12 at 1:18
J. Dav
113
113
Does your dataset have the labels?
– Sandhiya
Nov 12 at 4:48
They're just files in labeled folders. For example:mydata/training_set/icecream
,mydata/training_set/pizza
,mydata/training_set/hotdog
and so on.
– J. Dav
Nov 12 at 12:39
add a comment |
Does your dataset have the labels?
– Sandhiya
Nov 12 at 4:48
They're just files in labeled folders. For example:mydata/training_set/icecream
,mydata/training_set/pizza
,mydata/training_set/hotdog
and so on.
– J. Dav
Nov 12 at 12:39
Does your dataset have the labels?
– Sandhiya
Nov 12 at 4:48
Does your dataset have the labels?
– Sandhiya
Nov 12 at 4:48
They're just files in labeled folders. For example:
mydata/training_set/icecream
, mydata/training_set/pizza
, mydata/training_set/hotdog
and so on.– J. Dav
Nov 12 at 12:39
They're just files in labeled folders. For example:
mydata/training_set/icecream
, mydata/training_set/pizza
, mydata/training_set/hotdog
and so on.– J. Dav
Nov 12 at 12:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I would add the following code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(Y_test,Y_test_predicted)
print('n','cm=','n',cm)
for more descriptive confusion matrix look at scikit-learn documentation in the following link:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I would add the following code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(Y_test,Y_test_predicted)
print('n','cm=','n',cm)
for more descriptive confusion matrix look at scikit-learn documentation in the following link:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
add a comment |
up vote
0
down vote
I would add the following code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(Y_test,Y_test_predicted)
print('n','cm=','n',cm)
for more descriptive confusion matrix look at scikit-learn documentation in the following link:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
add a comment |
up vote
0
down vote
up vote
0
down vote
I would add the following code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(Y_test,Y_test_predicted)
print('n','cm=','n',cm)
for more descriptive confusion matrix look at scikit-learn documentation in the following link:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
I would add the following code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(Y_test,Y_test_predicted)
print('n','cm=','n',cm)
for more descriptive confusion matrix look at scikit-learn documentation in the following link:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
answered Nov 26 at 22:47
Faris
61
61
add a comment |
add a 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53254879%2fconfusion-matrix-in-keras-cnn-model-without-xtrain-xtest-ytrain-ytest%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
Does your dataset have the labels?
– Sandhiya
Nov 12 at 4:48
They're just files in labeled folders. For example:
mydata/training_set/icecream
,mydata/training_set/pizza
,mydata/training_set/hotdog
and so on.– J. Dav
Nov 12 at 12:39