Ejemplo n.º 1
0
def miss(test_filename, train_filename, param_filename):
    fn = test_filename.replace("-data", "-index")
    meta = None
    if os.path.exists(fn):
        with open(fn, "r") as idxfile:
            meta = idxfile.readlines()

    X, y, df = design_matrix(test_filename, train_filename, get_df=True)
    predictor = gen_predictor(param_filename)
    probs = predictor(X)
    indices = get_misses(probs, y)
    for i in indices:
        print "----------------"
        if meta: print "META:",",".join(meta[i].split(",")).strip()
        print df.ix[i]
    return indices
Ejemplo n.º 2
0
def miss(test_filename, train_filename, param_filename):
    fn = test_filename.replace("-data", "-index")
    meta = None
    if os.path.exists(fn):
        with open(fn, "r") as idxfile:
            meta = idxfile.readlines()

    X, y, df = design_matrix(test_filename, train_filename, get_df=True)
    predictor = gen_predictor(param_filename)
    probs = predictor(X)
    indices = get_misses(probs, y)
    for i in indices:
        print "----------------"
        if meta: print "META:", ",".join(meta[i].split(",")).strip()
        print df.ix[i]
    return indices
Ejemplo n.º 3
0
def eval(test_filename, train_filename, param_filename, method, **kwparams):
    X, y = design_matrix(test_filename, train_filename)
    predictor = gen_predictor(param_filename)
    probs = predictor(X)
    return run_eval(probs, y, method, **kwparams)
Ejemplo n.º 4
0
def pred(test_filename, train_filename, param_filename):
    X, y = design_matrix(test_filename, train_filename)
    predictor = gen_predictor(param_filename)
    probs = predictor(X)
    return probs, y
Ejemplo n.º 5
0
    def calc_risk(self):
        if "AGE" in values and values["AGE"]:
            age = 30
            try:
                age = float(values["AGE"])
            except ValueError:
                pass
            except TypeError:
                pass
            if age < 10 or 50 < age:
                res_scr.curr_risk_color = [
                    153.0 / 255, 93.0 / 255, 77.0 / 255, 1
                ]
                res_scr.curr_risk_label = 'HIGH RISK'
                res_scr.curr_risk_level = 1
                sm.current = 'result'
                return

        # Find highest ranking model that contained in the provided variables
        model_dir = None
        model_vars = None
        vv = set([])
        for k in values:
            if values[k]: vv.add(k)
        print vv
        for info in models_info:
            v = set(info[1])
            res = v.issubset(vv)
            #print res, info[1]
            if res:
                model_dir = info[0]
                model_vars = info[1]
                break

        if not model_dir or not models_info:
            res_scr.curr_risk_color = [0.5, 0.5, 0.5, 1]
            res_scr.curr_risk_label = 'INSUFFICIENT DATA'
            res_scr.curr_risk_level = 0
            sm.transition = RiseInTransition()
            sm.current = 'result'
            return

        print "FOUND MODEL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        print model_dir
        print model_vars

        predictor = gen_predictor(os.path.join(model_dir, 'nnet-params'))
        N = len(model_vars)

        model_min = []
        model_max = []
        with open(os.path.join(model_dir, 'bounds.txt')) as bfile:
            lines = bfile.readlines()
            for line in lines:
                line = line.strip()
                parts = line.split()
                model_min.append(float(parts[1]))
                model_max.append(float(parts[2]))

        print model_min
        print model_max

        v = [None] * (N + 1)
        v[0] = 1
        for i in range(N):
            var = model_vars[i]
            if var in values:
                try:
                    v[i + 1] = float(values[var])
                    if var in units and units[var] != var_def_unit[var]:
                        # Need to convert units
                        c, f = var_unit_conv[var]
                        print "convert", var, v[i +
                                                1], "->", f * (v[i + 1] + c)
                        v[i + 1] = f * (v[i + 1] + c)
                except ValueError:
                    pass
                except TypeError:
                    pass

        if None in v:
            res_scr.curr_risk_color = [0.5, 0.5, 0.5, 1]
            res_scr.curr_risk_label = 'INSUFFICIENT DATA'
            res_scr.curr_risk_level = 0
            sm.current = 'result'
            return

        for i in range(N):
            f = (v[i + 1] - model_min[i]) / (model_max[i] - model_min[i])
            if f < 0: v[i + 1] = 0
            elif 1 < f: v[i + 1] = 1
            else: v[i + 1] = f

        print values
        print v

        X = np.array([v])
        probs = predictor(X)
        pred = probs[0]
        print "------------->", pred, type(pred)
        res_scr.curr_risk_level = float(pred)
        if pred < 0.5:
            res_scr.curr_risk_color = [
                121.0 / 255, 192.0 / 255, 119.0 / 255, 1
            ]
            res_scr.curr_risk_label = 'LOW RISK'
        else:
            level = float((pred - 0.5) / 0.5)
            res_scr.curr_risk_color = [153.0 / 255, 93.0 / 255, 77.0 / 255, 1]
            res_scr.curr_risk_label = 'HIGH RISK'
        sm.transition = RiseInTransition()
        #sm.transition = SlideTransition(direction='left')
        sm.current = 'result'
Ejemplo n.º 6
0
def eval(test_filename, train_filename, param_filename, method, **kwparams):
    X, y = design_matrix(test_filename, train_filename)
    predictor = gen_predictor(param_filename)
    probs = predictor(X)
    return run_eval(probs, y, method, **kwparams)
Ejemplo n.º 7
0
def pred(test_filename, train_filename, param_filename):
    X, y = design_matrix(test_filename, train_filename)
    predictor = gen_predictor(param_filename)
    probs = predictor(X)
    return probs, y
Ejemplo n.º 8
0
        model_vars = None
        for info in models_info: 
            v = set(info[1])
            res = v.issubset(vv)
            #print res, info[1]
            if res:
                model_dir = info[0]
                model_vars = info[1]
                break
                
        if not model_dir or not models_info:
            continue
            
        count += 1
        
        predictor = gen_predictor(os.path.join(model_dir, 'nnet-params'))
        N = len(model_vars)

        model_min = []
        model_max = []
        with open(os.path.join(model_dir, 'bounds.txt')) as bfile:
            lines = bfile.readlines()
            for line in lines:
                line = line.strip()
                parts = line.split()
                model_min.append(float(parts[1]))  
                model_max.append(float(parts[2]))

#         print model_min
#         print model_max                 
        
Ejemplo n.º 9
0
    def calc_risk(self):
        if "AGE" in values and values["AGE"]:
            age = 30
            try:                  
                age = float(values["AGE"])
            except ValueError:
                pass
            except TypeError:
                pass
            if age < 10 or 50 < age: 
                res_scr.curr_risk_color = [153.0/255, 93.0/255, 77.0/255, 1]
                res_scr.curr_risk_label = 'HIGH RISK'            
                res_scr.curr_risk_level = 1
                sm.current = 'result'
                return        

        # Find highest ranking model that contained in the provided variables
        model_dir = None
        model_vars = None
        vv = set([])
        for k in values:
            if values[k]: vv.add(k)
        print vv 
        for info in models_info: 
            v = set(info[1])
            res = v.issubset(vv)
            #print res, info[1]
            if res:
                model_dir = info[0]
                model_vars = info[1]
                break    
        
        if not model_dir or not models_info:
            res_scr.curr_risk_color = [0.5, 0.5, 0.5, 1]
            res_scr.curr_risk_label = 'INSUFFICIENT DATA'            
            res_scr.curr_risk_level = 0
            sm.transition = RiseInTransition()
            sm.current = 'result'
            return

        print "FOUND MODEL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"     
        print model_dir
        print model_vars
            
        predictor = gen_predictor(os.path.join(model_dir, 'nnet-params'))
        N = len(model_vars)
        
        model_min = []
        model_max = []
        with open(os.path.join(model_dir, 'bounds.txt')) as bfile:
            lines = bfile.readlines()
            for line in lines:
                line = line.strip()
                parts = line.split()
                model_min.append(float(parts[1]))  
                model_max.append(float(parts[2]))

        print model_min
        print model_max 

        v = [None] * (N + 1)
        v[0] = 1
        for i in range(N):
            var = model_vars[i]
            if var in values:
                try:                  
                    v[i + 1] = float(values[var])
                    if var in units and units[var] != var_def_unit[var]:
                        # Need to convert units
                        c, f = var_unit_conv[var]
                        print "convert",var,v[i + 1],"->",f*(v[i + 1] + c)
                        v[i + 1] = f * (v[i + 1] + c)
                except ValueError:
                    pass
                except TypeError:
                    pass

        if None in v:
            res_scr.curr_risk_color = [0.5, 0.5, 0.5, 1]
            res_scr.curr_risk_label = 'INSUFFICIENT DATA'            
            res_scr.curr_risk_level = 0
            sm.current = 'result'
            return

        for i in range(N):
            f = (v[i + 1] - model_min[i]) / (model_max[i] - model_min[i]) 
            if f < 0: v[i + 1] = 0
            elif 1 < f: v[i + 1] = 1
            else: v[i + 1] = f

        print values
        print v

        X = np.array([v])
        probs = predictor(X)
        pred = probs[0]
        print "------------->",pred,type(pred)
        res_scr.curr_risk_level = float(pred)
        if pred < 0.5:
            res_scr.curr_risk_color = [121.0/255, 192.0/255, 119.0/255, 1]
            res_scr.curr_risk_label = 'LOW RISK'
        else:
            level = float((pred - 0.5) / 0.5)
            res_scr.curr_risk_color = [153.0/255, 93.0/255, 77.0/255, 1]
            res_scr.curr_risk_label = 'HIGH RISK' 
        sm.transition = RiseInTransition() 
        #sm.transition = SlideTransition(direction='left')
        sm.current = 'result'