text
stringlengths
0
4.99k
641/641 [==============================] - 13s 19ms/step - loss: 211.9185 - accuracy: 0.9533 - val_loss: 208.2112 - val_accuracy: 0.9540
Epoch 16/20
641/641 [==============================] - 13s 19ms/step - loss: 207.7694 - accuracy: 0.9544 - val_loss: 207.3279 - val_accuracy: 0.9547
Epoch 17/20
641/641 [==============================] - 13s 19ms/step - loss: 208.6964 - accuracy: 0.9540 - val_loss: 204.3082 - val_accuracy: 0.9553
Epoch 18/20
641/641 [==============================] - 13s 19ms/step - loss: 207.2199 - accuracy: 0.9547 - val_loss: 206.4799 - val_accuracy: 0.9549
Epoch 19/20
641/641 [==============================] - 13s 19ms/step - loss: 206.7960 - accuracy: 0.9548 - val_loss: 206.0898 - val_accuracy: 0.9555
Epoch 20/20
641/641 [==============================] - 13s 20ms/step - loss: 206.2721 - accuracy: 0.9547 - val_loss: 206.6541 - val_accuracy: 0.9549
Model training finished.
Evaluating model performance...
377/377 [==============================] - 5s 11ms/step - loss: 206.3511 - accuracy: 0.9541
Test accuracy: 95.41%
You should achieve more than 95% accuracy on the test set.
To increase the learning capacity of the model, you can try increasing the encoding_size value, or stacking multiple GRN layers on top of the VSN layer. This may require to also increase the dropout_rate value to avoid overfitting.
How to train differentiable decision trees for end-to-end learning in deep neural networks.
Introduction
This example provides an implementation of the Deep Neural Decision Forest model introduced by P. Kontschieder et al. for structured data classification. It demonstrates how to build a stochastic and differentiable decision tree model, train it end-to-end, and unify decision trees with deep representation learning.
The dataset
This example uses the United States Census Income Dataset provided by the UC Irvine Machine Learning Repository. The task is binary classification to predict whether a person is likely to be making over USD 50,000 a year.
The dataset includes 48,842 instances with 14 input features (such as age, work class, education, occupation, and so on): 5 numerical features and 9 categorical features.
Setup
import tensorflow as tf
import numpy as np
import pandas as pd
from tensorflow import keras
from tensorflow.keras import layers
import math
Prepare the data
CSV_HEADER = [
\"age\",
\"workclass\",
\"fnlwgt\",
\"education\",
\"education_num\",
\"marital_status\",
\"occupation\",
\"relationship\",
\"race\",
\"gender\",
\"capital_gain\",
\"capital_loss\",
\"hours_per_week\",
\"native_country\",
\"income_bracket\",
]
train_data_url = (
\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\"
)
train_data = pd.read_csv(train_data_url, header=None, names=CSV_HEADER)
test_data_url = (
\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test\"
)
test_data = pd.read_csv(test_data_url, header=None, names=CSV_HEADER)
print(f\"Train dataset shape: {train_data.shape}\")
print(f\"Test dataset shape: {test_data.shape}\")
Train dataset shape: (32561, 15)
Test dataset shape: (16282, 15)
Remove the first record (because it is not a valid data example) and a trailing 'dot' in the class labels.
test_data = test_data[1:]
test_data.income_bracket = test_data.income_bracket.apply(
lambda value: value.replace(\".\", \"\")
)
We store the training and test data splits locally as CSV files.
train_data_file = \"train_data.csv\"
test_data_file = \"test_data.csv\"
train_data.to_csv(train_data_file, index=False, header=False)
test_data.to_csv(test_data_file, index=False, header=False)
Define dataset metadata
Here, we define the metadata of the dataset that will be useful for reading and parsing and encoding input features.
# A list of the numerical feature names.
NUMERIC_FEATURE_NAMES = [
\"age\",
\"education_num\",
\"capital_gain\",
\"capital_loss\",
\"hours_per_week\",
]
# A dictionary of the categorical features and their vocabulary.
CATEGORICAL_FEATURES_WITH_VOCABULARY = {
\"workclass\": sorted(list(train_data[\"workclass\"].unique())),
\"education\": sorted(list(train_data[\"education\"].unique())),
\"marital_status\": sorted(list(train_data[\"marital_status\"].unique())),
\"occupation\": sorted(list(train_data[\"occupation\"].unique())),
\"relationship\": sorted(list(train_data[\"relationship\"].unique())),