Python Tutorial: Fit and evaluate a model

preview_player
Показать описание

---
In this lesson, you will take the model you compiled in lesson two and fit it to college basketball data.

Your goal is to predict which team will win a tournament game.

The only data you have to work with are the team's "seeds", which are assigned by the tournament organizers, and are a rating of how good the team is.

A seed of 1 is a very good team, and a seed of 16 is a very bad team.

In the 30 plus year history of the tournament, a 16 seed has beat a 1 seed exactly once. It was in 2018, which was a very exciting year for college basketball fans.

Your input will be the difference in seed between the two teams. For example, if a 7 seed plays a 10 seed, their seed difference is 7 minus 10, or -3.

If an 11 seed plays a 7 seed, their seed difference is 11 minus 7, or 4.

Your output will be the difference in score between the two teams. For example, if team 1 scores 41 points and team 2 scores 50 points, the score difference is 41 minus 50, or negative 9.

On the other hand, if team 1 scores 61 points and team 2 scores 55 points, the score difference is 61 minus 55 or positive 6.

Therefore, your model has one input, and one output. This is exactly the model you created in lessons 1 and 2 of this chapter!

You will use the difference in seeds as your input.

Note that you have both a 16 seed playing a 1 seed, and a 1 seed playing a 16 seed in your data, so you'll have seed differences ranging from negative 15 to positive 15.

A seed difference of positive 15 means that team 1 has a seed of 16 and is playing a team of seed of 1. This means team 1 is likely (though not certain) to lose.

A seed difference of negative 15 means that team 1 has a seed of 1 and is playing a team of seed of 16. This means team 1 is likely (though not certain) to win.

So a positive seed difference is usually predictive of a negative score difference, and a negative seed difference is usually predictive of a positive score difference.

Our target variable is the game's score difference and ranges from about negative 50 to positive 50. This means you have games where team 1 lost by 50 points and games where they won by 50 points.

Note that both the regular season and the tournament datasets have 2 rows per game, where the second row has the opposite signs of the first row.

In other words, for a given game where the first team won, there is also a row in the dataset where team_1 and team_2 are swapped, and the first team lost.

Here is the model from lessons 1 and 2, defined in a single code chunk. This is a very basic keras regression model, with one input and one output. You could use this model for any regression problem with a single predictor and a single outcome.

Use the seed_diff column from the dataset as the input and the score_diff column from the dataset as the output.

The fit method has some additional arguments, which can be useful:

Batch size sets how many rows of data are used for each step of stochastic gradient descent. In this case, you'll train on 64 rows at a time.

Validation split tells Keras to use a holdout set, and return metrics on accuracy using that data. This can be useful for validating that your models will perform well on new data.

When verbose is set to True, Keras prints a log during training. This can be useful for debugging, but usually, I set it to False once I like how the model works.

Once you've fit a model, it is useful to evaluate it on new data. Even if you use a validation set during training, you often want to do a second check, using a new dataset, to make sure the model is predicting as expected.

To do this, you can use the evaluate() method of the model, and pass it the X variables and Y variables from the new data.

When you do this, Keras will report error metrics on the new data.

Time for you to fit the model!

#PythonTutorial #Python #DataCamp #Keras #denselayers
Рекомендации по теме
Комментарии
Автор

When you need agricultural basketball to understand the example...

DJVARAO
Автор

what if there are 3 teams how would we fit that

brendontay