How to load features from a Dictionary in python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to load features from a Dictionary in python?

How to load features from a Dictionary in python?

This recipe helps you load features from a Dictionary in python

0
In [1]:
## How to load features from a Dictionary in python
def Kickstarter_Example_20():
    print()
    print(format('How to load features from a Dictionary in python', '*^72'))

    # Load library
    from sklearn.feature_extraction import DictVectorizer

    # Create A Dictionary
    employee = [{'name': 'Steve Miller', 'age': 33., 'dept': 'Analytics'},
                {'name': 'Lyndon Jones', 'age': 42., 'dept': 'Finance'},
                {'name': 'Baxter Morth', 'age': 37., 'dept': 'Marketing'},
                {'name': 'Mathew Scott', 'age': 32., 'dept': 'Business'}]

    # Convert Dictionary To Feature Matrix
    vec = DictVectorizer()

    # Fit then transform the dictionary with vec, then output an array
    print();
    print("Feature Matrix: "); print(vec.fit_transform(employee).toarray())

    # View Feature Names
    print()
    print("Feature Name: "); print(vec.get_feature_names())

Kickstarter_Example_20()
************How to load features from a Dictionary in python************

Feature Matrix:
[[33.  1.  0.  0.  0.  0.  0.  0.  1.]
 [42.  0.  0.  1.  0.  0.  1.  0.  0.]
 [37.  0.  0.  0.  1.  1.  0.  0.  0.]
 [32.  0.  1.  0.  0.  0.  0.  1.  0.]]

Feature Name:
['age', 'dept=Analytics', 'dept=Business', 'dept=Finance', 'dept=Marketing', 'name=Baxter Morth', 'name=Lyndon Jones', 'name=Mathew Scott', 'name=Steve Miller']

Relevant Projects

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.