How to save a modal and load again to use?












0















I have no more knowledge of python. This is my ANN modal code in python. This code contains to predict customers situation in binary output. Which is customers leave or not.



Code:



import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Churn_Modelling.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# Part 2 - Now let's make the ANN!

# Importing the Keras libraries and packages
import keras
from keras.models import Sequential
from keras.layers import Dense

# Initialising the ANN
classifier = Sequential()

# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))

# Adding the second hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))

# Adding the output layer
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))

# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)

# Part 3 - Making predictions and evaluating the model

# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)


I want to know how to save this modal as h5 using keras. After I saved it how to load again in another project to predict the data.










share|improve this question

























  • "m5" or ".h5"? if it's the latter, these links may help - machinelearningmastery.com/save-load-keras-deep-learning-models and jovianlin.io/saving-loading-keras-models

    – gireesh4manu
    Jan 19 at 6:25











  • This link on SO gives a more detailed explanation for the question in picture - stackoverflow.com/questions/47266383/…

    – gireesh4manu
    Jan 19 at 6:26











  • try pickle module in python..

    – Ashu Grover
    Jan 19 at 6:31











  • why pickle is good?

    – Ind
    Jan 19 at 6:36











  • Possible duplicate of How to save final model using keras?

    – sdcbr
    Jan 19 at 10:33
















0















I have no more knowledge of python. This is my ANN modal code in python. This code contains to predict customers situation in binary output. Which is customers leave or not.



Code:



import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Churn_Modelling.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# Part 2 - Now let's make the ANN!

# Importing the Keras libraries and packages
import keras
from keras.models import Sequential
from keras.layers import Dense

# Initialising the ANN
classifier = Sequential()

# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))

# Adding the second hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))

# Adding the output layer
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))

# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)

# Part 3 - Making predictions and evaluating the model

# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)


I want to know how to save this modal as h5 using keras. After I saved it how to load again in another project to predict the data.










share|improve this question

























  • "m5" or ".h5"? if it's the latter, these links may help - machinelearningmastery.com/save-load-keras-deep-learning-models and jovianlin.io/saving-loading-keras-models

    – gireesh4manu
    Jan 19 at 6:25











  • This link on SO gives a more detailed explanation for the question in picture - stackoverflow.com/questions/47266383/…

    – gireesh4manu
    Jan 19 at 6:26











  • try pickle module in python..

    – Ashu Grover
    Jan 19 at 6:31











  • why pickle is good?

    – Ind
    Jan 19 at 6:36











  • Possible duplicate of How to save final model using keras?

    – sdcbr
    Jan 19 at 10:33














0












0








0








I have no more knowledge of python. This is my ANN modal code in python. This code contains to predict customers situation in binary output. Which is customers leave or not.



Code:



import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Churn_Modelling.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# Part 2 - Now let's make the ANN!

# Importing the Keras libraries and packages
import keras
from keras.models import Sequential
from keras.layers import Dense

# Initialising the ANN
classifier = Sequential()

# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))

# Adding the second hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))

# Adding the output layer
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))

# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)

# Part 3 - Making predictions and evaluating the model

# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)


I want to know how to save this modal as h5 using keras. After I saved it how to load again in another project to predict the data.










share|improve this question
















I have no more knowledge of python. This is my ANN modal code in python. This code contains to predict customers situation in binary output. Which is customers leave or not.



Code:



import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Churn_Modelling.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# Part 2 - Now let's make the ANN!

# Importing the Keras libraries and packages
import keras
from keras.models import Sequential
from keras.layers import Dense

# Initialising the ANN
classifier = Sequential()

# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))

# Adding the second hidden layer
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))

# Adding the output layer
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))

# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)

# Part 3 - Making predictions and evaluating the model

# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)


I want to know how to save this modal as h5 using keras. After I saved it how to load again in another project to predict the data.







python keras






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 6:27







Ind

















asked Jan 19 at 6:22









IndInd

306




306













  • "m5" or ".h5"? if it's the latter, these links may help - machinelearningmastery.com/save-load-keras-deep-learning-models and jovianlin.io/saving-loading-keras-models

    – gireesh4manu
    Jan 19 at 6:25











  • This link on SO gives a more detailed explanation for the question in picture - stackoverflow.com/questions/47266383/…

    – gireesh4manu
    Jan 19 at 6:26











  • try pickle module in python..

    – Ashu Grover
    Jan 19 at 6:31











  • why pickle is good?

    – Ind
    Jan 19 at 6:36











  • Possible duplicate of How to save final model using keras?

    – sdcbr
    Jan 19 at 10:33



















  • "m5" or ".h5"? if it's the latter, these links may help - machinelearningmastery.com/save-load-keras-deep-learning-models and jovianlin.io/saving-loading-keras-models

    – gireesh4manu
    Jan 19 at 6:25











  • This link on SO gives a more detailed explanation for the question in picture - stackoverflow.com/questions/47266383/…

    – gireesh4manu
    Jan 19 at 6:26











  • try pickle module in python..

    – Ashu Grover
    Jan 19 at 6:31











  • why pickle is good?

    – Ind
    Jan 19 at 6:36











  • Possible duplicate of How to save final model using keras?

    – sdcbr
    Jan 19 at 10:33

















"m5" or ".h5"? if it's the latter, these links may help - machinelearningmastery.com/save-load-keras-deep-learning-models and jovianlin.io/saving-loading-keras-models

– gireesh4manu
Jan 19 at 6:25





"m5" or ".h5"? if it's the latter, these links may help - machinelearningmastery.com/save-load-keras-deep-learning-models and jovianlin.io/saving-loading-keras-models

– gireesh4manu
Jan 19 at 6:25













This link on SO gives a more detailed explanation for the question in picture - stackoverflow.com/questions/47266383/…

– gireesh4manu
Jan 19 at 6:26





This link on SO gives a more detailed explanation for the question in picture - stackoverflow.com/questions/47266383/…

– gireesh4manu
Jan 19 at 6:26













try pickle module in python..

– Ashu Grover
Jan 19 at 6:31





try pickle module in python..

– Ashu Grover
Jan 19 at 6:31













why pickle is good?

– Ind
Jan 19 at 6:36





why pickle is good?

– Ind
Jan 19 at 6:36













Possible duplicate of How to save final model using keras?

– sdcbr
Jan 19 at 10:33





Possible duplicate of How to save final model using keras?

– sdcbr
Jan 19 at 10:33












1 Answer
1






active

oldest

votes


















3














Inorder to save the model, You can do the one below:



from keras.models import load_model
model.save('model_file.h5')


And to load the model back use:



my_model = load_model('model_file.h5')





share|improve this answer
























  • Where the model word come from?

    – Ind
    Jan 19 at 10:35











  • The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

    – RAM SHANKER G
    Jan 19 at 10:49













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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264617%2fhow-to-save-a-modal-and-load-again-to-use%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









3














Inorder to save the model, You can do the one below:



from keras.models import load_model
model.save('model_file.h5')


And to load the model back use:



my_model = load_model('model_file.h5')





share|improve this answer
























  • Where the model word come from?

    – Ind
    Jan 19 at 10:35











  • The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

    – RAM SHANKER G
    Jan 19 at 10:49


















3














Inorder to save the model, You can do the one below:



from keras.models import load_model
model.save('model_file.h5')


And to load the model back use:



my_model = load_model('model_file.h5')





share|improve this answer
























  • Where the model word come from?

    – Ind
    Jan 19 at 10:35











  • The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

    – RAM SHANKER G
    Jan 19 at 10:49
















3












3








3







Inorder to save the model, You can do the one below:



from keras.models import load_model
model.save('model_file.h5')


And to load the model back use:



my_model = load_model('model_file.h5')





share|improve this answer













Inorder to save the model, You can do the one below:



from keras.models import load_model
model.save('model_file.h5')


And to load the model back use:



my_model = load_model('model_file.h5')






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 19 at 6:46









RAM SHANKER GRAM SHANKER G

77110




77110













  • Where the model word come from?

    – Ind
    Jan 19 at 10:35











  • The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

    – RAM SHANKER G
    Jan 19 at 10:49





















  • Where the model word come from?

    – Ind
    Jan 19 at 10:35











  • The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

    – RAM SHANKER G
    Jan 19 at 10:49



















Where the model word come from?

– Ind
Jan 19 at 10:35





Where the model word come from?

– Ind
Jan 19 at 10:35













The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

– RAM SHANKER G
Jan 19 at 10:49







The model is the one you created.For example model = KerasClassifier(build_fn=baseline_model, epochs=200, batch_size=50, verbose=0)

– RAM SHANKER G
Jan 19 at 10:49




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264617%2fhow-to-save-a-modal-and-load-again-to-use%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre