persistence

How to save to disk / export a lightgbm LGBMRegressor model trained in python?

How to save to disk / export a lightgbm LGBMRegressor model trained in python? Question: Hi I am unable to find a way to save a lightgbm.LGBMRegressor model to a file for later re-use. Asked By: Utpal Datta || Source Answers: Try: my_model.booster_.save_model(‘mode.txt’) #load from model: bst = lgb.Booster(model_file=’mode.txt’) Note: the API state that bst …

Total answers: 4

How to read/write a matrix from a persistent XML/YAML file in OpenCV 3 with python?

How can I read/write a matrix from a persistent XML/YAML file in OpenCV 3 with Python? Question: I’ve been trying to read and write matrices to persistent file storage (for example, XML) with Anaconda‘s current cv2 (which I believe is actually OpenCV 3.x). I looked at the solutions online for this, and people reference something …

Total answers: 1

How to save Scikit-Learn-Keras Model into a Persistence File (pickle/hd5/json/yaml)

How to save Scikit-Learn-Keras Model into a Persistence File (pickle/hd5/json/yaml) Question: I have the following code, using Keras Scikit-Learn Wrapper: from keras.models import Sequential from sklearn import datasets from keras.layers import Dense from sklearn.model_selection import train_test_split from keras.wrappers.scikit_learn import KerasClassifier from sklearn.model_selection import StratifiedKFold from sklearn.model_selection import cross_val_score from sklearn import preprocessing import pickle import …

Total answers: 5

Persist variable changes between tests in unittest?

Persist variable changes between tests in unittest? Question: How do I persist changes made within the same object inheriting from TestCase in unitttest? from unittest import TestCase, main as unittest_main class TestSimpleFoo(TestCase): foo = ‘bar’ def setUp(self): pass def test_a(self): self.assertEqual(self.foo, ‘bar’) self.foo = ‘can’ def test_f(self): self.assertEqual(self.foo, ‘can’) if __name__ == ‘__main__’: unittest_main() I.e.: …

Total answers: 3

With Python, can I keep a persistent dictionary and modify it?

With Python, can I keep a persistent dictionary and modify it? Question: So, I want to store a dictionary in a persistent file. Is there a way to use regular dictionary methods to add, print, or delete entries from the dictionary in that file? It seems that I would be able to use cPickle to …

Total answers: 9

Easiest way to persist a data structure to a file in python?

Easiest way to persist a data structure to a file in python? Question: Let’s say I have something like this: d = { “abc” : [1, 2, 3], “qwerty” : [4,5,6] } What’s the easiest way to progammatically get that into a file that I can load from python later? Can I somehow save it …

Total answers: 7

Why can't environmental variables set in python persist?

Why can't environmental variables set in python persist? Question: I was hoping to write a python script to create some appropriate environmental variables by running the script in whatever directory I’ll be executing some simulation code, and I’ve read that I can’t write a script to make these env vars persist in the mac os …

Total answers: 8

How to store a dictionary on a Django Model?

How to store a dictionary on a Django Model? Question: I need to store some data in a Django model. These data are not equal to all instances of the model. At first I thought about subclassing the model, but I’m trying to keep the application flexible. If I use subclasses, I’ll need to create …

Total answers: 14