How to load features from a Dictionary in python?

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

In [1]:
## How to load features from a Dictionary in python
def Kickstarter_Example_20():
    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("Feature Matrix: "); print(vec.fit_transform(employee).toarray())

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

************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

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

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Data Science Project-All State Insurance Claims Severity Prediction
Data science project in R to develop automated methods for predicting the cost and severity of insurance claims.

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.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

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.