from sklearn.preprocessing import LabelEncoder import pickle # Sample data categories = ['PAYMENT', 'TRANSFER', 'CASH_OUT', 'DEBIT', 'CASH_IN', 'Yes', 'No'] # Initialize and fit the LabelEncoder le = LabelEncoder() le.fit(categories) # Save the fitted LabelEncoder to a pickle file with open('label_encoder.pkl', 'wb') as f: pickle.dump(le, f)