Lesson 1.4Code~50 min
Objects & classes
Bundle data with behaviour. You’ll use this to build your own neural-network engine.
Module 1 · 0/8 done
Bundling values together
An object groups related values under one name, each with its own label (called a property). A house has a size, a number of rooms and a price — so make it one thing: { size: 120, rooms: 3, price: 250000 }, and read a property with a dot: house.price.
// An object bundles named values together.
const house = { size: 120, rooms: 3, price: 250000 }
console.log(house.size, house.price)
// Datasets are usually arrays of objects:
const houses = [
{ size: 60, price: 140000 },
{ size: 95, price: 205000 },
{ size: 120, price: 250000 },
{ size: 150, price: 330000 },
]
plot.scatter(houses.map(h => [h.size, h.price]), { title: "size vs price", xLabel: "m²", yLabel: "price" })
Press Run (⌘/Ctrl + Enter) to see output here.
That’s what a dataset really is: a list of objects, each one an example. Those four dots are the kind of data you’ll fit your first model to in Module 6.