python - LabelEncoder: How to keep a dictionary that shows ...
stackoverflow.com › questions › 34628423Jan 06, 2016 · le = preprocessing.LabelEncoder () ids = le.fit_transform (labels) mapping = dict (zip (le.classes_, range (len (le.classes_)))) to test: all ( [mapping [x] for x in le.inverse_transform (ids)] == ids) should return True. This works because fit_transform uses numpy.unique to simultaneously calculate the label encoding and the classes_ attribute: def fit_transform (self, y): self.classes_, y = np.unique (y, return_inverse=True) return y.
How to encode python dictionary? - Stack Overflow
stackoverflow.com › questions › 24508726Jul 01, 2014 · This is another way to encode python dictionary in Python. I tested in Python 36 import base64 my_dict = {'name': 'Rajiv Sharma', 'designation': "Technology Supervisor"} encoded_dict = str(my_dict).encode('utf-8') base64_dict = base64.b64encode(encoded_dict) print(base64_dict) my_dict_again = eval(base64.b64decode(base64_dict)) print(my_dict_again)