Python Tutorial: Keras input and dense layers

///Python Tutorial: Keras input and dense layers

Python Tutorial: Keras input and dense layers

FavoriteLoadingAdd to favorites

Want to learn more? Take the full course at at your own pace. More than a video, you’ll learn hands-on coding & quickly apply skills to your daily work.

Hi! I’m Zach Deane-Mayer, and in this course, I’ll be teaching you advanced deep learning concepts using the keras functional API.

You will learn how to build functional keras models, including advanced topics such as shared layers, categorical embeddings, multiple inputs, and multiple outputs.

The keras functional API is extremely simple, yet immensely powerful.

By the end of this class, you will build a model that is capable of solving a regression and a classification problem at the same time.

Chapter 1 is a refresher on building simple models, where you will learn to use the keras functional API.

In chapter 2, you will build a keras model with 2 inputs.

In chapter 3, you will learn how to generalize your 2-input model to 3 or more inputs.

And finally, in chapter 4, you will build models with multiple outputs that can solve multiple problems.

You will be using two datasets of college basketball games from American colleges. The first dataset is from the regular season and has the following data: the IDs of the 2 teams that played, whether the first team was home or away, whether the first team won or lost the game, and by how many points the first team won or lost.

For the tournament dataset, you also have the tournament “seed”, which is a pre-tournament ranking for each team. These seeds range from 1 to 16, where the best 4 teams get a seed of 1, and the worst 4 teams get a seed of 16.

You will use the difference in the two team’s seeds as an input to your model.

Here are the first five rows of both the datasets.

You can see that the team variables are encoded as integers, and the tournament dataset has one additional column: the difference between the tournament seeds for both teams.

Other than the seed difference, the two datasets have identical columns.

Within a given year, a team’s roster stays relatively constant, but between years it can change a lot, as seniors graduate, and freshmen start. Therefore, for every year, each school is given a unique integer ID.

Keras models at their simplest, are fundamentally composed of 2 parts: an input layer and an output layer.

To start, I’ll define a very simple keras model, which only expects a single input.

I specify this using the Input() function from the keras.layers module.

The number of columns in the input is specified using the shape parameter. This tells the model how much data to expect. Note that the shape argument expects a tuple.

The Input function returns a “tensor.”

If you print this tensor, you’ll see that it is a tf.Tensor object, which indicates it is ready to be used by our model as input.

Now that we’ve defined our input layer, let’s define the output layer.

Outputs in keras are most commonly a single dense layer, which specifies the shape of the expected output.

In this case, we are expecting our model to predict a single value, so we pass one unit to the dense layer.

If you print the output layer, the result is NOT a tensorflow tensor. It is a function, which takes a tensor as input and produces a tensor as output.

The difference between layers and tensors is key to understanding the keras functional API.

Layers are used to construct a deep learning model, and tensors are used to define the data flow through the model.

In this case, the input layer defines a tensor, which we pass to the output_layer() function.

The final output of our model is a tensor. It’s time for you to build some layers!

#PythonTutorial #Python #DataCamp #Keras #denselayers


By |2020-11-24T10:50:18+00:00November 24th, 2020|Python Video Tutorials|1 Comment

One Comment

  1. Gabriel tonini November 24, 2020 at 10:50 am - Reply

    I open my eyes

    I try to see but I'm blinded by the white light

    I can't remember how

    I can't remember why

    I'm lying here tonight

    And I can't stand the pain

    And I can't make it go away

    No I can't stand the pain

    How could this happen to me

    I've made my mistakes

    Got nowhere to run

    The night goes on

    As I'm fading away

    I'm sick of this life

    I just wanna scream

    How could this happen to me

    Everybody's screaming

    I try to make a sound but no one hears me

    I'm slipping off the edge

    I'm hanging by a thread

    I wanna start this over again

    So I try to hold onto a time when nothing mattered

    And I can't explain what happened

    And I can't erase the things that I've done

    No I can't

    How could this happen to…

Leave A Comment