Predicting The Lottery With MATLAB® Neural Network

Posted on Updated on

DISCLAMER: This post does not in any way prove or disprove the validity of using neural networks to predict the lottery. It is purely for the purpose of demonstrating certain capabilities available in MATLAB ® . The results and conclusions are my opinion and may or may not constitute applicable techniques of predicting the popular Jamaican Lottery Cash Pot game.


Supreme Ventures Jamaica Limited has a lottery game called Cash Pot (CP) . The game is based on 36 balls being loaded into a chamber and one ball been selected at random from the grouping. The game is ran four (4) times each day seven (7) days per week.

Anecdotal Heuristics:

While doing a little tongue and cheek research at my favorite barbershop, I stumbled upon some heuristics that are employed by most patrons who play the (CP) game. One involved writing down the day, time, and winning number for each day’s lottery. After building up a sufficient dataset, they could then query a particular day and time; and with some simple arithmetic tally the most likely number to be played on that day and time. I was informed that this proved to be a very efficient way of telling which number was to be played next. Another popular heuristic involved pre-assigned symbols; these symbols were associated with each of the thirty six (36) numbers. Then based on dreams aka “rakes” numbers would be chosen that matched the symbols seen in the “rake”. These two methods were the favorite amongst the players of Cash Pot.

Procedure for predicting Cash Pot with MATLAB ANN:

  1. Get the dataset from Supreme Ventures Jamaica website. [contains all winning numbers with date and time]
  2. We will need to do some twiddling with the file in order to get it into a format that MATLAB can use. To do that we need to remove all headings/sub-headings and labels.
  3. Next remove the DRAW# and MARK columns since we will not be using those in our analysis.
  4. In column D use the =WEEKDAY() formula to get the day number from the corresponding date: repeat for all rows.
  5. Use find and replace to replace MORNING with 1, MIDDAY with 2, DRIVETIME with 3 and EVENING with 4. [Save the file]
  6. Using MATLAB folder explorer, navigate to the file then double click on it to run the import tool.
  7. Select columns B and D then hit the import button; this should import only columns B and D, rename the imported matrix to cpInputs .
  8. Select column C and hit the import button; this should import column C only, rename the imported matrix to  cpTargets.
  9. Because MATLAB sees Neural Network(NN) features as rows, transpose the two matrices using
  10. cpInputs = cpInputs’;
    cpTargets = cpTargets’;
  11. In the MATLAB command window type nntool.
  12. Import cpInputs and cpTargets into the NN data manager.
  13. Hit the new button on the Neural Network Data Manager and change the default name to cpNN.
  14. Set Input data to cpInputs, Target data to cpTargets.
  15. Hit the create button to create the NN.


    The newly created NN has two inputs, the first been the day of the week on which the [CP] is scheduled to be played and the second input the time of day that the [CP] is scheduled to played. It also has a hidden layer with 10 neurons with associated bias, and an output layer with 1 neuron and its associated bias. The output is a scalar double which represents the predicted winning number.

  17. Let’s go ahead and train this network. On the train tab of the Network: cpNN dialog, select cpInputs for Inputs and cpTargets for Targets; then press the Train Network button to start the network training.
  18. Results of training.
  19. After training the network to the desired tolerance’s go back to the Neural Network/Data Manager dialog box and hit the export button, select cpNN from the list then hit the export button.
  20. Go back to the MATLAB command window and type
  21. CpNN([2;3]) % [day;time]
  22. The resulting value will be the NN’s best guess of what will be the winning entry for Cash Pot on a Tuesday at DRIVETIME.


My initial analysis of the results of the NN was not conclusive, maybe the parameters of the NN could be adjusted and the results compared to actual winning numbers. However, even after doing so one may find that the outputs are still random and contain no discernible patterns, which should be the case for a supposedly random game of chance.

56 thoughts on “Predicting The Lottery With MATLAB® Neural Network

    Donperry (@Donperry) said:
    January 16, 2012 at 11:42 am

    So…what numbers playing today?

      Romaine Carter said:
      January 16, 2012 at 11:44 am

      Purely for research purposes!!

        Starry said:
        August 20, 2012 at 10:32 am

        DWL on my !! Don Perry You got jokes

        Romaine Carter said:
        August 25, 2012 at 9:05 am

        No harm in trying🙂

    ganesh said:
    August 26, 2012 at 1:53 pm

    hai sir i will give 1 input and 8 outputs,how will get the output,pls mention the command for that?

      Romaine Carter said:
      August 26, 2012 at 8:45 pm

      Hey ganesh, as the post explains the tool box sees NN features as rows; that means the cpInputs vector has two rows which corresponds to two inputs while cpTargets has only one row which corresponds to one output. Your input vector should have one row while your output vector should have 8 rows, hope that clears it up for you.

        ganesh said:
        August 30, 2012 at 1:45 pm

        first i was salute ur response sir, my doubts,i was try in same procedures ,but in last step i had some errors,how i will get desired output,pls clear my doubt

        Romaine Carter said:
        August 30, 2012 at 4:25 pm

        What were the errors that you got on your attempt, a description of you problem may help.

    ganesh said:
    September 1, 2012 at 7:35 am

    this is my desired predictive value for my datas nns([1;99.63]),having the 2 input values&8 output values ,
    this is i was finally got the error output in command window .

    ??? Error using ==> network.subsref at 83
    Subscript indices must either be real positive integers or logicals.

    pls tell solution for my problem………..

      Romaine Carter said:
      September 1, 2012 at 8:05 am

      MATLAB does not allow indexing with numbers that are not real positive integers 1, 2, 3…n or logicals 0, 1. One of your inputs has a decimal => 99.63. Try to map the decimal inputs to some real’s instead for example i mapped the day names monday, tuesday… to integers 1, 2,…

        john said:
        April 5, 2013 at 4:57 am

        my data were integers, and I had the same reference

    Pugazhenthi said:
    September 1, 2012 at 11:16 am

    sir, i have tried the same example, what you had posted here. . . but i dnt know how to import the data in excel as you had did here. i am using matlab r2008b, i dnt know how to import single column as you did. please help me sir. many thanks

      Romaine Carter said:
      September 12, 2012 at 11:45 pm

      First open the excel file using File -> Import Data, then select the desired column[s] and press the Import Button.

    ganesh said:
    September 1, 2012 at 2:14 pm

    i was made changes,but i was not get the output,pls give some ideas……

    ganesh said:
    September 7, 2012 at 11:18 pm

    hai sir ,this my program,from this program ,how i will get the desired predicted output ? pls help me sir………………………….

    % Target Vector
    T = [3 9 12 4 10 13 5];

    % Input Vector
    delaymat = toeplitz([3 0],T);
    P = delaymat(2,:);

    % Number of hidden neurons
    S1 = 20;

    % Create Network
    net = newelm(P,T,S1);

    % Train Network
    Pseq = con2seq(P);
    Tseq = con2seq(T);
    net = train(net,Pseq,Tseq);

    % Test the network
    Y = sim(net,Pseq);
    z = seq2con(Y);
    diff1 = T – z{1,1};

      Romaine Carter said:
      September 11, 2012 at 4:58 pm

      I looked at your code and noticed that your are using two vectors, one for input and the other for target, this is why you have a neural net with one input and one output.
      example vector = [2,3,4,5]

      However you should be using a vector for input and a matrix for target
      example vector = [2,3,4,5]
      matrix = [3,4,5,6;9,5,7,8]

      This will create a NN with 1 input and 2 outputs, it follows that a target matrix with n rows would create a NN with n outputs. Hope I have cleared things up for you.

    Nirmal Tanwar said:
    February 18, 2013 at 11:58 pm

    if i want to get dataset in code then how i write my code

      Romaine Carter responded:
      February 19, 2013 at 11:21 am

      Hi Nirmal, could you be more specific with your question?

    ganesh said:
    March 16, 2013 at 2:08 pm

    can u tell me sir,what is the acceptable error in neural network?

      Romaine Carter responded:
      March 17, 2013 at 5:36 am

      It depends on the level of accuracy that you require from the network, remember also that the error values may depend on the algo which is used to train the nn.

    Vladimir said:
    March 31, 2013 at 12:36 pm

    I did everything that you said, but at the end I got this error when I tried to predict. I typed in command window this
    CpNN([2;3]) and got this
    ??? Error using ==> network.subsref at 83
    Index exceeds matrix dimensions

    Please help
    Thanks in advance

      Romaine Carter responded:
      March 31, 2013 at 6:22 pm

      Vladimir you may have missed step 9.

    john said:
    April 4, 2013 at 6:33 am

    ??? Error using ==> network.subsref at 83 / the same problem

    Romaine Carter responded:
    April 4, 2013 at 9:58 am

    Hi John and Vladimir, which version of MATLAB are you guys using?

      john said:
      April 4, 2013 at 12:06 pm


        Romaine Carter responded:
        April 5, 2013 at 6:55 am

        Please try with 2011b, some things may work differently for 2009b

    nav said:
    April 4, 2013 at 2:15 pm

    is there any testing data available as I have reviewed all the previous entries for training…

        kadian said:
        August 14, 2013 at 6:58 pm

        i have try to download it but cant. where can i get this software. plz help

      kadian said:
      August 9, 2013 at 8:04 pm

      wat is the name of the software u guys using

        Romaine Carter responded:
        August 9, 2013 at 8:54 pm


        kadian said:
        August 13, 2013 at 8:57 pm

        i have try to download it but cant. where can i get this software. plz help

    Vladimir said:
    April 5, 2013 at 8:01 am

    Yes, I also have 2009b, maybe that was the problem. Thanks for your answer

      Romaine Carter responded:
      April 5, 2013 at 9:30 am

      Glad to be of help Valdimir.

        john said:
        April 7, 2013 at 9:55 am

        I tried with 2012b , and it really worked, thanks a lot.

        Romaine Carter responded:
        April 7, 2013 at 11:16 am

        You are welcome john

      kadian said:
      August 15, 2013 at 9:27 am

      where did u guys download this from

    jainy said:
    May 30, 2013 at 12:04 pm

    Dear sir once i created the model using same procedure can I use this model on daily based prediciton and if yes what is the next step for that?

      jainy said:
      May 31, 2013 at 8:35 am

      dear sir,
      Please have a look on my past post..

    jeny said:
    May 30, 2013 at 1:43 pm

    Hi there,
    I was wondering about how to use the model using this same method on daily base prediction.

    kadian said:
    August 14, 2013 at 7:00 pm

    where can i get this software can somebody help me

    oleg said:
    November 22, 2013 at 2:32 pm

    I’m having a problem with neural network forecasting in Matlab Neural Network Toolbox.

    Let’s consider two datasets (1 hour timestamp):

    input – weather forecast – temperature and cloudiness

    target – water flow rate

    I load data and train model.

    Now my problem – how I can get forecasted values of water flow rate based on 24h weather forecast dataset (temp. and cloudiness)?

    Romaine Carter responded:
    November 22, 2013 at 2:45 pm

    Hi oleg,
    How are your input values arranged your input matrix? you should have a 3xn matrix.

      oleg said:
      November 22, 2013 at 3:24 pm

      Hi Romaine,

      My values are arranged as below:
      input – 26278×2 – [temperatue ; cloudiness]
      target 26278×1 – [flow rate]

      After I train the NARX model with input and output data, I would like to predict flow rate (24×1) for prepared 24-hour temperature and cloudiness forecast dataset (24×2). Is it possible? How can I do that?

      Thank you for your quick response.

        Romaine Carter responded:
        November 22, 2013 at 4:33 pm

        You need to transpose both matrices so that they become 2 x 26278 and 1 x 26278 then you can use that to train the network.

        yournet([temp, cloudiness]) will give you a predicted value for flow rate.

    oleg said:
    November 23, 2013 at 7:19 am

    I transformed my model into closed-loop to obtain multi-step predictions //netc=closeloop(net);//, but when I enter:


    the results are strange – all 24 flow values are the same😦
    I have no idea what I did wrong.

    Romaine Carter responded:
    November 23, 2013 at 3:59 pm

    Are you using closeloop just because you want to get all 24 predictions at once? if so you should note that a closed-loop network feeds its output back into its inputs which may be the source of your problem. I do not have MATLAB installed at the moment so I am unable to do any testing with your code.

    Anonymous said:
    November 30, 2013 at 3:24 pm

    When I do this in the last step LotteryNN([1;1])
    I get the following error.

    ans =

    Neural Network object:


    numInputs: 1
    numInputs: 1
    numLayers: 2
    numLayers: 2
    ??? Error using ==> network.disp>boolstr
    Too many input arguments.

    Error in ==> network.disp at 35
    fprintf(‘ biasConnect: %s\n’,boolstr(net.biasConnect));

    Error in ==> network.display at 32

    Could you suggest a solution?

      Romaine Carter responded:
      January 21, 2014 at 4:12 pm

      Which version of MATLAB are you using?

    Łukasz Rzepiński said:
    March 26, 2014 at 7:39 am

    You should have written clearly that it is FOR RESEARCH ONLY because some people here believe that neural network is some sort of magic mirror. It is not – if the game is purely random, the neural network will not detect ANYTHING. If there is some correlation in the game, for example machine is damaged, NN can detect something. But this can be also detected by any math software by self-correlation check.
    So dear guys – play with this program but do not expect it will help you to win on lottery. If you do – this means you completly do not understand what is neural network and blindly copy paste is like magic box.

      Romaine Carter responded:
      March 26, 2014 at 8:54 am

      Hi there, it does state that in the disclaimer and also at the end of the post, however your comment will also add to the warning that this is FOR RESEARCH ONLY.

        Łukasz Rzepiński said:
        March 26, 2014 at 8:59 am

        anyway good job, I will add it to my personal training
        Just I noticed some comments here believing that NN is magic box so I decided to write this in capital letters again

        Romaine Carter responded:
        March 26, 2014 at 9:02 am

        Thanks for your feedback your comments are very insightful.

    Patience said:
    April 24, 2015 at 10:25 am

    hi, I am designing a machine that will give change for purchases below R100 and it should give the number of notes and coins, also the notes and coins should be as few as possible. I thought of using a while loop but im confused as to how, please help

    David V said:
    May 13, 2016 at 7:02 pm

    Just having a little FUN with the concept that neural network software could be used for lottery predictions. With that being said, I am new to the concept of neural networks and how the data should be setup for training or predictions. I am using the latest trial version of Matlab with the NNTool option and was hoping for a little help in understanding what is the target vs. input when setting up a 5/45 lottery game. For example, I want to analyze say the latest 50 draws and have the network output 20 of the best numbers to play after training. How would I set up the parameters? Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s