Public
Edited
Sep 15, 2023
Insert cell
Insert cell
Insert cell
loc = FileAttachment("data.tsv").tsv()
Insert cell
percents = loc.map((obj) => {
let result = {
date: new Date(obj.date),
cpp: Number(obj["c++"]),
c: Number(obj.c),
rust: Number(obj.rust)
};
let total = result.cpp + result.c + result.rust;
result.percent = (100.0 * result.rust) / total;
return result;
})
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
percents_lm = new ML.SimpleLinearRegression(
percents.map((d) => d.date.getTime()),
percents.map((d) => d.percent)
)
Insert cell
futureDate = (() => {
const futureDate = new Date();
futureDate.setTime(percents_lm.computeX(100));
return futureDate;
})()
Insert cell
percentPlot = Plot.plot({
marks: [
Plot.lineY(percents, { x: "date", y: "percent", tip: true }),
Plot.linearRegressionY(percents, {
x: "date",
y: "percent",
stroke: "red"
})
]
})
Insert cell
percentPlot1 = Plot.plot({
marks: [
Plot.lineY(percents, {
x: "date",
y: "percent",
tip: true
}),
Plot.linearRegressionY(
percents.concat([{ date: futureDate, percent: 100 }]),
{
x: "date",
y: "percent",
stroke: "red"
}
)
]
})
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