Logistic Regression with Tensor Flow
Overview
A
logistic regression
is simply a linear model with the sigmoid function applied to the output. This makes it easy to express in terms of
tensors and fit using tensor-flow
sequential model.
The loss function that is typically used is the binary cross-entropy function, also referred to as the logistic loss function.
It is defined as
{% loss(\hat{y}_i,y_i) = -[y_i log(\hat{y}_i) + (1-y_i)log(1-\hat{y}_i)] %}
where {% y_i %} is the actual value for record i, and {% \hat{y}_i %} is the predicted value.
Implementation
const model= tf.sequential();
model.add(tf.layers.dense({
units:1,
activation:"sigmoid",
inputShape:[2]
}));
const optimizer = tf.train.adam(0.001);
model.compile({
optimizer:optimizer,
loss:tf.losses.logLoss
})
Try it!