Utilising Genetic algorithm to overcome different size datasets in model
algorithm, genetic-algorithm, python, python-2.7, scipy
Solution
The problem you are facing sounds to me like "Bias Variance Dilemna" from a general point of view. In a nutshell, a more precise model favours variance (sensitivity to change in a single training set), a more general model favours bias (model works for many training sets)
May I suggest not to focus on GA but look at Instance Base Learning and advanced regression techniques. The Andrew moore page at CMU is a good entry point.
And particularly those slides.
[EDIT]
After a second reading, here is my second understanding:
- You have a set of example data with two related attributes X and Y.
- You do not want X/Y to dominate when Y is small, (considered as less representative).
- As a consequence you want to "weigth" the examples with a adapted value adjusted_xy .
You want adjusted_xy to be related to a third attribute R (rank). Related such as,per class, adjusted_xy is sorted like R.
To do so you suggest to put it as an optimization problem, searching for PARAMS of a given function F(X,Y,PARAMS)= adjusted_xy .
- With the constraint that D=Distance( achieved rank for this class, rank of adjusted_xy for this class ) is minimal.
Your question, at least for me, is in the field of attribute selection/attribute adaptation. (I guess the data set will later be used for supervised learning ).
One problem that I see in your approach (if well understood) is that, at the end, rank will be highly related to adjusted_xy which will bring therefore no interesting supplementary information.
Once this said, I think you surely know how GA works . You have to
- define the content of the chromosome : this appears to be your alpha parameter.
- define an appropriate fitness function
The fitness function for one individual can be a sum of distances over all examples of the dataset.
As you are dealing with real values , other metaheuristics such as Evolution Strategies (ES) or Simulated Anealing may be more adapted than GA.
As solving optimization problems is cpu intensive, you might eventually consider C or Java instead of Python. (as fitness at least will be interpreted and thus cost a lot).
Alternatively I would look at using Y as a weight to some supervised learning algorithm (if supervised learning is the target).
Problem
SO I realise the question I am asking here is large and complex. A potential solution to variences in sizes of In all of my searching through statistical forums and posts I haven't come across a scientifically sound method of taking into account the type of data that I am encountering, but I have thought up a (novel?) potential solutions to account perfectly (in my mind) for large and small datasets within the same model. The proposed method involves using a genetic algorithm to alter two numbers defining a relationship between the size of the dataset making up an `implied strike` rate and the percentage of the `implied strike` to be used, with the target of the model to maximise the homology of the number `1` in two columns of the following csv. (ultra simplified but hopefully demonstrates the principle) Example data ``` Date,PupilName,Unique class,Achieved rank,x,y,x/y,Average xy 12/12/2012,PupilName1,UniqueClass1,1,3000,9610,0.312174818,0.08527 12/12/2012,PupilName2,UniqueClass1,2,300,961,0.312174818,0.08527 12/12/2012,PupilName3,UniqueClass1,3,1,3,0.333333333,0.08527 13/12/2012,PupilName1,UniqueClass2,1,2,3,0.666666667,0.08527 13/12/2012,PupilName2,UniqueClass2,2,0,1,0,0.08527 13/12/2012,PupilName3,UniqueClass2,3,0,5,0,0.08527 13/12/2012,PupilName4,UniqueClass2,4,0,2,0,0.08527 13/12/2012,PupilName5,UniqueClass2,5,0,17,0,0.08527 14/12/2012,PupilName1,UniqueClass3,1,1,2,0.5,0.08527 14/12/2012,PupilName2,UniqueClass3,2,0,1,0,0.08527 14/12/2012,PupilName3,UniqueClass3,3,0,5,0,0.08527 14/12/2012,PupilName4,UniqueClass3,4,0,6,0,0.08527 14/12/2012,PupilName5,UniqueClass3,5,0,12,0,0.08527 15/12/2012,PupilName1,UniqueClass4,1,0,0,0,0.08527 15/12/2012,PupilName2,UniqueClass4,2,1,25,0.04,0.08527 15/12/2012,PupilName3,UniqueClass4,3,1,29,0.034482759,0.08527 15/12/2012,PupilName4,UniqueClass4,4,1,38,0.026315789,0.08527 16/12/2012,PupilName1,UniqueClass5,1,12,24,0.5,0.08527 16/12/2012,PupilName2,UniqueClass5,2,1,2,0.5,0.08527 16/12/2012,PupilName3,UniqueClass5,3,13,59,0.220338983,0.08527 16/12/2012,PupilName4,UniqueClass5,4,28,359,0.077994429,0.08527 16/12/2012,PupilName5,UniqueClass5,5,0,0,0,0.08527 17/12/2012,PupilName1,UniqueClass6,1,0,0,0,0.08527 17/12/2012,PupilName2,UniqueClass6,2,2,200,0.01,0.08527 17/12/2012,PupilName3,UniqueClass6,3,2,254,0.007874016,0.08527 17/12/2012,PupilName4,UniqueClass6,4,2,278,0.007194245,0.08527 17/12/2012,PupilName5,UniqueClass6,5,1,279,0.003584229,0.08527 ``` So I have created a tiny model dataset, which contains some good examples of where my current methods fall short and how I feel a genetic algorithm can be used to fix this. If we look in the dataset above it contains 6 unique classes the ultimate objective of the algorithm is to create as high as possible correspondence between a rank of an adjusted `x/y` and the `achieved rank` in column 3 (zero based referencing.) In `uniqueclass1` we have two identical `x/y` values, now these are comparatively large `x/y` values if you compare with the average (note the average isn't calculated from this dataset) but it would be common sense to expect that the 3000/9610 is more significant and therefore more likely to have an `achieved rank` of `1` than the 300/961. So what I want to do is make an `adjusted x/y` to overcome these differences in dataset sizes using a logarithmic growth relationship defined by the equation: `adjusted xy = ((1-exp(-y*α)) * x/y)) + ((1-(1-exp(-y*α)))*Average xy)` Where `α` is the only dynamic number If I can explain my logic a little and open myself up to (hopefully) constructive criticsm. This graph below shows is an exponential growth relationship between size of the data set and the % of x/y contributing to the adjusted x/y. Essentially what the above equation says is as the dataset gets larger the percentage of the original `x/y` used in the `adjusted x/y` gets larger. Whatever percentage is left is made up by the average xy. Could hypothetically be 75% `x/y` and 25% `average xy` for 300/961 and 95%/5% for 3000/9610 creating an adjusted x/y which clearly demonstrates For help with understanding the lowering of `α` would produce the following relationship where by a larger dataset would be requred to achieve the same "% of xy contributed" Conversly increasing `α` would produce the following relationship where by a smaller dataset would be requred to achieve the same "% of xy contributed" So I have explained my logic. I am also open to code snippets to help me overcome the problem. I have plans to make a multitude of genetic/evolutionary algorithms in the future and could really use a working example to pick apart and play with in order to help my understanding of how to utilise such abilities of python. If additional detail is required or further clarification about the problem or methods please do ask, I really want to be able to solve this problem and future problems of this nature. So after much discussion about the methods available to overcome the problem presented here I have come to the conclusion that he best method would be a genetic algorithm to iterate α in order to maximise the homology/correspondance between a rank of an adjusted x/y and the achieved rank in column 3. It would be greatly greatly appreciated if anyone be able to help in that department? So to clarify, this post is no longer a discussion about methodology I am hoping someone can help me produce a genetic algorithm to maximise the homology between the results of the equation `adjusted xy = ((1-exp(-y*α)) * x/y)) + ((1-(1-exp(-y*α)))*Average xy)` Where `adjusted xy` applies to each row of the csv. Maximising homology could be achieved by minimising the difference between the rank of the `adjusted xy` (where the rank is by each `Unique class` only) and `Achieved rank.` Minimising this value would maximise the homology and essentially solve the problem presented to me of different size datasets. If any more information is required please ask, I check this post about 20 times a day at the moment so should reply rather promptly. Many thanks SMNALLY.