How does it work?

This function is by far the COOLEST 😎 function in DisplayJS (but not the most useful. This price 🥇 is given to the $.var() function 😊) because it can predict any point from 2 to 3 points. Let me explain, imagine you have a list of 3 number [3, 7, 11]. From that we are going to generate a list of points, like that:

  • The first point will be [1, 3] because 3 is the first item of our list
  • The second point will be [2, 7] because 7 is the second item of our list
  • The third point will be [3, 11] because 11 is the third item of our list

So, our list will contain each point, like that: [[1,3],[2,7],[3,11]].

Now, using the predict function, we can do 2 things:

  • predict the y value for any x value.
  • Know the affine transformation that will give any number. (optional)

How to use it?

This function will take 3 arguments:

  • array, the array of points. The minimum of points is 2, the third point is optional and is only here to check the model
  • val, this is the x value, and it will return the y value (if the third argument is set to false 😉)
  • text, (true or false, by default its value is false) Do you want to display the function and the result or only the result.

Example

Now, let's predict the fourth value of our initial list.

JS:

//        list of points       fourth number
$.predict([[1,3],[2,7],[3,11]], 4) // 15
//        list of points  fourth number  text will be displayed
$.predict([[1,3],[2,7],[3,11]], 4, true) // f(x) = 4x+-1; f(4) = 15

⚠️ Questions?

Don't hesitate to ask your questions ⁉️ in the issue part 😁

results matching ""

    No results matching ""