Skip to content

Instantly share code, notes, and snippets.

@trygvea
Created February 26, 2019 19:46
Show Gist options
  • Save trygvea/9b01810bc6abb8c9643289002a52f3b5 to your computer and use it in GitHub Desktop.
Save trygvea/9b01810bc6abb8c9643289002a52f3b5 to your computer and use it in GitHub Desktop.
Machine learning - pedagogical
type Data = number[]
type Observation = number
type Prediction = Observation
function learn(xs: Data[], ys: Observation[]) {
return (x: Data): Prediction => {
// use xs and ys to predict outcome of x
return 1
}
}
const data = [
[1, 2, 3, 4, 5],
[2, 5, 1, 9, 4],
[9, 4, 3, 2, 5],
// ...more
]
const observations = [
5,
6,
9,
// ...more
]
const predict = learn(data, observations)
predict([1, 3, 1, 5, 4]) // => 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment