K-fold cross validation of scikit-learn with confusion matrix of Keras The Next CEO of Stack Overflow2019 Community Moderator ElectionCross Validation in KerasK-Fold Cross validation confusion?Linear Regression and k-fold cross validationK fold cross validation algorithmHow does k fold cross validation work?k-fold cross-validation: model selection or variation in models when using k-fold cross validationQuestion about K-Fold Cross ValidationSimple prediction with KerasK-fold cross validation when using fit_generator and flow_from_directory() in KerasUsing K-fold cross-validation in Keras on the data of my model
Solving system of ODEs with extra parameter
Does soap repel water?
How to count occurrences of text in a file?
Rotate a column
What was the first Unix version to run on a microcomputer?
What can we do to stop prior company from asking us questions?
Is there a difference between "Fahrstuhl" and "Aufzug"
Why do remote US companies require working in the US?
Writing differences on a blackboard
Why does standard notation not preserve intervals (visually)
Is micro rebar a better way to reinforce concrete than rebar?
Display a text message if the shortcode is not found?
What is the difference between 翼 and 翅膀?
Received an invoice from my ex-employer billing me for training; how to handle?
How to get from Geneva Airport to Metabief?
How to scale a tikZ image which is within a figure environment
How many extra stops do monopods offer for tele photographs?
Why this way of making earth uninhabitable in Interstellar?
Do I need to write [sic] when a number is less than 10 but isn't written out?
Is this "being" usage is essential?
Unreliable Magic - Is it worth it?
If the updated MCAS software needs two AOA sensors, doesn't that introduce a new single point of failure?
Is there a way to bypass a component in series in a circuit if that component fails?
Can MTA send mail via a relay without being told so?
K-fold cross validation of scikit-learn with confusion matrix of Keras
The Next CEO of Stack Overflow2019 Community Moderator ElectionCross Validation in KerasK-Fold Cross validation confusion?Linear Regression and k-fold cross validationK fold cross validation algorithmHow does k fold cross validation work?k-fold cross-validation: model selection or variation in models when using k-fold cross validationQuestion about K-Fold Cross ValidationSimple prediction with KerasK-fold cross validation when using fit_generator and flow_from_directory() in KerasUsing K-fold cross-validation in Keras on the data of my model
$begingroup$
I intend to display confusion matrix using Keras while K-fold of scikit-learn. My code using Keras is:
import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
seed = 7
numpy.random.seed(seed)
# load dataset
dataframe = pandas.read_csv("BolMov.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:24].astype(float)
Y = dataset[:,24]
model = Sequential()
model.add(Dense(16, activation='relu'))
model.add(Dense(7, activation='softmax')
model.compile('adam', 'categorical_crossentropy', metrics=['accuracy'])
y_cat = to_categorical(Y)
result = model.fit(X, y_cat, verbose=0, epochs=50)
plot_loss_accuracy(result)
y_pred = model.predict_classes(X, verbose=0)
print(classification_report(y, y_pred))
plot_confusion_matrix(model, X, y)
How should I use kfold in this code? Here the author is calling a function. What I believe is that if I do so in my code, the model.fit() will be executed twice - once for my Keras code and another time (internally) for the KerasClassifier(). I want that the model.fit() executes once only. Help from anyone is appreciated.
keras scikit-learn cross-validation
$endgroup$
add a comment |
$begingroup$
I intend to display confusion matrix using Keras while K-fold of scikit-learn. My code using Keras is:
import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
seed = 7
numpy.random.seed(seed)
# load dataset
dataframe = pandas.read_csv("BolMov.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:24].astype(float)
Y = dataset[:,24]
model = Sequential()
model.add(Dense(16, activation='relu'))
model.add(Dense(7, activation='softmax')
model.compile('adam', 'categorical_crossentropy', metrics=['accuracy'])
y_cat = to_categorical(Y)
result = model.fit(X, y_cat, verbose=0, epochs=50)
plot_loss_accuracy(result)
y_pred = model.predict_classes(X, verbose=0)
print(classification_report(y, y_pred))
plot_confusion_matrix(model, X, y)
How should I use kfold in this code? Here the author is calling a function. What I believe is that if I do so in my code, the model.fit() will be executed twice - once for my Keras code and another time (internally) for the KerasClassifier(). I want that the model.fit() executes once only. Help from anyone is appreciated.
keras scikit-learn cross-validation
$endgroup$
$begingroup$
don't call model.fit() as you currently do in your code but instead wrap your model in a KerasClassifier() and apply KFold() to it
$endgroup$
– pcko1
Feb 16 at 23:58
$begingroup$
@pcko1 Can I write like this:result = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=5, verbose=0)
and thenplot_loss_accuracy(result)
so thatresult
can be used for kfold validation of scikit-learn as well as confusion matrix display of Keras?
$endgroup$
– PS Nayak
Feb 18 at 14:08
add a comment |
$begingroup$
I intend to display confusion matrix using Keras while K-fold of scikit-learn. My code using Keras is:
import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
seed = 7
numpy.random.seed(seed)
# load dataset
dataframe = pandas.read_csv("BolMov.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:24].astype(float)
Y = dataset[:,24]
model = Sequential()
model.add(Dense(16, activation='relu'))
model.add(Dense(7, activation='softmax')
model.compile('adam', 'categorical_crossentropy', metrics=['accuracy'])
y_cat = to_categorical(Y)
result = model.fit(X, y_cat, verbose=0, epochs=50)
plot_loss_accuracy(result)
y_pred = model.predict_classes(X, verbose=0)
print(classification_report(y, y_pred))
plot_confusion_matrix(model, X, y)
How should I use kfold in this code? Here the author is calling a function. What I believe is that if I do so in my code, the model.fit() will be executed twice - once for my Keras code and another time (internally) for the KerasClassifier(). I want that the model.fit() executes once only. Help from anyone is appreciated.
keras scikit-learn cross-validation
$endgroup$
I intend to display confusion matrix using Keras while K-fold of scikit-learn. My code using Keras is:
import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
seed = 7
numpy.random.seed(seed)
# load dataset
dataframe = pandas.read_csv("BolMov.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:24].astype(float)
Y = dataset[:,24]
model = Sequential()
model.add(Dense(16, activation='relu'))
model.add(Dense(7, activation='softmax')
model.compile('adam', 'categorical_crossentropy', metrics=['accuracy'])
y_cat = to_categorical(Y)
result = model.fit(X, y_cat, verbose=0, epochs=50)
plot_loss_accuracy(result)
y_pred = model.predict_classes(X, verbose=0)
print(classification_report(y, y_pred))
plot_confusion_matrix(model, X, y)
How should I use kfold in this code? Here the author is calling a function. What I believe is that if I do so in my code, the model.fit() will be executed twice - once for my Keras code and another time (internally) for the KerasClassifier(). I want that the model.fit() executes once only. Help from anyone is appreciated.
keras scikit-learn cross-validation
keras scikit-learn cross-validation
edited Feb 16 at 17:46
PS Nayak
asked Feb 16 at 17:38
PS NayakPS Nayak
134
134
$begingroup$
don't call model.fit() as you currently do in your code but instead wrap your model in a KerasClassifier() and apply KFold() to it
$endgroup$
– pcko1
Feb 16 at 23:58
$begingroup$
@pcko1 Can I write like this:result = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=5, verbose=0)
and thenplot_loss_accuracy(result)
so thatresult
can be used for kfold validation of scikit-learn as well as confusion matrix display of Keras?
$endgroup$
– PS Nayak
Feb 18 at 14:08
add a comment |
$begingroup$
don't call model.fit() as you currently do in your code but instead wrap your model in a KerasClassifier() and apply KFold() to it
$endgroup$
– pcko1
Feb 16 at 23:58
$begingroup$
@pcko1 Can I write like this:result = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=5, verbose=0)
and thenplot_loss_accuracy(result)
so thatresult
can be used for kfold validation of scikit-learn as well as confusion matrix display of Keras?
$endgroup$
– PS Nayak
Feb 18 at 14:08
$begingroup$
don't call model.fit() as you currently do in your code but instead wrap your model in a KerasClassifier() and apply KFold() to it
$endgroup$
– pcko1
Feb 16 at 23:58
$begingroup$
don't call model.fit() as you currently do in your code but instead wrap your model in a KerasClassifier() and apply KFold() to it
$endgroup$
– pcko1
Feb 16 at 23:58
$begingroup$
@pcko1 Can I write like this:
result = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=5, verbose=0)
and then plot_loss_accuracy(result)
so that result
can be used for kfold validation of scikit-learn as well as confusion matrix display of Keras?$endgroup$
– PS Nayak
Feb 18 at 14:08
$begingroup$
@pcko1 Can I write like this:
result = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=5, verbose=0)
and then plot_loss_accuracy(result)
so that result
can be used for kfold validation of scikit-learn as well as confusion matrix display of Keras?$endgroup$
– PS Nayak
Feb 18 at 14:08
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
KFold() is meant for cross-validation purpose where multiple models are created over the subsets of the entire dataset and discarded after the validation procedure is over. So the model.fit() should be called explicitly to create the model for purpose. Both the tasks can be easily done through the wrapper named KerasClassifier() by packaging all the details of the model design.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fdatascience.stackexchange.com%2fquestions%2f45698%2fk-fold-cross-validation-of-scikit-learn-with-confusion-matrix-of-keras%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
$begingroup$
KFold() is meant for cross-validation purpose where multiple models are created over the subsets of the entire dataset and discarded after the validation procedure is over. So the model.fit() should be called explicitly to create the model for purpose. Both the tasks can be easily done through the wrapper named KerasClassifier() by packaging all the details of the model design.
$endgroup$
add a comment |
$begingroup$
KFold() is meant for cross-validation purpose where multiple models are created over the subsets of the entire dataset and discarded after the validation procedure is over. So the model.fit() should be called explicitly to create the model for purpose. Both the tasks can be easily done through the wrapper named KerasClassifier() by packaging all the details of the model design.
$endgroup$
add a comment |
$begingroup$
KFold() is meant for cross-validation purpose where multiple models are created over the subsets of the entire dataset and discarded after the validation procedure is over. So the model.fit() should be called explicitly to create the model for purpose. Both the tasks can be easily done through the wrapper named KerasClassifier() by packaging all the details of the model design.
$endgroup$
KFold() is meant for cross-validation purpose where multiple models are created over the subsets of the entire dataset and discarded after the validation procedure is over. So the model.fit() should be called explicitly to create the model for purpose. Both the tasks can be easily done through the wrapper named KerasClassifier() by packaging all the details of the model design.
answered Feb 22 at 6:24
PS NayakPS Nayak
134
134
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fdatascience.stackexchange.com%2fquestions%2f45698%2fk-fold-cross-validation-of-scikit-learn-with-confusion-matrix-of-keras%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
$begingroup$
don't call model.fit() as you currently do in your code but instead wrap your model in a KerasClassifier() and apply KFold() to it
$endgroup$
– pcko1
Feb 16 at 23:58
$begingroup$
@pcko1 Can I write like this:
result = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=5, verbose=0)
and thenplot_loss_accuracy(result)
so thatresult
can be used for kfold validation of scikit-learn as well as confusion matrix display of Keras?$endgroup$
– PS Nayak
Feb 18 at 14:08