How to create Regression Model in TensorFlow

This article explains how to create Regression Model in TensorFlow using tf.keras.Sequential.

Import required libraries

import pandas as pd
import numpy as np

import tensorflow as tf
from tensorflow.keras import layers

Download abalone dataset into Pandas DataFrame

abalone_train = pd.read_csv(
    names=["Length", "Diameter", "Height", "Whole weight", "Shucked weight",
           "Viscera weight", "Shell weight", "Age"])

Separate Features and Labels for training

abalone_features = abalone_train.copy()
abalone_labels = abalone_features.pop('Age')

Create Feature array with numpy

abalone_features = np.array(abalone_features)

Create a Regression model to predict the age

abalone_model = tf.keras.Sequential([

abalone_model.compile(loss = tf.losses.MeanSquaredError(),
                      optimizer = tf.optimizers.Adam())

Train the regression model, abalone_labels, epochs=10)

Categories: TensorFlow