コード例 #1
0
def SMap(pathIn="./",
         dataFile="",
         dataFrame=None,
         pathOut="./",
         predictFile="",
         lib="",
         pred="",
         E=0,
         Tp=1,
         knn=0,
         tau=1,
         theta=0,
         exclusionRadius=0,
         columns="",
         target="",
         smapFile="",
         jacobians="",
         embedded=False,
         verbose=False,
         const_pred=False,
         showPlot=False):
    '''S-Map prediction on path/file.'''

    # Establish DF as empty list or Pandas DataFrame for SMap()
    if dataFile:
        DF = pyBindEDM.DF()
    elif isinstance(dataFrame, DataFrame):
        if dataFrame.empty:
            raise Exception("SMap(): dataFrame is empty.")
        DF = pyEDM.AuxFunc.PandasDataFrametoDF(dataFrame)
    else:
        raise Exception("SMap(): Invalid data input.")

    # D is a Python dict from pybind11 < cppEDM SMap:
    #  { "predictions" : {}, "coefficients" : {} }
    D = pyBindEDM.SMap(pathIn, dataFile, DF, pathOut, predictFile, lib, pred,
                       E, Tp, knn, tau, theta, exclusionRadius, columns,
                       target, smapFile, jacobians, embedded, const_pred,
                       verbose)

    df_pred = DataFrame(D['predictions'])  # Convert to pandas DataFrame
    df_coef = DataFrame(D['coefficients'])  # Convert to pandas DataFrame

    if showPlot:
        pyEDM.AuxFunc.PlotObsPred(df_pred, dataFile, E, Tp, False)
        pyEDM.AuxFunc.PlotCoeff(df_coef, dataFile, E, Tp)

    SMapDict = {'predictions': df_pred, 'coefficients': df_coef}

    return SMapDict
コード例 #2
0
def SMap( pathIn          = "./",
          dataFile        = "",
          dataFrame       = None,
          pathOut         = "./",
          predictFile     = "",
          lib             = "",
          pred            = "",
          E               = 0, 
          Tp              = 1,
          knn             = 0,
          tau             = -1,
          theta           = 0,
          exclusionRadius = 0,
          columns         = "",
          target          = "",
          smapFile        = "",
          jacobians       = "",
          solver          = None,
          embedded        = False,
          verbose         = False,
          const_pred      = False,
          showPlot        = False,
          validLib        = [],
          generateSteps   = 0,
          parameterList   = False
          ):
    '''S-Map prediction on path/file.'''

    # Establish DF as empty list or Pandas DataFrame for SMap()
    if dataFile :
        DF = pyBindEDM.DF() 
    elif isinstance( dataFrame, DataFrame ) :
        if dataFrame.empty :
            raise Exception( "SMap(): dataFrame is empty." )
        DF = pyEDM.AuxFunc.PandasDataFrametoDF( dataFrame )
    else :
        raise Exception( "SMap(): Invalid data input." )

    # If lib, pred, columns are not string, but iterable, convert to string
    if pyEDM.AuxFunc.NotStringIterable( lib ) :
        lib = ' '.join( map( str, lib ) )
    if pyEDM.AuxFunc.NotStringIterable( pred ) :
        pred = ' '.join( map( str, pred ) )
    if pyEDM.AuxFunc.NotStringIterable( columns ) :
        columns = ' '.join( map( str, columns ) )

    # Validate the solver if one was passed in
    if solver :
        supportedSolvers = [ 'LinearRegression',
                             'Ridge',   'Lasso',   'ElasticNet',
                             'RidgeCV', 'LassoCV', 'ElasticNetCV' ]
        if not solver.__class__.__name__ in supportedSolvers :
            raise Exception( "SMap(): Invalid solver." )

    # D is a Python dict from pybind11 < cppEDM SMap:
    #  { "predictions" : {}, "coefficients" : {}, ["parameters" : {}] }
    D = pyBindEDM.SMap( pathIn,
                        dataFile,
                        DF,
                        pathOut,
                        predictFile,
                        lib,
                        pred,
                        E, 
                        Tp,
                        knn,
                        tau,
                        theta,
                        exclusionRadius,
                        columns,
                        target,
                        smapFile,
                        jacobians,
                        solver,
                        embedded,
                        const_pred,
                        verbose,
                        validLib,
                        generateSteps,
                        parameterList )

    df_pred = DataFrame( D['predictions']  ) # Convert to pandas DataFrame
    df_coef = DataFrame( D['coefficients'] ) # Convert to pandas DataFrame

    SMapDict = { 'predictions' : df_pred, 'coefficients' : df_coef }

    if parameterList :
        SMapDict[ 'parameters' ] = D[ 'parameters' ]

    if showPlot :
        if embedded :
            E = len( columns.split() )
        pyEDM.AuxFunc.PlotObsPred( df_pred, dataFile, E, Tp, False )
        pyEDM.AuxFunc.PlotCoeff  ( df_coef, dataFile, E, Tp )

    return SMapDict