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.

  • 1
    Would you please share the code you used in copyable form? It is certainly hard to say anything useful without it... – Henrik Schumacher Jul 11 at 17:21
  • 1
    Hi-- I added some code. the real data is from a csv file but I made some fake data. – TeresaBroadwin Jul 11 at 17:39

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.

  • 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. – TeresaBroadwin Jul 11 at 17:55
  • What are the 10000 examples? What does Developer`PackedArrayQ[examles] return? – Henrik Schumacher Jul 11 at 18:09
  • And how are you running the timing? It might also be a front-end issue and the kernel might still be fast. – b3m2a1 Jul 12 at 2:41

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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