0

I am a newbie to Python and am playing with a sample lotto drawing software. I have gotten as far as creating a dictionary of results, from which my code chooses a set of numbers which come most often, least often, or three suggestions with a randomized mix of both. Now, I am interested in making my software learn to make better choices based on real results of lotto draw. I would also need to add those results to my dictionary. Any ideas?

My aim is not to become a millionaire (although that would be fun) only to see how such a learning code can be approached. Thank you for your time. Here is the code I have:

from random import choice

# Data created on 06.12.2013
LottoNumbers = {'1':336,'2':339,'3':383,'4':346,'5':369,'6':347,'7':364,'8':329,
                '9':342,'10':345,'11':344,'12':336,'13':340,'14':330,'15':345,
                '16':370,'17':376,'18':334,'19':343,'20':353,'21':334,'22':329,
                '23':349,'24':351,'25':359,'26':378,'27':357,'28':347,'29':347,
                '30':352,'31':365,'32':354,'33':310,'34':343,'35':341,'36':362,
                '37':356,'38':361,'39':389,'40':351,'41':344,'42':385,'43':399,
                '44':378,'45':357}

# Copy of Lotto Numbers in order not to accidentally damage or change it
LNC = LottoNumbers

#get a list of tuples, with value in 1st position, key second
li = [(value, key) for key, value in LNC.items()]

#sort the list
li.sort()

# needed number of items
m = 6

# grab the m highest values, from the end of the list
li_high_keys = [k for v, k in li[-m:]]

# grab the m lowest values from the beginning of the list
li_low_keys = [k for v, k in li[0:m]]

# add two lists together:
mixed_list = li_high_keys + li_low_keys

# create a list with 6 random items:
def ranList(list):
    ranList = []
    for i in range(0, 6):
        item = choice(list)
        if item in ranList:
            item = choice(list)
        ranList.append(item)
    return ranList

# Get random choice from both lists:
ranList1 = sorted(ranList(mixed_list))
ranList2 = sorted(ranList(mixed_list))
ranList3 = sorted(ranList(mixed_list))

print "Numbers with highest frequency: "
print ', '.join(str(p) for p in li_high_keys) 

print "Numbers with lowest frequency: "
print ', '.join(str(p) for p in li_low_keys) 

print "Random mix of both lists: "
print ', '.join(str(p) for p in ranList1)
print ', '.join(str(p) for p in ranList2) 
print ', '.join(str(p) for p in ranList3)
9
  • 1
    Just a note, modifying LNC will also modify LottoNumbers, it's just a reference to the same object not a copy! Commented Dec 5, 2013 at 15:44
  • 2
    By the very nature of a random draw, there is no methodology that will lead to more or less success with any set of numbers! The only exception is that choosing numbers that are less frequently chosen by others will maximise your prize, as if those numbers win you won't have to share it. Commented Dec 5, 2013 at 15:48
  • Thank you Wim, you are right, I should have used LNC = LottoNumbers.copy() Commented Dec 5, 2013 at 15:50
  • Thank you jonrsharpe - I thought that since such draws should be close to some Gaussian distribution, machine could learn to place them better on the bell curve, based on past effects (results). Commented Dec 5, 2013 at 15:52
  • Certainly not Gaussian; over time you would expect the counts for each number to tend to be identical, a flat distribution Commented Dec 5, 2013 at 15:59

2 Answers 2

1

There is no technique to predict the numbers from a randomized lottery as the definition of random is that there is no algorithm to predict it.

However, if the lottery was biased, one primitive machine-learning way would be to count the number of times each number has occurred in the lottery but weight it: add only a constant raised to the number of lottery draws ago the number occurred to the counter each time the number is encountered. The higher the constant the less weightage the older lottery draws have.

Sign up to request clarification or add additional context in comments.

2 Comments

if it is computer random there certainly are algorithms to predict it ... you just have to have the same inputs (seed, ???, ???) ... that said this would be very difficult for someone who is very experienced with machine learning let alone someone who is new to it... this is a very bad choice of first machine learning project
Thanks, you are probably right... Will look for a easier way first.
0

first of all your answer is not a "choice"(number) it is a formula to pick that choice, given some input

one such formula might be guess = current_time ^ sin(current_time) >> curent_time % 360 chances are this guess is not very good ...

you need to decide on what shape your solution would take for this problem it will likely be a parse tree. this is one of the hardest individuals to use ... (a solution will look like http://biobio.loc.edu/chu/web/Courses/Cosi350/Ch3/fig3_2.gif)

so you will need to create a population (or a large pool of guessed solutions)

you then need to select fitter (better) solutions to transfer them to the next generation. when you transfer an individual you cross breed it with a second individual and then with some probability mutate some parts of it. you repeat this process for several(hundred/thousand/millions) generations. and eventually you will have decent individuals.

A much better project for machine learning and genetic algorithms would be to pick some random points and come up with a quadratic formula that will solve those points (then you are only dealing with an individual as being a simple list of coefficients)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.