Public
Edited
Sep 11, 2020
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof featuresTensor = {
const result = tf.tensor(features);
invalidation.then(() => result.dispose());
return pt(result);
}
Insert cell
viewof levelsTensor = {
const result = tf.tensor(levelIndicators(labels, ['low', 'mid', 'high']));
invalidation.then(() => result.dispose());
return pt(result);
}
Insert cell
Insert cell
model = {
const model = tf.sequential();
model.add(new CoralOrdinal({inputShape: [4], numClasses: 3}));
const optimizer = tf.train.adam(0.5);
model.compile({
optimizer: optimizer,
loss: tf.losses.sigmoidCrossEntropy,
metrics: ordinalMeanAbsoluteError
});
await model.fit(
featuresTensor,
levelsTensor, {
epochs: 5,
});
invalidation.then(() => {
optimizer.dispose();
model.dispose();
});
return model
}
Insert cell
Insert cell
viewof predictions = {
const cumProbs = model.predict(featuresTensor);
const probs = ordinalSoftmax(cumProbs);
cumProbs.dispose();
invalidation.then(() => probs.dispose());
return pt(probs);
}
Insert cell
Insert cell
viewof meanAbsError = {
const result = tf.tidy(() => model.metrics(levelsTensor, model.predict(featuresTensor)));
invalidation.then(() => result.dispose());
return pt(result);
}
Insert cell
Insert cell
Promise.all(model.weights.map(w => w.val.array()))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more