Published
Edited
Aug 16, 2019
Insert cell
Insert cell
Insert cell
Insert cell
treeParams = ({
minPercentVarianceReduction: 0.5,
minLeafNodeItems: 10,
minSplitCandidateItems: 30,
minAvgChildrenItems: 2
});
Insert cell
params=d3.range(1000).map(n => [
Math.floor(Math.random()*80),
Math.random() > 0.5 ? 'M' : 'F',
Math.floor(Math.log(1/Math.random()))
])
Insert cell
method = ([age, gender, appts]) =>
(gender == 'M' ?
(appts == 0 ? 10 : 0) + (age < 5 ? 20 : age > 60 ? 40 : 10) :
(appts == 0 ? 10 : 0) + (age < 10 ? 25 : age > 65 ? 50 : 15)
)// + Math.floor(Math.random()*10-5)
Insert cell
results=params.map(method)
Insert cell
trainingData = params.map((p, i) => ([...p, results[i]]))
Insert cell
columns = [
{ name: 'age', categorical: true, exclude: false},
{ name: 'gender', categorical: true, exclude: false},
{ name: 'appts', categorical: false, exclude: false},
{ name: 'wait_time',categorical: false, target: true}
]
Insert cell
rt={
let rt = regressionTree();
rt.defineConfig(columns, treeParams);
trainingData.forEach(row => rt.ingest(row));
rt.learn();
return rt
}
Insert cell
rt.predict(({
age: 65,
gender: 'F',
appts: 1
}))
Insert cell
JSON.parse(rt.exportJSON())
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