I'm new to the Data Science field and last week I started to learn about Neural Networks and Deep Learning. To practice, I decided to do a small project: design a Neural Network to predict the winner of an NBA game given the two teams playing. Also, for each match I have 2 stats (let's say number of points and number of free throws) for each of the teams.

In the end, the dataset looks like:

|  ID |  Home |  Away | H_Pts | H_Fts | A_Pts | A_Fts | H_win |
|  1  | Team1 | Team2 |   45  |   10  |   47  |   8   |   1   |
|  2  | Team3 | Team4 |   56  |   6   |   70  |   13  |   0   |
| ... |  ...  |  ...  |  ...  |  ...  |  ...  |  ...  |  ...  |

I implemented the model with TensorFlow/Keras (with the help of this tutorial: Classify structured data with feature columns | TensorFlow Core).

The code is pretty concise:

batch_size = 16
train_ds, test_ds, val_ds = get_datasets()  # The function mainly uses tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
team_names = get_team_names()

feature_columns = []
for column_name in ['Home', 'Away']:
    team = feature_column.categorical_column_with_vocabulary_list(column_name, team_names)

for column_name in ['H_Pts', 'H_Fls', 'A_Pts', 'A_Fls']:

feature_layer = tf.keras.layers.DenseFeatures(feature_columns)

model = tf.keras.Sequential([
    layers.Dense(128, activation='relu'),
    layers.Dense(128, activation='relu'),

model.compile(optimizer='adam', loss=tf.keras.losses.BinaryCrossentropy(from_logits=True), metrics=['accuracy'])

model.fit(train_ds, validation_data=val_ds, epochs=10)

loss, accuracy = model.evaluate(test_ds)
print(f"Model evaluation: Loss = {loss} | Accuracy = {accuracy}")

Trained with just 100 games, I get a great accuracy: 99%. Of course: as it is, the test dataset given to model.evaluate(test_ds) contains everything except the target label H_win. Because H_win can easily be deduced from H_Pts and A_Pts, I get a high accuracy. But this model can't work because by definition you don't know the number of points of each team before the game...

How should I deal with features like these ones which I do not want to predict (so they're not labels) but that should still be considered during the training? Does this kind of feature have a name?

  • $\begingroup$ Afaik, those auxiliary features are still predictions of your model that you later use to derive the classification label. Why do you say they are not predictions of your model in this case? Am I misunderstanding your question? $\endgroup$ – SpiderRico Mar 22 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.