Пример #1
0
def load_assess_files(segment):
    if segment["model"] != 'Logistic Regression':
        cols = segment['session'].CASTable(segment['score_params']['casOut']['name']).columns
        df = segment['session'].CASTable(segment['score_params']['casOut']['name'])[[cols[0],cols[-2]]].to_frame()
        df.dropna(inplace=True)
        yTestActual = df[cols[0]].tolist()
        yTestPredict = df[cols[-2]].tolist()
        
        
        data = [(None, None),
                (None, None),
                (yTestActual, yTestPredict)]
        # Define a directory where all the files for model manager will be kept 
        MODEL_DIR = 'automate/{}_{}-{}'.format(segment['model'], segment['region'], segment['handset'])

        
        if os.path.exists(MODEL_DIR):
            shutil.rmtree(MODEL_DIR)
        os.makedirs(MODEL_DIR)
        JSONFiles = pzmm.JSONFiles()
        target = cols[0]
        JSONFiles.calculateFitStat(data, MODEL_DIR)
        JSONFiles.generateROCStat(data, target, MODEL_DIR)
        JSONFiles.generateLiftStat(data, target, 1, MODEL_DIR)
Пример #2
0
    print('Model exists, creting new version')
    model_repository.delete_model_contents(modelname)
    register_model(model=model,
                   name=modelname,
                   project=project,
                   input=inputs,
                   force=True,
                   version='latest')

### adding extra files
### not needed but good practice
path = Path.cwd()

####
#### Creating input & output files
JSONFiles = pzmm.JSONFiles()

### write inputVar.json
JSONFiles.writeVarJSON(inputs, isInput=True, jPath=path)

### write outputVar.json
JSONFiles.writeVarJSON(outputs, isInput=False, jPath=path)

#### missing files files

filenames = {
    'file': ['inputVar.json', 'outputVar.json', 'training_code_iris.py'],
    'role': ['input', 'output', 'train']
}

#### uploading files
Пример #3
0
def score_non_swat_model(segment, tab, authUser):
    
    df = segment['segment_tbl'].to_frame()
    df = df[df['_PartInd_'] == 0]
    df = df.select_dtypes(exclude=['object'])
    imputed_cols = [col for col in df.columns if "IMP" in col]
    df = df[imputed_cols]
    target = "IMP_" + tab.children[0].children[3].children[0].children[0].value
    imputed_cols.remove(target)
    X_test = df[imputed_cols]
    y_test = df[target].tolist()
    if segment['model'] =='XGBoost':
        y_predicted = segment['modelObj'].predict_proba(X_test)[:,1]
        fpr, tpr, _ = roc_curve(y_test, y_predicted)
        ROCInfo = dict(FPR = fpr, Sensitivity = tpr)
        segment['ROCInfo'] = ROCInfo
        segment['LIFTInfo'] = create_lift(y_test, y_predicted)
        accuracy = accuracy_score(y_test, segment['modelObj'].predict(X_test))
        segment['misclassification'] = 1 - accuracy
    elif segment['model'] =='TensorFlow':
        #X_test = (X_test - X_test.mean()) / (X_test.max() - X_test.min())
        y_predicted = segment['modelObj'].predict(X_test.as_matrix()).flatten()
        fpr, tpr, _ = roc_curve(y_test, y_predicted)
        ROCInfo = dict(FPR = fpr, Sensitivity = tpr)
        segment['ROCInfo'] = ROCInfo
        segment['LIFTInfo'] = create_lift(y_test, y_predicted)
        accuracy = accuracy_score(y_test, [round(num) for num in y_predicted])
        segment['misclassification'] = 1 - accuracy
    elif (segment['model'] =='AutoML') and (segment['modelObj'] is not None):
        segment['session'].loadactionset('modelpublishing')
        tbl_test = segment['segment_tbl'].query('_PartInd_ = 0')
        y_test = tbl_test[tab.children[0].children[3].children[0].children[0].value].values.tolist()
        var_list = list()
        for col in list(segment['session'].CASTable(tab.children[0].children[1].value, caslib='Public').columns):
            var_list.append({"name" : col})
        model_tbl = segment['session'].loadtable(path='sas_model_table.sashdat',caslib='Public', casout={"caslib" : "CASUSER({})".format(authUser)})
        segment['session'].table.partition(table={'name' : tbl_test.name, 
                                                            "vars" : var_list, "where" : "_PartInd_ = 0"}, 
                                           casout={'name' : tbl_test.name + "Test", 
                                                   'promote' : True, 'caslib' : 'CASUSER({})'.format(authUser)})
        try:
            segment['session'].table.droptable(caslib='Public', name='lgdemoscore')
        except:
            pass
        print("model Object", segment['modelObj'])
        y_predicted = segment['session'].modelpublishing.runmodellocal(intable={'name': tbl_test.name + "Test", 
                                                                                "caslib" : 'CASUSER({})'.format(authUser)},
                                modelName= segment['modelObj'],
                                modeltable={'caslib': 'CASUSER({})'.format(authUser),'name': 'sas_model_table'},
                                outtable={'caslib':'Public','name':'lgdemoscore'})
        segment['session'].table.droptable(caslib='CASUSER({})'.format(authUser),name='sas_model_table')
        y_predicted = segment['session'].CASTable('lgdemoscore', caslib='Public').to_frame()
        y_predicted.columns = y_predicted.columns.str.upper()
        y_predicted = y_predicted['P_' + tab.children[0].children[3].children[0].children[0].value.upper() + '1'].values
        
        segment['session'].table.droptable(caslib='CASUSER({})'.format(authUser),name=tbl_test.name + "Test")
        fpr, tpr, _ = roc_curve(y_test, y_predicted)
        ROCInfo = dict(FPR = fpr, Sensitivity = tpr)
        segment['ROCInfo'] = ROCInfo
        segment['LIFTInfo'] = create_lift(y_test, y_predicted)
        accuracy = accuracy_score(y_test, [round(num) for num in y_predicted])
        segment['misclassification'] = 1 - accuracy
    else:
        segment['ROCInfo'] = None
        segment['LIFTInfo'] = None
        segment['misclassification'] = None
    

    yTestActual = y_test
    yTestPredict = y_predicted

    data = [(None, None),
            (None, None),
            (yTestActual, yTestPredict)]
    # Define a directory where all the files for model manager will be kept 
    MODEL_DIR = 'automate/{}_{}-{}'.format(segment['model'], segment['region'], segment['handset'])


    if os.path.exists(MODEL_DIR):
        shutil.rmtree(MODEL_DIR)
    os.makedirs(MODEL_DIR)
    JSONFiles = pzmm.JSONFiles()
    JSONFiles.calculateFitStat(data, MODEL_DIR)
    JSONFiles.generateROCStat(data, target, MODEL_DIR)
    JSONFiles.generateLiftStat(data, target, 1, MODEL_DIR)
    
    segment['score_params'] = None
    segment['assess_params'] = None