Digitally encode labels using Sklearn's Labelencoder

Source: Internet
Author: User

 fromSklearn.preprocessingImportLabelencoderdefGen_label_encoder (): Labels= ['BB','CC'] Le=Labelencoder () le.fit (labels)Print 'Le.classes_', Le.classes_ forLabelinchLe.classes_:Printlabel, Le.transform ([Label]) [0] Joblib.dump (LE,'Data/label_encoder.h5')

Description of Labelencoder:

1 classLabelencoder (Baseestimator, transformermixin):2     """Encode labels with value between 0 and n_classes-1.3 4 Read more in The:ref: ' User guide <preprocessing_targets> '.5 6 Attributes7     ----------8 Classes_: Array of shape (N_class,)9 holds the label for each class.Ten  One Examples A     -------- - ' Labelencoder ' can is used to normalize labels. -  the >>> from Sklearn import preprocessing - >>> le = preprocessing. Labelencoder () - >>> Le.fit ([1, 2, 2, 6]) - Labelencoder () + >>> Le.classes_ - Array ([1, 2, 6]) + >>> Le.transform ([1, 1, 2, 6]) #doctest: +ellipsis A Array ([0, 0, 1, 2] ...) at >>> Le.inverse_transform ([0, 0, 1, 2]) - Array ([1, 1, 2, 6]) -  - It can also is used to transform non-numerical labels (as long as they is - hashable and comparable) to numerical labels. -  in >>> le = preprocessing. Labelencoder () - >>> Le.fit (["Paris", "Paris", "Tokyo", "Amsterdam"]) to Labelencoder () + >>> List (le.classes_) - [' Amsterdam ', ' Paris ', ' Tokyo '] the >>> Le.transform (["Tokyo", "Tokyo", "Paris"]) #doctest: +ellipsis * Array ([2, 2, 1] ...) $ >>> List (Le.inverse_transform ([2, 2, 1]))Panax Notoginseng [' Tokyo ', ' Tokyo ', ' Paris '] -  the See also +     -------- A sklearn.preprocessing.OneHotEncoder:encode categorical integer features the using a One-hot aka One-of-k scheme. +     """

Digitally encode labels using Sklearn's Labelencoder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.