What is feature column data format in tensorflow

This recipe explains what is feature column data format in tensorflow

Recipe Objective

What is feature_column data format?

Feature columns these are nothing but the bridge between the raw data and the model or estimator. These are very rich, enabling us for transforming and diversify the range of raw data into the formats that the models or estimators can use, allowing easy experimentation.

Complete Guide to Tensorflow for Deep Learning with Python for Free

Step 1 - Import libraries

import tensorflow as tf import numpy as np import pandas as pd from tensorflow import feature_column from tensorflow.keras import layers

Step 2 - Take a sample data

sample_data = {'Student_marks': [55,21,63,88,74,54,95,41,84,52], 'Student_grade': ['average','poor','average','good','good','average','good','average','good','average'], 'Final_point': ['c','f','c+','b+','b','c','a','d+','b+','c']}

Step 3 - Convert Sample data into dataframe

dataframe = pd.DataFrame(sample_data) dataframe

Step 4 - Define feature columns

def My_feature(feature_column): layer_feature = layers.DenseFeatures(feature_column) print(layer_feature(sample_data).numpy())

Step 5 - Numeric Column

Student_marks = feature_column.numeric_column("Student_marks") My_feature(Student_marks)

[[55.]
 [21.]
 [63.]
 [88.]
 [74.]
 [54.]
 [95.]
 [41.]
 [84.]
 [52.]]

Here we have represented the real value features by using Numeric column, It is the simplest type of column. Our model will recieve the column value from the dataframe unchanged.

Step 5 - Bucketized Column

Student_marks_bucket = feature_column.bucketized_column(Student_marks, boundaries=[30,40,50,60,70,80,90]) My_feature(Student_marks_bucket)

[[0. 0. 0. 1. 0. 0. 0. 0.]
 [1. 0. 0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 1. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 1. 0.]
 [0. 0. 0. 0. 0. 1. 0. 0.]
 [0. 0. 0. 1. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 1.]
 [0. 0. 1. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 1. 0.]
 [0. 0. 0. 1. 0. 0. 0. 0.]]

Here we have tried the feature with the bucketed column, in which the data is being split into several buckets by using this bucketed column. The buckets exclude the right boundary and include the left boundary.

{"mode":"full","isActive":false}

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python