Skip to content

Commit

Permalink
Merge c1fa41b into 58f3e5d
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesdrotar committed Oct 16, 2016
2 parents 58f3e5d + c1fa41b commit 72cf87a
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 31 deletions.
19 changes: 6 additions & 13 deletions doc/index.rst
Expand Up @@ -23,21 +23,14 @@ come to know and love.
Travis CI Build Status
======================

.. raw:: html

<p style="height:22px">
<a href="https://travis-ci.org/tgsmith61591/skutil" >
<img src="https://travis-ci.org/tgsmith61591/skutil.svg?branch=master"/>
</a>
<a href="https://coveralls.io/github/tgsmith61591/skutil?branch=master" >
<img src="https://coveralls.io/repos/github/tgsmith61591/skutil/badge.svg?branch=master"/>
</a>
<a href="https://img.shields.io/badge/python-2.7-blue" >
<img src="https://img.shields.io/badge/python-2.7-blue.svg"/>
</a>
</p>
.. image:: https://travis-ci.org/tgsmith61591/skutil.svg?branch=master
:target: https://travis-ci.org/tgsmith61591/skutil

.. image:: https://coveralls.io/repos/github/tgsmith61591/skutil/badge.svg?branch=master
:target: https://coveralls.io/github/tgsmith61591/skutil?branch=master

.. image:: https://img.shields.io/badge/python-2.7-blue.svg
:target: https://img.shields.io/badge/python-2.7-blue

Helpful Links
=============
Expand Down
10 changes: 5 additions & 5 deletions skutil/h2o/grid_search.py
Expand Up @@ -848,7 +848,7 @@ class H2ORandomizedSearchCV(BaseH2OSearchCV):
n_iter : int, optional (default=10)
The number of iterations to fit. Note that
n_iter * cv.get_n_splits will be fit. If there
``n_iter * cv.get_n_splits`` will be fit. If there
are 10 folds and 10 iterations, 100 models (plus
one) will be fit.
Expand All @@ -865,7 +865,7 @@ class H2ORandomizedSearchCV(BaseH2OSearchCV):
cv : int or H2OCrossValidator, optional (default=5)
The number of folds to be fit for cross validation.
Note that n_iter * cv.get_n_splits will be fit. If there
Note that ``n_iter * cv.get_n_splits`` will be fit. If there
are 10 folds and 10 iterations, 100 models (plus
one) will be fit.
Expand Down Expand Up @@ -984,7 +984,7 @@ class H2OGainsRandomizedSearchCV(H2ORandomizedSearchCV):
n_iter : int, optional (default=10)
The number of iterations to fit. Note that
n_iter * cv.get_n_splits will be fit. If there
``n_iter * cv.get_n_splits`` will be fit. If there
are 10 folds and 10 iterations, 100 models (plus
one) will be fit.
Expand All @@ -1001,7 +1001,7 @@ class H2OGainsRandomizedSearchCV(H2ORandomizedSearchCV):
cv : int or H2OCrossValidator, optional (default=5)
The number of folds to be fit for cross validation.
Note that n_iter * cv.get_n_splits will be fit. If there
Note that ``n_iter * cv.get_n_splits`` will be fit. If there
are 10 folds and 10 iterations, 100 models (plus
one) will be fit.
Expand Down Expand Up @@ -1149,7 +1149,7 @@ def report_scores(self):
@overrides(BaseH2OSearchCV)
def score(self, frame):
"""Predict and score on a new frame. Note that this method
will not store performance metrics in the report that ```report_score```
will not store performance metrics in the report that ``report_score``
generates.
Parameters
Expand Down
6 changes: 3 additions & 3 deletions skutil/h2o/metrics.py
Expand Up @@ -780,7 +780,7 @@ def make_h2o_scorer(score_function, y_true):
"""Make a scoring function from a callable.
The signature for the callable should resemble:
```some_function(y_true, y_pred, y_type=None...)```
``some_function(y_true, y_pred, y_type=None...)``
Parameters
----------
Expand All @@ -802,9 +802,9 @@ class _H2OScorer(six.with_metaclass(abc.ABCMeta)):
with H2OFrames. The first two arguments in the scoring function
signature should resemble the following:
```some_function(y_true, y_pred, y_type=None...)```
``some_function(y_true, y_pred, y_type=None...)``
Any specific scoring kwargs should be passed to the ```score```
Any specific scoring kwargs should be passed to the ``score``
function in the class instance.
Parameters
Expand Down
4 changes: 3 additions & 1 deletion skutil/h2o/transform.py
Expand Up @@ -356,7 +356,9 @@ def _mul(a, b):
class H2OInteractionTermTransformer(BaseH2OTransformer):
"""A class that will generate interaction terms between selected columns.
An interaction captures some relationship between two independent variables
in the form of In = (xi * xj).
in the form of:
:math:`In = (x_i * x_j)`
Note that the H2OInteractionTermTransformer will only operate on the feature_names,
and at the transform point will return ALL features plus the newly generated ones.
Expand Down
4 changes: 3 additions & 1 deletion skutil/linear_model/__init__.py
@@ -1,4 +1,6 @@
"""
skutil.linear_model will provide the basis for
Poisson and Tweedy regressions and gradient computations.
"""
"""

__all__ = [s for s in dir() if not s.startswith("_")] # Remove hiddens
2 changes: 1 addition & 1 deletion skutil/metrics/__init__.py
Expand Up @@ -6,4 +6,4 @@
from .pairwise import *
from ._act import *

# __all__ = [s for s in dir() if not s.startswith("_")] # Remove hiddens
__all__ = [s for s in dir() if not s.startswith("_")] # Remove hiddens
53 changes: 49 additions & 4 deletions skutil/metrics/_kernel.py → skutil/metrics/kernel.py
Expand Up @@ -39,7 +39,7 @@ def _prep_X_Y_for_cython(X, Y):

# Cython proxies
def _hilbert_dot(x, y, scalar=1.0):
# return 2 * safe_sparse_dot(x, y) - safe_sparse_dot(x, x.T) - safe_sparse_dot(y, y.T)
# return ``2 * safe_sparse_dot(x, y) - safe_sparse_dot(x, x.T) - safe_sparse_dot(y, y.T)``
x, y = x.astype(np.double, order='C'), y.astype(np.double, order='C')
return _hilbert_dot_fast(x, y, scalar)

Expand All @@ -59,6 +59,10 @@ def exponential_kernel(X, Y=None, sigma=1.0):
power. In the other hand, if underestimated, the function will lack regularization and
the decision boundary will be highly sensitive to noise in training data.
The kernel is given by:
:math:`k(x, y) = exp( -||x-y|| / 2\\sigma^2 )`
Parameters
----------
Expand Down Expand Up @@ -92,14 +96,18 @@ def exponential_kernel(X, Y=None, sigma=1.0):


def gaussian_kernel(X, Y=None, sigma=1.0):
"""The ``gaussian_kernel`` is closely related to the ``exponential_kernel``.
"""The ``gaussian_kernel`` is closely related to the ``exponential_kernel``.
It is also an ``rbf_kernel``. Note that the adjustable parameter, ``sigma``,
plays a major role in the performance of the kernel and should be carefully
tuned. If overestimated, the exponential will behave almost linearly and
the higher-dimensional projection will start to lose its non-linear
power. In the other hand, if underestimated, the function will lack regularization and
the decision boundary will be highly sensitive to noise in training data.
The kernel is given by:
:math:`k(x, y) = exp( -||x-y||^2 / 2\\sigma^2 )`
Parameters
----------
Expand Down Expand Up @@ -137,6 +145,10 @@ def inverse_multiquadric_kernel(X, Y=None, constant=1.0):
results in a kernel matrix with full rank (Micchelli, 1986) and thus forms
an infinite dimension feature space.
The kernel is given by:
:math:`k(x, y) = 1 / sqrt( -||x-y||^2 + c^2 )`
Parameters
----------
Expand Down Expand Up @@ -174,6 +186,10 @@ def laplace_kernel(X, Y=None, sigma=1.0):
except for being less sensitive for changes in the ``sigma`` parameter.
Being equivalent, it is also an ``rbf_kernel``.
The kernel is given by:
:math:`k(x, y) = exp( -||x-y|| / \\sigma )`
Parameters
----------
Expand Down Expand Up @@ -212,6 +228,10 @@ def linear_kernel(X, Y=None, constant=0.0):
Kernel algorithms using a linear kernel are often equivalent to their non-kernel
counterparts, i.e. KPCA with a ``linear_kernel`` is the same as standard PCA.
The kernel is given by:
:math:`k(x, y) = x^Ty + c`
Parameters
----------
Expand Down Expand Up @@ -249,6 +269,10 @@ def multiquadric_kernel(X, Y=None, constant=0.0):
as the Rational Quadratic kernel. As is the case with the Sigmoid kernel,
it is also an example of an non-positive definite kernel.
The kernel is given by:
:math:`k(x, y) = sqrt( -||x-y||^2 + c^2 )`
Parameters
----------
Expand Down Expand Up @@ -289,6 +313,10 @@ def polynomial_kernel(X, Y=None, alpha=1.0, degree=1.0, constant=1.0):
Adjustable parameters are the slope (``alpha``), the constant term (``constant``),
and the polynomial degree (``degree``).
The kernel is given by:
:math:`k(x, y) = ( \\alpha x^Ty + c)^d`
Parameters
----------
Expand Down Expand Up @@ -333,6 +361,10 @@ def power_kernel(X, Y=None, degree=1.0):
It is an example of scale-invariant kernel (Sahbi and Fleuret, 2004) and is
also only conditionally positive definite.
The kernel is given by:
:math:`k(x, y) = -||x-y||^d`
Parameters
----------
Expand Down Expand Up @@ -374,6 +406,14 @@ def rbf_kernel(X, Y=None, sigma=1.0):
power. In the other hand, if underestimated, the function will lack regularization and
the decision boundary will be highly sensitive to noise in training data.
The kernel is given by:
:math:`k(x, y) = exp(- \\gamma * ||x-y||^2)`
where:
:math:`\\gamma = 1/( \\sigma ^2)`
Parameters
----------
Expand Down Expand Up @@ -407,9 +447,14 @@ def rbf_kernel(X, Y=None, sigma=1.0):


def spline_kernel(X, Y=None):
"""The ``spline_kernel`` is given as a piece-wise cubic polynomial,
"""
The ``spline_kernel`` is given as a piece-wise cubic polynomial,
as derived in the works by Gunn (1998).
The kernel is given by:
:math:`k(x, y) = 1 + xy + xy * min(x,y) - (1/2 * (x+y)) * min(x,y)^2 + 1/3 * min(x,y)^3`
Parameters
----------
Expand Down Expand Up @@ -448,7 +493,7 @@ def tanh_kernel(X, Y=None, constant=0.0, alpha=1.0):
The kernel is given by:
k(x, y) = tanh (alpha x^T y + c)
:math:`k(x, y) = tanh (\\alpha x^T y + c)`
It is interesting to note that a SVM model using a sigmoid kernel function is
equivalent to a two-layer, perceptron neural network. This kernel was quite popular
Expand Down
2 changes: 1 addition & 1 deletion skutil/metrics/pairwise.py
@@ -1,4 +1,4 @@
import numpy as np
from ._kernel import *
from .kernel import *
from sklearn.utils import check_array, check_X_y

4 changes: 2 additions & 2 deletions skutil/metrics/tests/test_metrics.py
@@ -1,8 +1,8 @@
from skutil.metrics import *
import numpy as np
import timeit
from skutil.metrics._kernel import (_hilbert_dot,
_hilbert_matrix)
from skutil.metrics.kernel import (_hilbert_dot,
_hilbert_matrix)
from skutil.metrics import GainsStatisticalReport
from skutil.utils.tests.utils import assert_fails
from numpy.testing import (assert_array_equal, assert_almost_equal, assert_array_almost_equal)
Expand Down

0 comments on commit 72cf87a

Please sign in to comment.