当前位置: 首页>>代码示例>>Python>>正文


Python SSUtilities.ssRange方法代码示例

本文整理汇总了Python中SSUtilities.ssRange方法的典型用法代码示例。如果您正苦于以下问题:Python SSUtilities.ssRange方法的具体用法?Python SSUtilities.ssRange怎么用?Python SSUtilities.ssRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SSUtilities的用法示例。


在下文中一共展示了SSUtilities.ssRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import ssRange [as 别名]
    def report(self):
        """Reports the results from exploratory regression analysis."""

        #### Set Title ####
        title = self.label

        #### Column Labels ####
        labs = [ARCPY.GetIDMessage(84021), ARCPY.GetIDMessage(84249),
                ARCPY.GetIDMessage(84042), ARCPY.GetIDMessage(84036),
                ARCPY.GetIDMessage(84284), ARCPY.GetIDMessage(84292),
                ARCPY.GetIDMessage(84286)]
        r2Info = [ labs ]

        #### Adjusted R2, Sorted Highest to Lowest with ID Tie Breaks ####
        header = ARCPY.GetIDMessage(84287)
        numRes = UTILS.ssRange(len(self.bestR2Res))
        r2Data = []
        for i in numRes:
            r2Val = self.bestR2Vals[i]
            idVal = int(self.bestR2Res[i].split(":")[-1])
            r2Data.append((r2Val, idVal))
        r2Data = NUM.array(r2Data, dtype = [('r2', float), ('ids', int)])
        r2SortedInds = r2Data.argsort(order = ('r2', 'ids'))
        sortIndex = reversed(r2SortedInds)
        for ind in sortIndex:
            olsID = self.bestR2Res[ind]
            olsRes = self.olsResults[olsID]
            olsOut = olsRes.report(formatStr = "%0.2f")
            r2Info.append(olsOut)

        r2Report = UTILS.outputTextTable(r2Info, header = header,
                                         justify = masterJustify)

        #### Passing Models ####
        header = ARCPY.GetIDMessage(84288)
        passList = [ labs ]
        r2Values = []
        olsIDs = []
        for olsID in self.passBools:
            olsRes = self.olsResults[olsID]
            r2Values.append(olsRes.r2)
            olsIDs.append(olsID)
        sortIndex = NUM.argsort(r2Values).tolist()
        sortIndex.reverse()
        for ind in sortIndex:
            olsID = olsIDs[ind]
            olsRes = self.olsResults[olsID]
            olsOut = olsRes.report(formatStr = "%0.6f")
            passList.append(olsOut)

        passingReport = UTILS.outputTextTable(passList, header = header)

        #### Print Report ####
        starMess = ARCPY.GetIDMessage(84289) * 78
        finalReport = [starMess, title, r2Report, passingReport]
        finalReport = "\n".join(finalReport)
        finalReport = finalReport + "\n"
        ARCPY.AddMessage(finalReport)

        return finalReport
开发者ID:f-tonini,项目名称:Python-Scripts,代码行数:62,代码来源:ModelSelectionOLS.py

示例2: createCoefficientReport

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import ssRange [as 别名]
    def createCoefficientReport(self):
        """Creates a formatted summary table of the OLS
        coefficients."""

        #### Table Title ####
        header =  ARCPY.GetIDMessage(84075)
        aFoot = ARCPY.GetIDMessage(84080)
        bFoot = ARCPY.GetIDMessage(84086)
        cFoot = ARCPY.GetIDMessage(84103)
        coefColLab = ARCPY.GetIDMessage(84049) + " " + aFoot
        probColLab = ARCPY.GetIDMessage(84055) + " " + bFoot
        robColLab = ARCPY.GetIDMessage(84102) + " " + bFoot
        vifColLab = ARCPY.GetIDMessage(84284) + " " + cFoot

        #### Column Labels ####
        total = [[ARCPY.GetIDMessage(84068), coefColLab,
                  ARCPY.GetIDMessage(84051), ARCPY.GetIDMessage(84053),
                  probColLab, ARCPY.GetIDMessage(84097),
                  ARCPY.GetIDMessage(84101), robColLab]]

        if self.vif:
            total[0].append(vifColLab)

        #### Loop Through Explanatory Variables ####
        for row in UTILS.ssRange(self.k):
            #### Variable Name ####
            rowVals = [self.varLabels[row]]

            #### Standard Values ####
            rowVals.append(UTILS.formatValue(self.coef[row, 0]))
            rowVals.append(UTILS.formatValue(self.seCoef[row]))
            rowVals.append(UTILS.formatValue(self.tStats[row]))
            rowVals.append(UTILS.writePVal(self.pVals[row], padNonSig = True))

            #### Robust Values ####
            rowVals.append(UTILS.formatValue(self.seCoefRob[row]))
            rowVals.append(UTILS.formatValue(self.tStatsRob[row]))
            rowVals.append(UTILS.writePVal(self.pValsRob[row],
                                           padNonSig = True))

            #### VIF ####
            if self.vif:
                if row == 0:
                    rowVIF = ARCPY.GetIDMessage(84092)
                else:
                    rowVIF = self.vifVal[(row - 1)]
                    if abs(rowVIF) > 1000:
                        rowVIF = "> 1000.0"
                    else:
                        rowVIF = LOCALE.format("%0.6f", rowVIF)
                rowVals.append(rowVIF)

            #### Append Row to Result List ####
            total.append(rowVals)

        #### Finalize Coefficient Table ####
        self.coefTable = UTILS.outputTextTable(total, header = header,
                                               pad = 1, justify = "right")
        self.coefRaw = total
开发者ID:f-tonini,项目名称:Python-Scripts,代码行数:61,代码来源:OLS.py

示例3: swm2Weights

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import ssRange [as 别名]
def swm2Weights(ssdo, swmfile):
    """Converts ArcGIS Sparse Spatial Weights Matrix (*.swm) file to 
    PySAL Sparse Spatial Weights Class.
    
    INPUTS:
    ssdo (class): instance of SSDataObject [1,2]
    swmFile (str): full path to swm file
    
    NOTES:
    (1) Data must already be obtained using ssdo.obtainData()
    (2) The masterField for the swm file and the ssdo object must be
        the same and may NOT be the OID/FID/ObjectID
    """
    neighbors = {}
    weights = {}
    
    #### Create SWM Reader Object ####
    swm = WU.SWMReader(swmfile)
    
    #### SWM May NOT be a Subset of the Data ####
    if ssdo.numObs > swm.numObs:
        ARCPY.AddIDMessage("ERROR", 842, ssdo.numObs, swm.numObs)
        raise SystemExit()

    if swm.masterField != ssdo.masterField:
        ARCPY.AddWarning("ERROR", 938)
        raise SystemExit()
        
    #### Parse All SWM Records ####
    for r in UTILS.ssRange(swm.numObs):
        info = swm.swm.readEntry()
        masterID, nn, nhs, w, sumUnstandard = info
        
        #### Must Have at Least One Neighbor ####
        if nn:
            #### Must be in Selection Set (If Exists) ####
            if masterID in ssdo.master2Order:
                outNHS = []
                outW = []
                
                #### Transform Master ID to Order ID ####
                orderID = ssdo.master2Order[masterID]
                
                #### Neighbors and Weights Adjusted for Selection ####
                for nhInd, nhVal in enumerate(nhs):
                    try:
                        nhOrder = ssdo.master2Order[nhVal]
                        outNHS.append(nhOrder)
                        weightVal = w[nhInd]
                        if swm.rowStandard:
                            weightVal = weightVal * sumUnstandard[0]
                        outW.append(weightVal)
                    except KeyError:
                        pass
                
                #### Add Selected Neighbors/Weights ####
                if len(outNHS):
                    neighbors[orderID] = outNHS
                    weights[orderID] = outW
    swm.close()
    
    #### Construct PySAL Spatial Weights and Standardize as per SWM ####
    w = PYSAL.W(neighbors, weights)
    if swm.rowStandard:
        w.transform = 'R'
        
    return w
开发者ID:Esri,项目名称:gis-stat-analysis-py-tutor,代码行数:69,代码来源:pysal2ArcGIS.py

示例4: calculate

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import ssRange [as 别名]
    def calculate(self, comboX):
        """Performs OLS and related diagnostics."""

        #### Shorthand Attributes ####
        ssdo = self.ssdo
        x = comboX
        n, k = NUM.shape(comboX)
        y = self.y

        #### General Information ####
        fn = n * 1.0
        dof = n - k
        fdof = dof * 1.0
        xt = x.T
        yt = y.T
        xx = NUM.dot(xt, x)

        #### Check for Perfect Multicollinearity ####
        U, s, V = LA.svd(xx)
        if UTILS.compareFloat(0.0, s[-1]):
            return False

        #### Attempt to Invert Design Matrix ####
        try:
            xxi = LA.inv(xx)
        except:
            #### Perfect multicollinearity, cannot proceed ####
            return False

        #### Bad Probabilities - Near Multicollinearity ####
        badProbs = False

        #### Compute Coefficients ####
        xy = NUM.dot(xt, y)
        coef = NUM.dot(xxi, xy)

        #### Residuals, Sum Of Squares, R2, Etc. ####
        yHat = NUM.dot(x, coef)
        yBar = (y.sum())/fn
        e = y - yHat
        ess = ( NUM.dot(e.T, e) )[0][0]
        s2 = (ess / fdof)
        s2mle = (ess / fn)
        seResiduals = NUM.sqrt(s2)
        ss = y - yBar
        tss = ( NUM.dot(ss.T, ss) )[0][0]
        r2 = 1.0 - (ess/tss)
        r2Adj =  1.0 - ( (ess / (fdof)) / (tss / (fn-1)) )
        u2 = e * e

        #### Variance-Covariance for Coefficients ####
        varBeta = xxi * s2

        #### Standard Errors / t-Statistics ####
        seBeta = NUM.sqrt(varBeta.diagonal())
        tStat = (coef.T / seBeta).flatten()

        #### White's Robust Standard Errors ####
        dofScale =  (int( n / (n - k) )) * 1.0
        sHat = NUM.dot((u2 * x).T, x) * dofScale
        varBetaRob = NUM.dot(NUM.dot(xxi, sHat), xxi)
        seBetaRob =  NUM.sqrt(varBetaRob.diagonal())
        tStatRob = (coef.T / seBetaRob).flatten()

        #### DOF Warning Once for t-Stats ####
        silentVector = [ True for i in range(k) ]
        if (2 <= dof <= 4) and not self.warnedTProb:
            silentVector[0] = False
            self.warnedTProb = True

        #### Coefficient t-Tests ####
        pVals = []
        pValsRob = []
        for varInd in UTILS.ssRange(k):
            #### General ####
            try:
                p = STATS.tProb(tStat[varInd], dof, type = 2,
                                silent = silentVector[varInd])
            except:
                p =  NUM.nan
                badProbs = True
            pVals.append(p)

            #### Robust ####
            try:
                p = STATS.tProb(tStatRob[varInd], dof, type = 2,
                                silent = True)
            except:
                p =  NUM.nan
                badProbs = True
            pValsRob.append(p)

        #### Jarque-Bera Test For Normality of the Residuals ####
        muE = (e.sum()) / fn
        devE = e - muE
        u3 = (devE**3.0).sum() / fn
        u4 = (devE**4.0).sum() / fn
        denomS = s2mle**1.5
        denomK = s2mle**2.0
        skew = u3 / denomS
#.........这里部分代码省略.........
开发者ID:f-tonini,项目名称:Python-Scripts,代码行数:103,代码来源:ModelSelectionOLS.py

示例5: createOutputGraphic

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import ssRange [as 别名]
    def createOutputGraphic(self, fileName):
        """Create OLS Output Report File.

        INPUTS
        fileName (str): path to output report file (*.pdf)
        """

        #### Set Progressor ####
        writeMSG = ARCPY.GetIDMessage(84186)
        ARCPY.SetProgressor("step", writeMSG, 0, 6, 1)
        ARCPY.AddMessage(writeMSG)

        #### Set Colors ####
        colors = NUM.array(["#4575B5", "#849EBA", "#C0CCBE", "#FFFFBF",
          "#FAB984", "#ED7551", "#D62F27"])
        cutoffs = NUM.array([-2.5, -1.5, -0.5, 0.5, 1.5, 2.5])

        #### Set Data ####
        stdRes = self.stdRedisuals.flatten()
        predicted = self.yHat.flatten()

        #### Create PDF Output ####
        pdfOutput = REPORT.openPDF(fileName)

        ##### Make Coefficient Table ####
        title = ARCPY.GetIDMessage(84075) + " - " + ARCPY.GetIDMessage(84370)
        contStr = ARCPY.GetIDMessage(84377)
        varTitlePlus = title + " " + contStr

        numCols = 9
        report = REPORT.startNewReport(9, title = title, landscape = True,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid
        colLabs = self.coefRaw[0]
        tabVals = self.coefRaw[1:]

        #### Create Column Labels ####
        writeVarColHeaders(grid, colLabs)

        #### Loop Through Explanatory Variables ####
        for row in UTILS.ssRange(self.k):
            if grid.rowCount >= 20:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(9, title = varTitlePlus,
                                               landscape = True,
                                               titleFont = REPORT.ssTitleFont)
                grid = report.grid
                writeVarColHeaders(grid, colLabs)

            #### Variable Name ####
            rowVals = tabVals[row]
            for ind, val in enumerate(rowVals):
                justify = "right"
                gridCell = PLT.subplot2grid(grid.gridInfo,
                                            (grid.rowCount, ind))
                if ind in [4, 7]:
                    if not val.count("*"):
                        x0 = .925
                elif ind == 0:
                    justify = "left"
                    x0 = 0.0
                else:
                    x0 = 1.0

                #### Limit Col Value Length to 12 ####
                if ind in [0, 1, 2, 5, 8]:
                    val = val[0:12]

                PLT.text(x0, 0.5, val,
                         fontproperties = REPORT.ssFont,
                         horizontalalignment = justify,
                         **REPORT.bAlignment)
                REPORT.clearGrid(gridCell)

            grid.stepRow()
        grid.createLineRow(grid.rowCount, startCol = 0, endCol = numCols)
        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Diagnostic Table/Interpret Tables ####
        numCols = 6
        title = ARCPY.GetIDMessage(84076)
        titlePlus = title + " " + contStr
        report = REPORT.startNewReport(numCols, title = title,
                                       landscape = True, numRows = 22,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid
        ind2Col = {0:0, 1:1, 2:3, 3:5}

        for row in self.diagRaw:
            for ind, val in enumerate(row):
                #### Limit Col Length to 23 ####
                if ind not in [0,2]:
#.........这里部分代码省略.........
开发者ID:f-tonini,项目名称:Python-Scripts,代码行数:103,代码来源:OLS.py


注:本文中的SSUtilities.ssRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。