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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more