Пример #1
0
def main():
    #Load original dataframes
    hemoData = pd.read_csv('Data/Preprocessed Data/ESCAPE_Hemo.csv', index_col='ID')
    allScores = hemoData['Score']
    death = hemoData['ScoreDeath']
    rehosp = hemoData['ScoreRehosp']
    readm = hemoData['ScoreReadmission']

    # Preprocess and create training and testing sets
    hemo = hemoData.drop('Score', axis=1)
    hemo = hemo.drop('ScoreDeath', axis=1)
    hemo = hemo.drop('ScoreRehosp', axis=1)
    hemo = hemo.drop('ScoreReadmission', axis=1)
    hemo = hemo.replace(np.inf, 0)
    hemo = hemo.fillna(0)

    xData = hemo

    yData = death

    modelName = 'Hemo_Death'
    mvdd = mvGen.generateTreeCrossValidation(xData=xData, yData=yData, classes=["1", "2", "3", "4", "5"],
                                            learningCriteria='gini', maxLevels=None, minSamplesPerLeaf=1,
                                            modelName=modelName, numFolds=5,
                                            showIndividualROC=True)

    # Get Feature importance
    featureDict = dict(zip(hemo.columns, mvdd.model.feature_importances_))
    featureImp = pd.DataFrame.from_dict(featureDict, orient='index')
    featureImp.rename(columns = {0:'Feature Importance'}, inplace = True)
    featureImp = featureImp.sort_values(by=['Feature Importance'], ascending=False)
    featureImp.to_csv("Graphs/FeatureImportances" + modelName + ".csv")
Пример #2
0
def runAllData(paramDict, outcome):

    # get outcome
    if outcome == "READMISSION":
        modelName = 'TreeFiles/AllData_Readmission'
    elif outcome == "DEATH":
        modelName = 'TreeFiles/AllData_Death'
    elif outcome == "REHOSPITALIZATION":
        modelName = 'TreeFiles/AllData_Rehosp'
    else:
        modelName = 'TreeFiles/AllData_AllOutcomes'

    # load model
    mvdd = mvGen.loadMVDDFromFile(modelName)

    # Predict score
    score, path = mvdd.predictScore(paramDict)
    score = int(score)

    if score == 5:
        scorePath = "Returned Score of " + str(
            score
        ) + ", Risk Level: HIGH\nIndicates a >= 40% chance of the outcome " + outcome
    elif score == 4:
        scorePath = "Returned Score of " + str(
            score
        ) + ", Risk Level: INTERMEDIATE - HIGH\nIndicates a 30-40% chance of the outcome " + outcome
    elif score == 3:
        scorePath = "Returned Score of " + str(
            score
        ) + ", Risk Level: INTERMEDIATE\nIndicates a 20-30% chance of the outcome " + outcome
    elif score == 2:
        scorePath = "Returned Score of " + str(
            score
        ) + ", Risk Level: LOW - INTERMEDIATE\nIndicates a 10-20% chance of the outcome " + outcome
    else:  # score == 1:
        scorePath = "Returned Score of " + str(
            score
        ) + ", Risk Level: LOW\nIndicates a < 10% chance of the outcome " + outcome

    imageName = modelName + '.png'

    return imageName, score, scorePath, path  # will be displayed on webpage