Code1248
Code1248

Reputation: 11

Tensorflow Keras Sequential Model

I have a data set of temperature change of earth over the year-

2019 1.1
2020 0.45
2017 0.34

The data set looks something like that and I want to create a neural network where we can give the year as input and it will output the temperature. Can anyone help me on how to create a sequential neural network for this?

Upvotes: 1

Views: 708

Answers (1)

Richard X
Richard X

Reputation: 1134

Before building a model, it is important to identify certain features of your problem. First, you should identify the nature of your task. In your case, it is regression. Identifying the task helps you build the structure of your model. Next, you want to identify the features (inputs) and labels (outputs) of your data. Knowing the features helps you determine the shape of the input layer to your model. For your problem, it is simply a year. The shape of your data is likely to be an array in the shape of (num_years,). The same goes for your output which is temperature. Now that you have identified the features and labels, you can easily see what type of model you will need. In your case, it will be a regression model with few parameters. You won't need many parameters for your model as the overall complexity of your problem is not high. Too many parameters can lead to overfitting, where your model begins to start learning the noise in your features. Below is a basic representation of a model suited for your task.

import tensorflow as tf
from tensorflow.keras.models import Sequential
import tensorflow.keras.layers as layers

model = Sequential()
model.add(layers.Dense(16, activation='relu', input_shape=(1,)))
model.add(layers.Dense(1, activation='linear'))

The first layer of the model is a dense layer with 16 units, 'relu' activation, and has an input shape of (1,). The input shape specifies the shape of your features. The 16 units tells the model to output 16 numbers for that layer. The 'relu' activation is the activation function that will recieve the 16 numbers and output values according to f(x)=max(x, 0). Notice that the last layer in this simple network is a dense layer with 1 unit. This tells your model to output one number per input. the activation='linear' tells that dense layer to return the output of that unit according to f(x)=x, which is itself.

Upvotes: 1

Related Questions