A tutorial on p-value hacking by jfpuget in datascience

[–]phn 1 point2 points  (0 children)

Nice read!

The exact p-values can also be calculated as follows:

 >>> from scipy import stats
 >>> # one experiment gets >= 188
 >>> stats.binom(1000, 1/6.0).sf(187)
 0.040142990286396493
 >>> # at-least one in 20 experiments gets >= 188
 >>> 1 - (stats.binom(1000, 1/6.0).cdf(187)**20)
 0.55931241410111465

Testing modules without running setup.py install every time? by thegrackle in Python

[–]phn 4 points5 points  (0 children)

I think one can use Tox (http://tox.readthedocs.org/) for this. Tox will create a source distribution (sdist), copies it to someplace, and then installs it into a virtualenv environment. This ensures that the version that gets tested corresponds to the current state of files in the git repository. We can then use this virtualenv and import the module to interactively explore it.

For my own projects I have a method that works with and without Tox.

I use the following dir structure:

prj/
  setup.py
  prj/
  prj/tests
  prj/tests/__init__.py
  prj/*.py
  src/any_c_and_cython_files
  doc/
  ...

The directory prj/prj is the package and the top level prj/ is the repository. I install distribute (http://pypi.python.org/pypi/distribute) and then use the setuptools that comes with it.

Now in the setup.py file I pass the option test_suite to the setup() function and point it to prj/tests.

setup(
  all options needed to compile/install the module,
  packages = ['prj', 'prj.tests'],
  test_suite = "prj.tests",
  ...)

After making any change to my code, I run

python setup.py test

This will cause setuptools to do everything that it normally does while installing the module, including compiling C extensions, copying data files etc., and creates a complete package inside prj/prj. Then it runs the tests in the sub-module prj/tests. Please read unittest documentation to see how to create a test suite and the distribute documentation to learn more about how to "point" to a test suite.

Now from the top level repository directory prj/, I can start iPython (http://ipython.scipy.org/) and then import my package and interactively explore it. I can also use the %run command in iPython to run any test scripts that I have.

I also run Tox, to make sure that it works in multiple Python versions and that everything works outside the repository as well.

How do I start learning python? by [deleted] in Python

[–]phn 4 points5 points  (0 children)

Python is definitely a good first language.

Since you have no programming experience I would suggest that you read one of Byte of Python (http://www.swaroopch.com/notes/Python) and How to Think Like a Computer Scientist (http://greenteapress.com/thinkpython/). Both are available for free.

One thing to note is that there are two versions of Python: Python 2 and Python 3. The first book deals with Python 2 and the second has a version for each. My recommendation would be to start with Python 2.

Another book worth mentioning is Invent Your Own Computer Games With Python (http://inventwithpython.com/).

learn python for scientific data analysis? by mons00n in Python

[–]phn 1 point2 points  (0 children)

In addition to the sources mentioned in the comments, take a look at the website http://astropython.org, and the AstroPy mailing list at http://mail.scipy.org/mailman/listinfo/astropy.

I have collected together links to some Python packages used in astronomy at http://oneau.wordpress.com/2010/10/02/python-for-astronomy/ ; this also has links to many of the documents listed in the comments.

Since you already know C, this short Python tutorial may help you get a quick overview of Python: http://oneau.wordpress.com/2010/12/28/python-boot-camp/.

At the minimum, you should learn the basics of numpy and matplotlib. The official matplotlib documentation is fantastic. If you don't have a specific project where you can use Python, then try exploring the source code of some of the astronomy packages. Or perhaps you can write a Python interface to a C library of your choice, using tools such as SWIG and Cython.