Open Symbadian opened 3 years ago
import keras import matplotlib.pyplot as plt import numpy as np import seaborn as sns from keras.datasets import mnist from sklearn.metrics import confusion_matrix
(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 28, 28, 1) x_test = x_test.reshape(10000, 28, 28, 1) print(x_train.shape) print(x_test.shape)
model = keras.models.Sequential() model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(64, activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary()
model.fit(x=x_train, y=y_train, batch_size=512, epochs=10, validation_data=(x_test, y_test))
y_pred = model.predict_classes(x_test) print(y_pred)
print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
plt.figure(figsize=(8, 8)) sns.heatmap(con_mat_norm, annot=True, cmap='Blues')
plt.ylim(0, 10) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show()
Hi Liupeng678,
I got your model to run and now that it is successful I am trying to plug in the confusion matrix to attain the true metrics for the model's performance!
This is my final analysis to determine the efficiency of your works
Can you assist me, please?
Dear MatParr. This is my previous work for confusion matrix in another work. Hoping this work is able to help your project.
Hi liupeng678,
Thanx for your swift response pal, I am stuck at the confusion matrix! I see you wrote in the labels categories for the classes! labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
What I am trying to do is pass all of the labels in via the variables you created in the code!
To see a total of what was predicted according to the TP, FP, FN, TN here is an example of the output results I am trying to achieve
Is this possible? Or am I missing something here? Please let me know standing by!!
[Chart, treemap chart Description automatically generated]
What I tried: but failed labels = labels labels = labellist labels = nclass labels = nb_classes labels = args.nclass
This is the challenge, I keep getting errors! Why I am do this? I am trying to bypass the tedious task of writing out all of the categories for the number of classes as you did!
con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"]) con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # normalisation con_mat_norm = np.around(con_mat_norm, decimals=2)
From: liupeng678 @.> Date: Friday, 7 May 2021 at 12:51 To: liupeng678/3DCNN-with-keras @.> Cc: MatParr @.>, Author @.> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5)
import keras import matplotlib.pyplot as plt import numpy as np import seaborn as sns from keras.datasets import mnist from sklearn.metrics import confusion_matrix
=== dataset ===
(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 28, 28, 1) x_test = x_test.reshape(10000, 28, 28, 1) print(x_train.shape) print(x_test.shape)
=== model: CNN ===
model = keras.models.Sequential() model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(64, activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary()
=== train ===
model.fit(x=x_train, y=y_train, batch_size=512, epochs=10, validation_data=(x_test, y_test))
=== pred ===
y_pred = model.predict_classes(x_test) print(y_pred)
https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html
print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
=== plot ===
plt.figure(figsize=(8, 8)) sns.heatmap(con_mat_norm, annot=True, cmap='Blues')
plt.ylim(0, 10) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show()
― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/liupeng678/3DCNN-with-keras/issues/5#issuecomment-834304143, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL7WSHMSENDHU3PIGHIGLBDTMPH47ANCNFSM44GOILMA.
Hi Liupeng,
I am still at it here pal with your code,
When I print these details they are all numbers print(y_test) print(y_pred)
but I want to access the actual name, hence me working assiduously to process such!
Somehow what you provided here has actual names in that processing but the output generate from your code is numbers as specified! print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
can you assist me here, please?
Thanks loads in advance!
From: mm gp @.> Date: Friday, 7 May 2021 at 13:27 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) Hi liupeng678,
Thanx for your swift response pal, I am stuck at the confusion matrix! I see you wrote in the labels categories for the classes! labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
What I am trying to do is pass all of the labels in via the variables you created in the code!
To see a total of what was predicted according to the TP, FP, FN, TN here is an example of the output results I am trying to achieve
Is this possible? Or am I missing something here? Please let me know standing by!!
[Chart, treemap chart Description automatically generated]
What I tried: but failed labels = labels labels = labellist labels = nclass labels = nb_classes labels = args.nclass
This is the challenge, I keep getting errors! Why I am do this? I am trying to bypass the tedious task of writing out all of the categories for the number of classes as you did!
con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"]) con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # normalisation con_mat_norm = np.around(con_mat_norm, decimals=2)
From: liupeng678 @.> Date: Friday, 7 May 2021 at 12:51 To: liupeng678/3DCNN-with-keras @.> Cc: MatParr @.>, Author @.> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5)
import keras import matplotlib.pyplot as plt import numpy as np import seaborn as sns from keras.datasets import mnist from sklearn.metrics import confusion_matrix
=== dataset ===
(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 28, 28, 1) x_test = x_test.reshape(10000, 28, 28, 1) print(x_train.shape) print(x_test.shape)
=== model: CNN ===
model = keras.models.Sequential() model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(64, activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary()
=== train ===
model.fit(x=x_train, y=y_train, batch_size=512, epochs=10, validation_data=(x_test, y_test))
=== pred ===
y_pred = model.predict_classes(x_test) print(y_pred)
https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html
print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
=== plot ===
plt.figure(figsize=(8, 8)) sns.heatmap(con_mat_norm, annot=True, cmap='Blues')
plt.ylim(0, 10) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show()
― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/liupeng678/3DCNN-with-keras/issues/5#issuecomment-834304143, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL7WSHMSENDHU3PIGHIGLBDTMPH47ANCNFSM44GOILMA.
This is my output, but I am trying to get the labels, would be really helpful with your guidance here! The previous code you’ve sent is complex and I am uncertain if is applicable for this scenario! Please provide some feedback, thanks loads….
Thanks once more! [A picture containing background pattern Description automatically generated]
From: mm gp @.> Date: Friday, 7 May 2021 at 13:27 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) Hi liupeng678,
Thanx for your swift response pal, I am stuck at the confusion matrix! I see you wrote in the labels categories for the classes! labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
What I am trying to do is pass all of the labels in via the variables you created in the code!
To see a total of what was predicted according to the TP, FP, FN, TN here is an example of the output results I am trying to achieve
Is this possible? Or am I missing something here? Please let me know standing by!!
[Chart, treemap chart Description automatically generated]
What I tried: but failed labels = labels labels = labellist labels = nclass labels = nb_classes labels = args.nclass
This is the challenge, I keep getting errors! Why I am do this? I am trying to bypass the tedious task of writing out all of the categories for the number of classes as you did!
con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"]) con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # normalisation con_mat_norm = np.around(con_mat_norm, decimals=2)
From: liupeng678 @.> Date: Friday, 7 May 2021 at 12:51 To: liupeng678/3DCNN-with-keras @.> Cc: MatParr @.>, Author @.> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5)
import keras import matplotlib.pyplot as plt import numpy as np import seaborn as sns from keras.datasets import mnist from sklearn.metrics import confusion_matrix
=== dataset ===
(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 28, 28, 1) x_test = x_test.reshape(10000, 28, 28, 1) print(x_train.shape) print(x_test.shape)
=== model: CNN ===
model = keras.models.Sequential() model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(64, activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary()
=== train ===
model.fit(x=x_train, y=y_train, batch_size=512, epochs=10, validation_data=(x_test, y_test))
=== pred ===
y_pred = model.predict_classes(x_test) print(y_pred)
https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html
print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
=== plot ===
plt.figure(figsize=(8, 8)) sns.heatmap(con_mat_norm, annot=True, cmap='Blues')
plt.ylim(0, 10) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show()
― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/liupeng678/3DCNN-with-keras/issues/5#issuecomment-834304143, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL7WSHMSENDHU3PIGHIGLBDTMPH47ANCNFSM44GOILMA.
Hi liupeng678,
Can you highlight how much of the predictions was incorrectly classified, correctly classified etc? I went online to see if I miss this file in your download data folder, but it is not specified! This is what I am trying to solve!
Please guide me here!
Thanx loads!
From: mm gp @.> Date: Saturday, 8 May 2021 at 17:00 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) This is my output, but I am trying to get the labels, would be really helpful with your guidance here! The previous code you’ve sent is complex and I am uncertain if is applicable for this scenario! Please provide some feedback, thanks loads….
Thanks once more! [A picture containing background pattern Description automatically generated]
From: mm gp @.> Date: Friday, 7 May 2021 at 13:27 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) Hi liupeng678,
Thanx for your swift response pal, I am stuck at the confusion matrix! I see you wrote in the labels categories for the classes! labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
What I am trying to do is pass all of the labels in via the variables you created in the code!
To see a total of what was predicted according to the TP, FP, FN, TN here is an example of the output results I am trying to achieve
Is this possible? Or am I missing something here? Please let me know standing by!!
[Chart, treemap chart Description automatically generated]
What I tried: but failed labels = labels labels = labellist labels = nclass labels = nb_classes labels = args.nclass
This is the challenge, I keep getting errors! Why I am do this? I am trying to bypass the tedious task of writing out all of the categories for the number of classes as you did!
con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"]) con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # normalisation con_mat_norm = np.around(con_mat_norm, decimals=2)
From: liupeng678 @.> Date: Friday, 7 May 2021 at 12:51 To: liupeng678/3DCNN-with-keras @.> Cc: MatParr @.>, Author @.> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5)
import keras import matplotlib.pyplot as plt import numpy as np import seaborn as sns from keras.datasets import mnist from sklearn.metrics import confusion_matrix
=== dataset ===
(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 28, 28, 1) x_test = x_test.reshape(10000, 28, 28, 1) print(x_train.shape) print(x_test.shape)
=== model: CNN ===
model = keras.models.Sequential() model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(64, activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary()
=== train ===
model.fit(x=x_train, y=y_train, batch_size=512, epochs=10, validation_data=(x_test, y_test))
=== pred ===
y_pred = model.predict_classes(x_test) print(y_pred)
https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html
print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
=== plot ===
plt.figure(figsize=(8, 8)) sns.heatmap(con_mat_norm, annot=True, cmap='Blues')
plt.ylim(0, 10) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show()
― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/liupeng678/3DCNN-with-keras/issues/5#issuecomment-834304143, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL7WSHMSENDHU3PIGHIGLBDTMPH47ANCNFSM44GOILMA.
Hi Liupeng678,
I tried your solution for the confusion matrix based on the code you’ve sent but none of it seems to be effective based on my efforts!
Are you certain that this produced the metrics for your model that I am working on? If yes, Can you demonstrate how you deployed it, please? I am really trying to understand how you did this so that I can document the true nature of your model! Thanks a mill, anticipating your response pal!
Cheers!
From: mm gp @.> Date: Sunday, 9 May 2021 at 12:10 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) Hi liupeng678,
Can you highlight how much of the predictions was incorrectly classified, correctly classified etc? I went online to see if I miss this file in your download data folder, but it is not specified! This is what I am trying to solve!
Please guide me here!
Thanx loads!
From: mm gp @.> Date: Saturday, 8 May 2021 at 17:00 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) This is my output, but I am trying to get the labels, would be really helpful with your guidance here! The previous code you’ve sent is complex and I am uncertain if is applicable for this scenario! Please provide some feedback, thanks loads….
Thanks once more! [A picture containing background pattern Description automatically generated]
From: mm gp @.> Date: Friday, 7 May 2021 at 13:27 To: liupeng678/3DCNN-with-keras @.>, liupeng678/3DCNN-with-keras @.***> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5) Hi liupeng678,
Thanx for your swift response pal, I am stuck at the confusion matrix! I see you wrote in the labels categories for the classes! labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
What I am trying to do is pass all of the labels in via the variables you created in the code!
To see a total of what was predicted according to the TP, FP, FN, TN here is an example of the output results I am trying to achieve
Is this possible? Or am I missing something here? Please let me know standing by!!
[Chart, treemap chart Description automatically generated]
What I tried: but failed labels = labels labels = labellist labels = nclass labels = nb_classes labels = args.nclass
This is the challenge, I keep getting errors! Why I am do this? I am trying to bypass the tedious task of writing out all of the categories for the number of classes as you did!
con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"]) con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # normalisation con_mat_norm = np.around(con_mat_norm, decimals=2)
From: liupeng678 @.> Date: Friday, 7 May 2021 at 12:51 To: liupeng678/3DCNN-with-keras @.> Cc: MatParr @.>, Author @.> Subject: Re: [liupeng678/3DCNN-with-keras] No Metrics For Model (#5)
import keras import matplotlib.pyplot as plt import numpy as np import seaborn as sns from keras.datasets import mnist from sklearn.metrics import confusion_matrix
=== dataset ===
(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.reshape(60000, 28, 28, 1) x_test = x_test.reshape(10000, 28, 28, 1) print(x_train.shape) print(x_test.shape)
=== model: CNN ===
model = keras.models.Sequential() model.add(keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) model.add(keras.layers.MaxPooling2D((2, 2))) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(64, activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.summary()
=== train ===
model.fit(x=x_train, y=y_train, batch_size=512, epochs=10, validation_data=(x_test, y_test))
=== pred ===
y_pred = model.predict_classes(x_test) print(y_pred)
https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html
print(y_test) print(y_pred) con_mat = confusion_matrix(y_test, y_pred,labels=["ant", "bird", "cat1","cat2","cat3","cat4","cat5","cat6","cat7","cat8"])
con_mat_norm = con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis] # 归一化 con_mat_norm = np.around(con_mat_norm, decimals=2)
=== plot ===
plt.figure(figsize=(8, 8)) sns.heatmap(con_mat_norm, annot=True, cmap='Blues')
plt.ylim(0, 10) plt.xlabel('Predicted labels') plt.ylabel('True labels') plt.show()
― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/liupeng678/3DCNN-with-keras/issues/5#issuecomment-834304143, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL7WSHMSENDHU3PIGHIGLBDTMPH47ANCNFSM44GOILMA.
Hi Liupeng678,
I got your model to run and now that it is successful I am trying to plug in the confusion matrix to attain the true metrics for the model's performance!
This is my final analysis to determine the efficiency of your works
Can you assist me, please?