Encoding user_names and storing encoder


In [ ]:
from planet4 import io
db = io.DBManager()
data = db.get_all()

In [ ]:
from sklearn import preprocessing

In [ ]:
le = preprocessing.LabelEncoder()

In [ ]:
le.fit(data.user_name)

In [ ]:
len(le.classes_)

In [ ]:
data.user_name = le.transform(data.user_name)

In [ ]:
le.transform(data.tail().user_name)

In [ ]:
import pickle

In [ ]:
folder = Path('/Users/klay6683/Dropbox/data/planet4/P4_catalog_v1.0')
fname = folder / 'P4_catalog_v1.0_username_encoder.pkl'
with open(fname, 'wb') as f:
    pickle.dump(le, f)

In [ ]:
from planet4 import reduction

In [ ]:
# storing new database
fname = folder / 'P4_catalog_v1.0_raw_classifications.hdf'
data.to_hdf(fname, 'df', format='t', data_columns=reduction.data_columns)

Reversing name encoding


In [ ]:
with open('name_encoder.pkl', 'rb') as f:
    le = pickle.load(f)

In [ ]:
le = pickle.load

In [ ]:
le.inverse_transform(np.array([15, 15, 49, 16, 53]))

Find a certain user


In [ ]:
np.argwhere(le.classes_=='Vincep1')

In [ ]: