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