Esempio n. 1
0
    def btnValue_click(self):
        global data
        msgBox = QMessageBox()
        if not len(ui.lwData.selectedItems()):
            msgBox.setText("Please select an item first!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        Index = ui.lwData.indexOfTopLevelItem(ui.lwData.selectedItems()[0])
        varName = ui.lwData.topLevelItem(Index).text(0)

        value = data[varName]
        valueType = str(type(value)).strip().replace("<class \'", "").replace("\'>", "").replace("numpy.", "")
        valueShape = np.shape(value)

        if valueType.replace("32", "").replace("64", "").lower() == "int" or \
                        valueType.replace("32", "").replace("64", "").lower() == "float" or \
                        valueType.replace("32", "").replace("64", "").lower() == "double":
            valueShape = 1
        elif valueType.lower() == "str":
            valueShape = len(value)
        elif valueType.lower() == "bool" or valueType.lower() == "nonetype":
            valueShape = 1
        elif valueType.lower() == "ndarray":
            if valueShape[0] == 1:
                valueShape = np.shape(value)

        frmDataV = frmDataViewer()

        if valueShape == 1:
            frmDataV = frmDataViewer(str(value), VarName=varName, VarType="num")
        else:
            if valueType == "str" or valueType == "bool":
                if not len(np.shape(value)):
                    frmDataV = frmDataViewer(str(value), VarName=varName, VarType="str")
                else:
                    frmDataV = frmDataViewer(value, VarName=varName, VarType="str_arr")
            else:
                if len(np.shape(value)) == 1:
                    frmSelectR = frmSelectRange(None,Mode="d1",D1From=0,D1To=np.shape(value)[0])
                    frmSelectR.show()
                    frmSelectR.hide()
                    if frmSelectR.PASS:
                        frmDataV = frmDataViewer(value, VarName=varName, VarType="d1",\
                                                 D1From=frmSelectR.D1From, D1To=frmSelectR.D1To)
                elif  len(np.shape(value)) == 2:
                    frmSelectR = frmSelectRange(None,Mode="d2",D1From=0,D1To=np.shape(value)[0],\
                                                D2From=0,D2To=np.shape(value)[1])
                    frmSelectR.show()
                    frmSelectR.hide()
                    if frmSelectR.PASS:
                        frmDataV = frmDataViewer(value, VarName=varName, VarType="d2",\
                                                 D1From=frmSelectR.D1From, D1To=frmSelectR.D1To,\
                                                 D2From=frmSelectR.D2From, D2To=frmSelectR.D2To)
                else:
                    print("Object data is not supported!")
                    return
        frmDataV.show()
Esempio n. 2
0
    def btnValue_click(self):
        global data
        global root
        msgBox = QMessageBox()
        if not len(ui.lwData.selectedItems()):
            msgBox.setText("Please select an item first!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        Index = ui.lwData.indexOfTopLevelItem(ui.lwData.selectedItems()[0])
        varName = ui.lwData.topLevelItem(Index).text(0)

        dat, _ = frmDataEditor.getCurrentVar(self)
        value = dat[varName]

        try:
            valueType = str(type(value[0][0])).strip().replace(
                "<class \'", "").replace("\'>", "").replace("numpy.", "")
            if valueType == 'str':
                if str(type(value)).strip().replace("<class \'", "").replace(
                        "\'>", "").replace("numpy.", "") == 'ndarray':
                    valueType = 'ndarray'
        except:
            try:
                valueType = str(type(value[0])).strip().replace(
                    "<class \'", "").replace("\'>", "").replace("numpy.", "")
            except:
                valueType = str(type(value)).strip().replace(
                    "<class \'", "").replace("\'>", "").replace("numpy.", "")
        valueShape = np.shape(value)
        if valueType.replace("32", "").replace("64", "").lower() == "int" or \
                        valueType.replace("32", "").replace("64", "").lower() == "float" or \
                        valueType.replace("32", "").replace("64", "").lower() == "double":
            if valueShape == ():
                valueShape = 1
            elif valueShape == (1, 1):
                value = value[0, 0]
                valueShape = 1
            elif valueShape[0] == 1:
                value = value[0]
                try:
                    valueShape = valueShape[1]
                except:
                    try:
                        valueShape = valueShape[0]
                    except:
                        valueShape = 1
        if valueType.lower() == "str":
            if valueShape == ():
                valueShape = 1
            elif valueShape == (1, ):
                value = value[0]
                valueShape = len(value)
        if valueType.lower() == "void":
            if valueShape == ():
                valueShape = 1
            elif valueShape == (1, 1):
                value = value[0, 0]
                valueType = "complex"
                valueShape = np.shape(value)
        if valueType.lower() == "ndarray":
            if valueShape == ():
                valueShape = 1
            else:
                if valueShape[0] == 1:
                    value = value[0]
                    valueShape = np.shape(value)
        frmDataV = frmDataViewer()

        if valueShape == 1:
            frmDataV = frmDataViewer(str(value),
                                     VarName=varName,
                                     VarType="num")
        else:
            if valueType == "str":
                if not len(np.shape(value)):
                    frmDataV = frmDataViewer(value,
                                             VarName=varName,
                                             VarType="str")
                else:
                    frmDataV = frmDataViewer(value,
                                             VarName=varName,
                                             VarType="str_arr")

            elif valueType == "complex":
                root.put(varName)
                frmDataEditor.DrawData(self)
            else:
                if len(np.shape(value)) == 1:
                    frmSelectR = frmSelectRange(None,
                                                Mode="d1",
                                                D1From=0,
                                                D1To=np.shape(value)[0])
                    frmSelectR.show()
                    frmSelectR.hide()
                    if frmSelectR.PASS:
                        frmDataV = frmDataViewer(value, VarName=varName, VarType="d1",\
                                                 D1From=frmSelectR.D1From, D1To=frmSelectR.D1To)
                elif len(np.shape(value)) == 2:
                    frmSelectR = frmSelectRange(None,Mode="d2",D1From=0,D1To=np.shape(value)[0],\
                                                D2From=0,D2To=np.shape(value)[1])
                    frmSelectR.show()
                    frmSelectR.hide()
                    if frmSelectR.PASS:
                        frmDataV = frmDataViewer(value, VarName=varName, VarType="d2",\
                                                 D1From=frmSelectR.D1From, D1To=frmSelectR.D1To,\
                                                 D2From=frmSelectR.D2From, D2To=frmSelectR.D2To)
                else:
                    print("Object data is not supported!")
                    return
        frmDataV.show()
Esempio n. 3
0
    def btnTestLabels_click(self):
        print("Test is running ...")
        msgBox = QMessageBox()

        # Filter
        try:
            Filter = ui.txtFilter.text()
            if not len(Filter):
                Filter = None
            else:
                Filter = Filter.replace("\'", " ").replace(",", " ").replace(
                    "[", "").replace("]", "").split()
                Filter = np.int32(Filter)
        except:
            print("Filter is wrong!")
            return

        # InModel
        InModelFile = ui.txtInFile.text()
        if not len(InModelFile):
            msgBox.setText("Please enter model file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not os.path.isfile(InModelFile):
            msgBox.setText("Model file not found!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # InData
        InDataFile = ui.txtInData.text()
        if not len(InDataFile):
            msgBox.setText("Please enter data file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not os.path.isfile(InDataFile):
            msgBox.setText("data file not found!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # Data
        if not len(ui.txtITeData.currentText()):
            msgBox.setText("Please enter Input Test Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # Label
        if not len(ui.txtITeLabel.currentText()):
            msgBox.setText("Please enter Test Input Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        try:
            clf = joblib.load(InModelFile)
        except:
            msgBox.setText("Cannot load classification model!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        try:
            InData = mainIO_load(InDataFile)
        except:
            print("cannot load data file!")
            msgBox.setText("cannot load data file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        TeX = InData[ui.txtITeData.currentText()]
        TeL = InData[ui.txtITeLabel.currentText()][0]

        try:
            if Filter is not None:
                for fil in Filter:
                    # Remove Testing Set
                    labelIndx = np.where(TeL == fil)[0]
                    TeL = np.delete(TeL, labelIndx, axis=0)
                    TeX = np.delete(TeX, labelIndx, axis=0)
                    print("Class ID = " + str(fil) + " is removed from data.")

            if ui.cbScale.isChecked():
                TeX = preprocessing.scale(TeX)
                print("Whole of data is scaled Train~N(0,1) and Test~N(0,1).")
        except:
            print("Cannot load data or label")
            return

        print("Run testing ...")
        PeL = clf.predict(TeX)
        Labels = np.transpose(np.concatenate(([TeL], [PeL])))
        print("Labels vs Predicts:\n", Labels)
        frmDataViewer(Labels,
                      VarName="Labels vs Predicts",
                      VarType="d2",
                      D1From=0,
                      D1To=np.shape(Labels)[0],
                      D2From=0,
                      D2To=np.shape(Labels)[1])