Thursday, September 12, 2019

Quick help on Writing C Extension for Python

Here are a few links to the website which I think is helpful in doing this:

The below 3 link will help you understand the basic of building from window:

https://docs.python.org/3/extending/extending.html
https://docs.python.org/3/c-api/module.html#c.PyModuleDef
https://stackabuse.com/enhancing-python-with-custom-c-extensions/
https://stackoverflow.com/questions/49299905/error-lnk2001-unresolved-external-symbol-pyinit
https://docs.python.org/3/c-api/structures.html

After which, the challenge is to compile/link it to the Python project. The challenge I have is when compiling the code, you cannot just use a typical compiler from the IDE. Rather I found out that you have to use the relevant command prompt:
https://docs.python.org/3/extending/windows.html
https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line?view=vs-2019

For example:

cl /LD /I <Path to Python36/inclulde> spammodule1.c <path to python36.lib>
e.g.
cl /LD /I C:\Users\username\AppData\Local\Programs\Python\Python36\include\  spammodule1.c C:\Users\username\AppData\Local\Programs\Python\Python36\libs\python36.lib


At this point, I got stucked because I am not able to proceed to how to use the DLL and LIB files.

However, I found out that you can also use the distutils method to compile into .py files:
https://docs.python.org/3/extending/building.html

For example:
<Python.exe path> setup.py build
C:\Users\username\AppData\Local\Programs\Python\Python36\python.exe setup.py build

I find this method easier as it will do compilation as well as typical installation that allow you to use it like any other Python Module. Do note however that you need to include the path into the Python Interface:

https://stackoverflow.com/questions/28326362/pycharm-and-pythonpath


Saturday, August 24, 2019

Analysing Turf Club Data - Age does matter

In the past few weeks, I have been exploring data science and having read about Bill Benter I decided to also explore Data published on Turf Club. I managed to scrape the Singapore Turf Club and pull ut the following data:

Horse Performance
Jockey Performance
Race information

The pulling of information was relatively easy but I spend a lot of time cleaning up the data. The following are some record of what I found.

Horse Age
My initial thoughts were that horse age would matter since intuitively, the older any organism gets, the less likely it will be as strong. But it turn out that horse age does not matter. This means a old horse may still win a younger ones. This may make sense because I imagine myself to be a horse owner and I would also want to optimize the capability of my horse. This means I will not take part in competition that I have no chance of winning.


Jockey
I notice that for some horses, the same Jockey gets to ride them while other horses, the Jockey keeps changing. Some jockey has higher winning percentage while others are lower than average.

Age - Hypothesis 1
Horse age has an impact to winning.
I do not see a significant change in distribution for winners vs losers vs all population. If anything it shows that owners are less likely to send old horses for competition.


Even for old horses, the winning (1st or 2nd) rate is about 14% and that is just 1+% off the fair winning rate of 16+% (1/12*2). So it is fair to say every horse has an equal winning rate.

The best way of doing this is of course to conduct an hypothesis test but I did not go any further since I also believe surface information will not get me any extra information.



First time riding - Hypothesis 2

In this hypothesis, I think it matter if the jockey is riding the horse the first time. He may not have established a good understanding of the horse and this may affect the chance. So here we did some analysis:

Overall Analysis:

My finding is that young horses react very well to new ridership. Total probability of any horse winning (1st or 2nd) for all age is generally high at 25%:




Specifically, for age less than 1500 years is higher at 30%:


For older horses, there is no advantage in terms of probability:

Nth riding - Hypothesis 3
What about riding after once or twice or Nth time? Many a times I realized a horse is being rode by the same Jockey for an extended period of time. Is there an advantage to using the same Jockey?

It is found that older horses generally do not perform well to repeatedly being rode by the same Jockey: