scikit-learn/scikit-learn — pull request #1334 by coreylynch (2012-11-05 22:47:47+00:00)
Title: cythonized expected_mutual_information

I read http://comments.gmane.org/gmane.comp.python.scikit-learn/3997 for guidance.

Here is a small script that shows decent speedup.

```python

from sklearn.metrics.cluster.supervised import contingency_matrix
from sklearn.metrics.cluster.supervised import expected_mutual_information
import numpy as np
from expected_mutual_info_fast import expected_mutual_information as fast

true = np.array([np.random.randint(100) for i in range(1000)])
pred = np.array([np.random.randint(100) for i in range(1000)])

contingency = contingency_matrix(true, pred)

# original expected_mutual_information from supervised.py
%timeit expected_mutual_information(contingency, len(true))
1 loops, best of 3: 2.53 s per loop

# cython version
%timeit fast(contingency, len(true))
10 loops, best of 3: 75.8 ms per loop

```
This is my first time integrating a piece of Cython into a larger project, so I am eager to hear any ways I could improve it. Thanks!