Predicting The Lottery With MATLAB® Neural Network

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.


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

    1. 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.

      1. 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

  1. 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………..

    1. 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,…

  2. 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

  3. 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};

    1. 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.

  4. Hello,
    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

  5. 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?

  6. 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)?

    1. 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.

      1. 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.

  7. 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.

  8. 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.

  9. 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?

  10. 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.

  11. 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

  12. 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.

  13. David V is RIGHT!!! How to set up this MathLab NeuNet for a 5/45 GAME that Analyzes the past 50 DRAWS with an OUTPUT of 25 possible numbers (1 to 45) for a single future draw date/time

      1. Thanks for the reply. Also how could I set this NeuNet MATLAB to RUN the Algorthm on a GPU nVidia CUDA Acceleration and event Network Parallel Computer setup instead of just the CPU and how? It would be nice if you made a youtube video that shows how to set this all up From Excel arrangement, to working MATLAB version install/config, to MATLAB Neural Net Setup/Training ! Also as a side question, what does your friends’ heuristics such as OldLady or FreashWater… stand for in each Cash Pot drawing? The number are different on for each FreashWater, OldLady draw time repetition, I dont see the corrolation between both OldLady or both FreashWater heuristics lol! THANKS!

      2. There is a book that contains the numbers and their meanings; however, as you see I completely ignored that column because it’s just there to further complicate the heuristics. In terms of NN prediction they have no meaning or correlation.

  14. The n x 5 vector would need to be also included it the previous 50 drawing for each column pick1, pick2, pick3, pick4, pick5, 5 hence vectors. A n x 5 trained target vectors but the output would have to be a n x 25 vectors? Am I getting it right that’s where I’m confused how to set this up?.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s