2
$\begingroup$

I have 2 sets of data. For example,

a={1,2,3,4,5}
b={5,4,3,2,1}
data= MapThread[List,{a,b}];
p = Predict[Rule @@@ ta12, 
  Method -> {"NearestNeighbors", Range[1,5]}]

I expect to have a set of {1,3},{3,5}.. something like this. Unfortunately, I got an error that the format is incorrect. How Should I fix it? Thank you very much.

$\endgroup$

1 Answer 1

2
$\begingroup$

You've almost got it right...

a = {1, 2, 3, 4, 5};
b = {5, 4, 3, 2, 1};
data = MapThread[List, {a, b}];
p = Predict[Rule @@@ data, Method -> "NearestNeighbors"]

Now you can call the function p, so that p[1] gives 4.5 and p[2] gives 3.5. To get all the values over the range 1 to 5:

p /@ Range[1, 5]

If you want the answer in {x,y} pairs:

Thread[{a, p /@ a}]
$\endgroup$
3
  • $\begingroup$ I still get only one set of numbers not {x, y} like this. Or I miss something here. $\endgroup$ Commented Feb 8, 2023 at 21:54
  • $\begingroup$ You can get {x,y} pairs easily enough as in the update... $\endgroup$
    – bill s
    Commented Feb 9, 2023 at 0:04
  • $\begingroup$ Thank you very much $\endgroup$ Commented Feb 9, 2023 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.