Пример #1
0
    def score(self, predictorParams):
        userXTest = predictorParams.get('test_x')
        forceOverwrite = json.loads(predictorParams.get('force').lower())

        # Drop force from the predictor params
        if 'force' in predictorParams:
            del predictorParams['force']
        if 'test_x' in predictorParams:
            del predictorParams['test_x']
        pObjKey = tuplify(predictorParams)

        # Check if pObj exists in ZODB
        if pObjKey in self.dbroot:
            #print ("Using existing object...")
            pObj = self.dbroot[pObjKey]
            #score = pObj.calc_score(userXTest = userXTest)
            if forceOverwrite:
                pObj.modelScore = None
            score = pObj.score(userXTest=userXTest)
            payload = self._get_payload("Score", score)
        else:
            #raise Exception("Run fit first!")
            payload = self._get_payload(
                "No object found with given params. Run fit first!",
                predictorParams)
        return payload
Пример #2
0
    def predict(self, predictorParams):
        userXTest = predictorParams.get('test_x')
        date = predictorParams.get('date')

        # Drop force from the predictor params
        if 'force' in predictorParams:
            del predictorParams['force']
        # Drop test_x from params. Don't need to key-ify it
        if 'test_x' in predictorParams:
            del predictorParams['test_x']
        if 'date' in predictorParams:
            del predictorParams['date']
        pObjKey = tuplify(predictorParams)
        #pprint (pObjKey)
        # Check if pObj exists in ZODB
        if pObjKey in self.dbroot:
            #print ("Using existing object...")
            pObj = self.dbroot[pObjKey]
            prediction = pObj.predict(userXTest)
            payload = self._get_payload("Predicted", prediction)
        else:
            #raise Exception("Run fit first!")
            payload = self._get_payload(
                "No object found with given params. Run fit first!",
                predictorParams)
        return payload
Пример #3
0
    def fit(self, predictorParams):
        hypers, errors = self._validate_predictor_params(predictorParams)
        if errors:
            payload = self._get_payload("Error with input arguments!", errors)
        else:
            predictorName = predictorParams.get('name')
            dataFilePath = predictorParams.get('data_file_path')
            features = eval(predictorParams.get('features'))
            targetCol = predictorParams.get('target_col')

            #assert predictorName, 'Must specify name for predictor'
            #print (content)

            # Check if pObj exists in ZODB

            forceOverwrite = json.loads(predictorParams.get('force').lower())

            # Drop force from the predictor params
            if 'force' in predictorParams:
                del predictorParams['force']
            if 'test_x' in predictorParams:
                del predictorParams['test_x']
            pObjKey = tuplify(predictorParams)
            #pprint (pObjKey)
            if pObjKey in self.dbroot and not forceOverwrite:
                pObj = self.dbroot[pObjKey]
                result = not pObj.skipFit
            else:
                pObj = self._get_concrete_predictor_obj(
                    predictorName, dataFilePath, hypers, targetCol, features)
                pObj.fit()
                self.dbroot[pObjKey] = pObj
                result = not pObj.skipFit

            pObj._p_changed = 1
            transaction.commit()
            if result:
                params = pObj.get_params()
                payload = self._get_payload("Fit complete!", params)
            else:
                payload = self._get_payload("Fit fail!")

        return payload
    def get_detailed_rosters(self, optimizerParams):

        #print (optimizerParams)
        optimizerName = optimizerParams.get('name')
        date = optimizerParams.get('date')

        # Drop force from the optimizer params
        if 'force' in optimizerParams:
            del optimizerParams['force']
        #pprint.pprint (optimizerParams)
        pObjKey = tuplify(optimizerParams)
        # Check if pObj exists in ZODB
        if pObjKey in self.dbroot:
            #print ("Using existing object...")
            pObj = self.dbroot[pObjKey]
            rosters = pObj.get_detailed_rosters(date)
            payload = self._get_payload("Rosters", rosters)
        else:
            #raise Exception("Run fit first!")
            payload = self._get_payload("No object found with given params. Run optimize first!", optimizerParams)
        return payload
    def optimize(self, optimizerParams):
        hypers, errors = self._validate_optimizer_params(optimizerParams)
        if errors:
            payload = self._get_payload("Error with input arguments!", errors)
        else:
            optimizerName = optimizerParams.get('name')
            date = optimizerParams.get('date')
            pisFilePath = optimizerParams.get('pis_file_path')
            salaryFilePath = optimizerParams.get('salary_file_path')
            pisFilePath2 = optimizerParams.get('pis_file_path2')
            salaryFilePath2 = optimizerParams.get('salary_file_path2')

            # Check if pObj exists in ZODB
            forceOverwrite = json.loads(optimizerParams.get('force').lower())
            # Drop force from the optimizer params
            if 'force' in optimizerParams:
                del optimizerParams['force']

            #pprint.pprint (optimizerParams)
            pObjKey = tuplify(optimizerParams)
            if pObjKey in self.dbroot and not forceOverwrite:
                pObj = self.dbroot[pObjKey]
                if pObj.solutions:
                    result = 'opt_success'
                else:
                    result = 'Re-run optimize!'
            else:
                pObj = self._get_concrete_optimizer_obj (optimizerName, hypers)
                if pisFilePath2:
                    result = pObj.optimize(date, pisFilePath, salaryFilePath, pisFilePath2=pisFilePath2, salaryFilePath2=salaryFilePath2)
                else:
                    result = pObj.optimize(date, pisFilePath, salaryFilePath)
                self.dbroot[pObjKey] = pObj
                pObj._p_changed = 1
                transaction.commit()
            payload = self._get_payload("Optimizer", result)

        return payload