Machine learning Path: Python dictionary feature extractor Dictvectorizer

Source: Internet
Author: User

Python3 Learning using the API

A sample of a data structure of a dictionary type, extracting features and converting them into vector form

SOURCE Git:https://github.com/linyi0604/machinelearning

Code:

1  fromSklearn.feature_extractionImportDictvectorizer2 3 " "4 dictionary feature Extractor:5 pumping and vectorization of dictionary data Structures6 category type features vectorization with 0 12 values using prototype feature names7 numeric type features remain unchanged8 " "9 Ten #Define a dictionary list to represent multiple data samples Onemeasurements = [ A{" City":"Dubai","Temperature": 33.0}, -{" City":"London","Temperature": 12.0}, -{" City":"San Fransisco","Temperature": 18.0}, the ] -  - #initializing the dictionary feature extractor -VEC =Dictvectorizer () +data =Vec.fit_transform (measurements). ToArray () - #to view extracted feature values + Print(data) A " " at [1.0. 0.] - [0.1. 0.] - [0.0. 1.] - " " - #View the meaning of a post extraction feature - Print(Vec.get_feature_names ()) in " " - [' City=dubai ', ' City=london ', ' City=san fransisco ', ' temperature '] to " "

Machine learning Path: Python dictionary feature extractor Dictvectorizer

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.