Esempio n. 1
0
    def validateModel(self, printToScreen=False):
        """ take the validation data and test it on the network at any given point.
        returns a single numeric error value which describes the goodness of the model"""
        if NoneType in (type(self.validationFeatures),
                        type(self.validationLabels), type(self.meta)):
            raise Exception("Specify validation features and labels")

        predictedOutput = list()
        for loopCounter, (rowIndex, row) in enumerate(
                self.validationFeatures.iterrows()):
            predictedOutput.append([item for item in self.predict(row)])
        predictedOutput = pd.DataFrame(
            np.array(predictedOutput),
            columns=[self.meta.categoricalLabelColumns])

        #convert predictions back into a human readable format
        predictedMatrix = DataCleaner.deNormalize(
            DataCleaner.categoricalToNominal(
                self.validationFeatures.join(predictedOutput), self.meta),
            self.meta)
        expectedMatrix = DataCleaner.deNormalize(
            DataCleaner.categoricalToNominal(
                self.validationFeatures.join(self.validationLabels),
                self.meta), self.meta)
        error = comparePrediction(predictedMatrix, expectedMatrix, self.meta,
                                  printToScreen)
        return error
Esempio n. 2
0
    def validateModel(self, printToScreen=False):
        """ take the validation data and test it on the network at any given point.
        returns a single numeric error value which describes the goodness of the model"""
        if NoneType in (type(self.validationFeatures), type(self.validationLabels), type(self.meta)):
            raise Exception("Specify validation features and labels")

        predictedOutput = list()
        for loopCounter, (rowIndex, row) in enumerate(self.validationFeatures.iterrows()):
            predictedOutput.append([item for item in self.predict(row)])
        predictedOutput = pd.DataFrame(np.array(predictedOutput), columns=[self.meta.categoricalLabelColumns])

        #convert predictions back into a human readable format
        predictedMatrix  = DataCleaner.deNormalize(DataCleaner.categoricalToNominal(self.validationFeatures.join(predictedOutput), self.meta), self.meta)
        expectedMatrix   = DataCleaner.deNormalize(DataCleaner.categoricalToNominal(self.validationFeatures.join(self.validationLabels), self.meta), self.meta)
        error            = comparePrediction(predictedMatrix, expectedMatrix, self.meta, printToScreen)
        return error
Esempio n. 3
0
    li("Dataset has Rows: {0}, Columns: {1}".format(len(data), len(meta.names())))

    if args["command"] in ("info"):
        sys.exit(0)

    if not args["labels"]:
        labels = raw_input("Which columns to use as labels? [{0}-{1}]: ".format(1, len(meta.names())))
    else:
        labels = args["labels"]
    setLabels(data, meta, labels)
    if len(meta.labelColumns) < 1:
        raise Exception("Specify atleast 1 label column")
    li("Label Columns: {0}".format(meta.labelColumns))

    li("Cleaning Data")
    data = DataCleaner.impute(data, meta)
    data = DataCleaner.normalize(data, meta)
    data = DataCleaner.nominalToCategorical(data, meta)

    if args["command"] in ("cross_validate", "train"):
        if args["command"] == "cross_validate":
            li("Starting {0}-fold cross validation".format(args["folds"]))
            error = crossValidate(
                data,
                meta,
                folds=args["folds"],
                topology=args["topo"],
                iterations=args["epochs"],
                weights=args["weights"],
                graph=args["graph"],
            )
Esempio n. 4
0
    data, meta = loader.load()
    li(meta)
    li("Dataset has Rows: {0}, Columns: {1}".format(len(data), len(meta.names())))

    if args['command'] in ("info"):
        sys.exit(0)

    if not args['labels']:
        labels = raw_input('Which columns to use as labels? [{0}-{1}]: '.format(1, len(meta.names())))
    else:
        labels = args['labels']
    setLabels(data, meta, labels)
    if len(meta.labelColumns) < 1:
        raise Exception("Specify atleast 1 label column")
    li("Label Columns: {0}".format(meta.labelColumns))

    li("Cleaning Data")
    data = DataCleaner.impute(data, meta)
    data = DataCleaner.normalize(data, meta)
    data = DataCleaner.nominalToCategorical(data, meta)

    if args['command'] in ("cross_validate", "train"):
        if args['command'] == "cross_validate":
            li("Starting {0}-fold cross validation".format(args['folds']))
            error = crossValidate(data, meta, folds=args['folds'], topology=args['topo'], iterations=args['epochs'], weights=args['weights'], graph=args['graph'])

    #uncomment the lines if you want to log all files processed
    #from os.path import expanduser
    #with open("{0}/nncli-history.txt".format(expanduser("~")), "a") as myfile:
        #myfile.write("\n{0},{1},{2},{3}".format(args['data'], args['command'], args['topo'], error))