Public
Edited
Sep 28, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
Insert cell
Insert cell
// The penguins dataset is automatically available in all Observable notebooks.
penguins
Insert cell
// Observable Plot is part of Observable's Standard Library, so can be automatically called in any Observable notebook
Plot.plot({
marks: [
Plot.dot(penguins, {x: "body_mass_g", y: "flipper_length_mm"})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
penguins.filter(d => isNaN(d.flipper_length_mm) || isNaN(d.body_mass_g))
Insert cell
Insert cell
penguinsComplete = penguins.filter(d => !isNaN(d.flipper_length_mm) && !isNaN(d.body_mass_g))
Insert cell
Insert cell
Insert cell
Insert cell
penguins_lm = new ML.SimpleLinearRegression(penguinsComplete.map(d => d.flipper_length_mm), penguinsComplete.map(d => d.body_mass_g))
Insert cell
Insert cell
Insert cell
penguins_coefficients = penguins_lm.coefficients // [intercept, slope]
Insert cell
Insert cell
penguins_coefficients[0] // Intercept estimate
Insert cell
penguins_coefficients[1] // Slope estimate
Insert cell
Insert cell
Insert cell
penguins_corr = penguins_lm.score(penguinsComplete.map(d => d.flipper_length_mm), penguinsComplete.map(d => d.body_mass_g))
Insert cell
Insert cell
penguins_corr.r // Pearson's r
Insert cell
penguins_corr.r2 // R^2 coefficient of determination
Insert cell
penguins_corr.rmsd // Root-mean-square deviation
Insert cell
Insert cell
Insert cell
Insert cell
penguins_lm.predict(205)
Insert cell
Insert cell
penguins_lm.computeX(5000)
Insert cell
Insert cell
Insert cell
Insert cell
chart = Plot.plot({
marks: [
Plot.dot(penguinsComplete, { // Add scatterplot (blue points)
x: "flipper_length_mm",
y: "body_mass_g",
fill: "blue",
r: 4,
opacity: 0.4
}),
Plot.linearRegressionY(penguinsComplete, { // Adds regression line and confidence interval
x: "flipper_length_mm",
y: "body_mass_g"
}),
Plot.text( // Add text annotation for model estimates (shown in blue)
[`y = ${penguins_coefficients[1].toFixed(1)}x - ${-penguins_coefficients[0].toFixed(1)}
𝘙 ² = ${penguins_corr.r2.toFixed(2)}
𝘳 = ${penguins_corr.r.toFixed(2)}`
],
{frameAnchor: "bottom-right",
dy: -20,
fontSize: 16,
fill: "blue",
fontWeight: 600}
)
]
})
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