Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add how to save serialized objects to course #17

Open
ttimbers opened this issue Mar 29, 2022 · 0 comments
Open

Add how to save serialized objects to course #17

ttimbers opened this issue Mar 29, 2022 · 0 comments

Comments

@ttimbers
Copy link
Contributor

ttimbers commented Mar 29, 2022

Model objects that are trained/fit in one script, and then need to be used again later in another script can and should be saved as binary files. In R, the format is .RDS and we use the functions saveRDS() and readRDS() to do this. In python, the format is .pickle and we use the functions pickle.dump() and pickle.load() from the pickle package.

example of saveRDS()

saveRDS(final_knn_model, "results/final_knn_model.rds")

example of readRDS()

final_knn_model <- readRDS("results/final_knn_model.rds")

example of pickle.dump()

import pickle
pickle.dump(final_knn_model, open("results/final_knn_model.pickle", "wb"))

example of pickle.load()

import pickle
final_knn_model = pickle.load(open("results/final_knn_model.pickle", "rb"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant