I trained a Predict and when I look at PredictorInformation it says evaluation time is less than 1 millisecond per example. However, when I apply my p to a new input example, it takes almost 4 seconds. I want to apply it to almost 10,000 new examples so this is rather slow. Is there a way to apply it faster?


Sharing the code is tricky, but a minimal example is:

DATA = Table[ Table[RandomReal[],{1000}] -> RandomReal[] ,{20000}];


Of course the real data is not random, but it is read in from a file. It is all numbers.

Training is rather fast (10 minutes?) and when I look at the PredictorInformation it says about 1 millisecond per example. However, if I try to apply p to new data is is very slow.


closed as off-topic by Henrik Schumacher, kirma, gwr, rcollyer, eyorble Sep 12 '18 at 21:03

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Would you please share the code you used in copyable form? It is certainly hard to say anything useful without it... $\endgroup$ – Henrik Schumacher Jul 11 '18 at 17:21
  • 1
    $\begingroup$ Hi-- I added some code. the real data is from a csv file but I made some fake data. $\endgroup$ – TeresaBroadwin Jul 11 '18 at 17:39
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because it cannot be answered without additional information and OP has abandoned the post. $\endgroup$ – Henrik Schumacher Sep 9 '18 at 19:08

The PredictorFunction p is treated by Mathematica as a function with attribute Listable. Exploiting this makes it 30 times faster for the presented example:

n = 20000;
m = 1000;
data = RandomReal[{0, 1}, {n, m}] -> RandomReal[{0, 1}, n];
p = Predict[data,
   Method -> {"GradientBoostedTrees", "MaxDepth" -> 8, 
     "L1Regularization" -> 0.001}
   ]; // AbsoluteTiming // First


Now, let's apply the predictor p to 1000 elements.

a = RandomReal[{0, 1}, {1000, m}];
b = p[a]; // RepeatedTiming // First
c = p /@ a; // RepeatedTiming // First
b == c




The result of PredictorInformation[p] states 3.77 ms per evaluation. That's pretty close to the timing of p /@ a. The listable variant needs only 0.11 ms per evaluation.

  • $\begingroup$ Hm-- I tried this with just 5 of my 10,000 examples and it took 16 seconds. I was this is much longer then the milliseconds that the PredictorInformation showed. Also-- sorry, can't upvote! need 15 reputation. $\endgroup$ – TeresaBroadwin Jul 11 '18 at 17:55
  • $\begingroup$ What are the 10000 examples? What does Developer`PackedArrayQ[examles] return? $\endgroup$ – Henrik Schumacher Jul 11 '18 at 18:09
  • $\begingroup$ And how are you running the timing? It might also be a front-end issue and the kernel might still be fast. $\endgroup$ – b3m2a1 Jul 12 '18 at 2:41

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