1
$\begingroup$

I am trying some basic machine learning with Mathematica. I am wondering if I can see the function that Mathematica produces for a training set. I give the following example:

trainingset = {1 -> 1.3, 2 -> 2.4, 3 -> 4.4, 4 -> 5.1, 6 -> 7.3}; p = Predict[trainingset, Method -> "LinearRegression"]

If I type p[1.5], it will give me the predicted value. However, could I also see/know somehow the function used, e.g. for this case in the form of y=a*x+b, (where x is the variable)? Is there a way to see the predicted function?

$\endgroup$
1
  • $\begingroup$ Have a look at the result of p[[1]] and you'll see the internals. An important thing to realize is that the resulting linear regression model is fit against the standardized data, not the original data. This is quite common for Mathematica to pre-standardize before learning, and it makes extracting the model a bit awkward because the parameters have to be un-standardized properly. See here for example with SVMs mathematica.stackexchange.com/questions/233099/… $\endgroup$
    – flinty
    Commented Dec 3, 2020 at 17:33

2 Answers 2

4
$\begingroup$

It turns out that PredictorFunctions are implemented in a nice and transparent way as PredictorFunction[ Association[...]]. So execute p[[1]] and everything is laid out nicely for you.

$\endgroup$
2
  • $\begingroup$ Thank you Henrik, this was very helpful! Still though, I don't get how can I see the function. Sorry for my ignorance. $\endgroup$
    – harazogo
    Commented Jun 19, 2018 at 9:22
  • $\begingroup$ Well, the actual predictor consists of one or more neural nets with pre- and postprocessors. Very complicated. You can try to inspect trace = Trace[p[1.5]]; in order to guess what is going on... The working of FindFit or LinearModelFit might be easier to graps. $\endgroup$ Commented Jun 19, 2018 at 11:40
0
$\begingroup$

This PredictorInformation[pd, "FunctionProperties"] should do.

hope it helps ( :

$\endgroup$
0

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.