How to impute missing class labels in Python?

How to impute missing class labels in Python?

How to impute missing class labels in Python?

This recipe helps you impute missing class labels in Python

This python source code does the following : 1. Creates a numpy array with missing values 2. Builds up imputer along with parameter for imputing the values 3. Uses imputer "fit_transform" for filling out NaN values
In [2]:
## How to impute missing class labels in Python 
def Kickstarter_Example_27():
    print(format('How to impute missing class labels in Python', '*^82'))
    import warnings

    # Load libraries
    import numpy as np
    from sklearn.preprocessing import Imputer

    # Create Feature Matrix With Missing Values
    X = np.array([[2,       2.10, 1.45],
                  [1,       1.18, 1.33],
                  [2,       1.22, 1.27],
                  [0,       -0.21, -1.19],
                  [np.nan,  0.87, 1.31],
                  [np.nan, -0.67, -0.22]])

    # Create Imputer object
    imputer = Imputer(strategy='most_frequent', axis=0)

    # Fill missing values with most frequent class
    print(); print(X)
    print(); print(imputer.fit_transform(X))

*******************How to impute missing class labels in Python*******************

[[ 2.    2.1   1.45]
 [ 1.    1.18  1.33]
 [ 2.    1.22  1.27]
 [ 0.   -0.21 -1.19]
 [  nan  0.87  1.31]
 [  nan -0.67 -0.22]]

[[ 2.    2.1   1.45]
 [ 1.    1.18  1.33]
 [ 2.    1.22  1.27]
 [ 0.   -0.21 -1.19]
 [ 2.    0.87  1.31]
 [ 2.   -0.67 -0.22]]

Relevant Projects

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

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.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

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.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.