Commit c71fcbc0 authored by Jay's avatar Jay
Browse files

Removing unused eval code

parent 2f9ec26d
Loading
Loading
Loading
Loading
+0 −297
Changes for autocnet/utils/evaluation_measures.py: 0 added lines, 297 removed lines.
Original line number Diff line number Diff line
import numpy as np

"""
Code from: statsmodels - https://github.com/statsmodels/statsmodels

Released under a BSD-3 license:

Copyright (C) 2006, Jonathan E. Taylor
All rights reserved.

Copyright (c) 2006-2008 Scipy Developers.
All rights reserved.

Copyright (c) 2009-2012 Statsmodels Developers.
All rights reserved.


Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  a. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
  b. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  c. Neither the name of Statsmodels nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL STATSMODELS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
"""


def mse(x1, x2, axis=0):
    """mean squared error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    mse : ndarray or float
       mean squared error along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass, for example
    numpy matrices will silently produce an incorrect result.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.mean((x1-x2)**2, axis=axis)


def rmse(x1, x2, axis=0):
    """root mean squared error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    rmse : ndarray or float
       root mean squared error along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass, for example
    numpy matrices will silently produce an incorrect result.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.sqrt(mse(x1, x2, axis=axis))


def maxabs(x1, x2, axis=0):
    """maximum absolute error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    maxabs : ndarray or float
       maximum absolute difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.max(np.abs(x1-x2), axis=axis)


def meanabs(x1, x2, axis=0):
    """mean absolute error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    meanabs : ndarray or float
       mean absolute difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.mean(np.abs(x1-x2), axis=axis)


def medianabs(x1, x2, axis=0):
    """median absolute error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    medianabs : ndarray or float
       median absolute difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.median(np.abs(x1-x2), axis=axis)


def bias(x1, x2, axis=0):
    """bias, mean error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    bias : ndarray or float
       bias, or mean difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.mean(x1-x2, axis=axis)


def medianbias(x1, x2, axis=0):
    """median bias, median error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    medianbias : ndarray or float
       median bias, or median difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.median(x1-x2, axis=axis)


def vare(x1, x2, ddof=0, axis=0):
    """variance of error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    vare : ndarray or float
       variance of difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.var(x1-x2, ddof=ddof, axis=axis)


def stde(x1, x2, ddof=0, axis=0):
    """standard deviation of error
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    stde : ndarray or float
       standard deviation of difference along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asanyarray`` to convert the input. Whether this is the
    desired result or not depends on the array subclass.
    """
    x1 = np.asanyarray(x1)
    x2 = np.asanyarray(x2)
    return np.std(x1-x2, ddof=ddof, axis=axis)


def iqr(x1, x2, axis=0):
    """interquartile range of error
    rounded index, no interpolations
    this could use newer numpy function instead
    Parameters
    ----------
    x1, x2 : array_like
       The performance measure depends on the difference between these two
       arrays.
    axis : int
       axis along which the summary statistic is calculated
    Returns
    -------
    mse : ndarray or float
       mean squared error along given axis.
    Notes
    -----
    If ``x1`` and ``x2`` have different shapes, then they need to broadcast.
    This uses ``numpy.asarray`` to convert the input, in contrast to the other
    functions in this category.
    """
    x1 = np.asarray(x1)
    x2 = np.asarray(x2)
    if axis is None:
        x1 = np.ravel(x1)
        x2 = np.ravel(x2)
        axis = 0
    xdiff = np.sort(x1 - x2)
    nobs = x1.shape[axis]
    idx = np.round((nobs-1) * np.array([0.25, 0.75])).astype(int)
    sl = [slice(None)] * xdiff.ndim
    sl[axis] = idx
    iqr = np.diff(xdiff[sl], axis=axis)
    iqr = np.squeeze(iqr)  # drop reduced dimension
    return iqr
 No newline at end of file

autocnet/utils/folds.py

deleted100644 → 0
+0 −36
Changes for autocnet/utils/folds.py: 0 added lines, 36 removed lines.
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
"""
Created on Fri Dec  4 12:51:34 2015

@author: rbanderson
"""
from sklearn import cross_validation
import numpy as np
def random(df,nfolds=5,seed=10,groupby=None):
    df['Folds']='None' #Create an entry in the data frame that holds the folds
    foldslist=np.array(df['Folds'])
    if groupby==None: #if no column name is listed to group on, just create random folds
        n=len(df.index)
        folds=cross_validation.KFold(n,nfolds,shuffle=True,random_state=seed)
        i=1        
        for train,test in folds:
            foldslist[test]='Fold'+str(i)
            i=i+1
    
    else: 
        #if a column name is provided, get all the unique values and define folds
        #so that all rows of a given value fall in the same fold 
        #(this is useful to ensure that training and test data are truly independent)
        unique_inds=np.unique(df[groupby]) 
        folds=cross_validation.KFold(len(unique_inds),nfolds,shuffle=True,random_state=seed)
        foldslist=np.array(df['Folds'])
        i=1        
        for train,test in folds:
            tmp=unique_inds[test]
            tmp_full_list=np.array(df[groupby])
            tmp_ind=np.in1d(tmp_full_list,tmp)
            foldslist[tmp_ind]='Fold'+str(i)
            i=i+1
    
    df['Folds']=foldslist
    return df
 No newline at end of file
+0 −109
Changes for autocnet/utils/tests/test_eval_measures.py: 0 added lines, 109 removed lines.
Original line number Diff line number Diff line
import unittest
import numpy as np
from .. import evaluation_measures as em

from numpy.testing import assert_equal, assert_almost_equal

"""
Code modifid from: statsmodels - https://github.com/statsmodels/statsmodels

Released under a BSD-3 license:

Copyright (C) 2006, Jonathan E. Taylor
All rights reserved.

Copyright (c) 2006-2008 Scipy Developers.
All rights reserved.

Copyright (c) 2009-2012 Statsmodels Developers.
All rights reserved.


Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  a. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
  b. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  c. Neither the name of Statsmodels nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL STATSMODELS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
"""


class TestEvalMeasures(unittest.TestCase):

    def setUp(self):
        pass

    def test_eval_measures(self):

        x = np.arange(20).reshape(4,5)
        y = np.ones((4,5))
        assert_equal(em.iqr(x, y), 5*np.ones(5))
        assert_equal(em.iqr(x, y, axis=1), 2*np.ones(4))
        assert_equal(em.iqr(x, y, axis=None), 9)

        assert_equal(em.mse(x, y),
                     np.array([  73.5,   87.5,  103.5,  121.5,  141.5]))
        assert_equal(em.mse(x, y, axis=1),
                     np.array([   3.,   38.,  123.,  258.]))

        assert_almost_equal(em.rmse(x, y),
                            np.array([  8.5732141 ,   9.35414347,  10.17349497,
                                       11.02270384,  11.89537725]))
        assert_almost_equal(em.rmse(x, y, axis=1),
                            np.array([  1.73205081,   6.164414,
                                       11.09053651,  16.0623784 ]))

        assert_equal(em.maxabs(x, y),
                     np.array([ 14.,  15.,  16.,  17.,  18.]))
        assert_equal(em.maxabs(x, y, axis=1),
                     np.array([  3.,   8.,  13.,  18.]))

        assert_equal(em.meanabs(x, y),
                     np.array([  7. ,   7.5,   8.5,   9.5,  10.5]))
        assert_equal(em.meanabs(x, y, axis=1),
                     np.array([  1.4,   6. ,  11. ,  16. ]))
        assert_equal(em.meanabs(x, y, axis=0),
                     np.array([  7. ,   7.5,   8.5,   9.5,  10.5]))

        assert_equal(em.medianabs(x, y),
                     np.array([  6.5,   7.5,   8.5,   9.5,  10.5]))
        assert_equal(em.medianabs(x, y, axis=1),
                     np.array([  1.,   6.,  11.,  16.]))

        assert_equal(em.bias(x, y),
                     np.array([  6.5,   7.5,   8.5,   9.5,  10.5]))
        assert_equal(em.bias(x, y, axis=1),
                     np.array([  1.,   6.,  11.,  16.]))

        assert_equal(em.medianbias(x, y),
                     np.array([  6.5,   7.5,   8.5,   9.5,  10.5]))
        assert_equal(em.medianbias(x, y, axis=1),
                     np.array([  1.,   6.,  11.,  16.]))

        assert_equal(em.vare(x, y),
                     np.array([ 31.25,  31.25,  31.25,  31.25,  31.25]))
        assert_equal(em.vare(x, y, axis=1),
                     np.array([ 2.,  2.,  2.,  2.]))

        assert_almost_equal(em.stde(x, y),
                     np.array([5.59017,  5.59017,  5.59017,  5.59017,  5.59017]))
        assert_almost_equal(em.stde(x, y, axis=1),
                     np.array([1.4142136,  1.4142136,  1.4142136,  1.4142136]))