def main(model='NN', web_server=False):

    # use Riot Live Client to check if a game is being played
    time_sleep = checker()

    if not time_sleep:
        return

    open('lock.txt', 'x').close()

    time.sleep(time_sleep)

    if web_server:
        url = 'http://localhost:8000'

        data = web_data(10, model)
        prediction10 = requests.post(url, json=data).text
        print(prediction10)

        time.sleep(300)

        data = web_data(15, model)
        prediction15 = requests.post(url, json=data).text
        print(prediction15)

    else:
        prediction10 = predictor(10, model)
        print(prediction10)

        time.sleep(300)

        prediction15 = predictor(15, model)
        print(prediction15)

    os.remove('lock.txt')
Example #2
0
def train(args):

    from predictor import predictor

    logging.basicConfig(level=logging.INFO, filename="something.log")
    logger = logging.getLogger("temp")

    home_prefix = os.getenv("HOME")
    coding_file = args.coding_file.replace("~", home_prefix)
    non_coding_file = args.non_coding_file.replace("~", home_prefix)
    output_prefix = args.output_prefix

    seeker = predictor()
    seeker.logger = logger
    seeker.train(coding_file, non_coding_file)

    graph = {
        "atrans": seeker.atrans,
        "fe": seeker.fe,
        "config": seeker.model.to_json(),
        "weights": seeker.model.get_weights()
    }

    with open(output_prefix + "_config.pkl", "wb") as f:
        pkl.dump(graph, f)
        logger.info("The configuration has been dumped into " + output_prefix +
                    "_config.pkl")
    def test_make_prediction_on_thread(self):

        # create predictor
        p = predictor(self.predictor_cfg)

        # connect to db
        db = database_handler(self.db_path)

        # get predictor info
        model_info, model_id = p.get_model_info()
        self.assertEqual(model_id, self.model_id)
        self.assertEqual(model_info["predictor_backend"],
                         self.predictor_backend)

        # create prediction
        db.create_prediction(self.prediction_id, model_info, model_id)

        # start prediction on thread
        pred_thread = prediction_thread(self.db_path,
                                        self.image_path,
                                        self.prediction_id,
                                        predictor=p)
        pred_thread.start()

        # wait for prediction
        time.sleep(self.result_wait_time)

        # get prediction result
        pred_json = db.get_prediction_json(self.prediction_id)
        self.assertEqual(pred_json["prediction_status"], 200)
        self.assertNotEqual(pred_json["predictions"], "")
Example #4
0
def predict_new(test_sample, c, path):
        dict={'0.0':0,'1.0':1,'2.0':2,'3.0':3,'4.0':4,'5.0':5,'6.0':6,'7.0':7,'8.0':8,'9.0':9,'a':11,'b':12, 'c':13,'d':14,
              'e':15,'f':16,'g':17,'h':18,'i':19,'j':20,'k':21,'l':22,'m':23,'n':24,'o':25}
        u=c.get('labels')
        if(c.get('kernel')==1):
            ker=kernel.Kernel.gaussian(6)
        elif(c.get('kernel')==0):
            ker=kernel.Kernel.linear()
        else:
            print "kernel in multipredict1 error"

        pp=np.zeros(u.size)
        for k in c.keys():
            if k=='kernel' or k=='labels':
                continue
            i=dict.get(k.split(",")[0])
            j=dict.get(k.split(',')[1])
            #p=predictor.predictor_new(ker,c.get(k),test_sample)
            p1=predictor.predictor(ker,k, path)
            p=p1.predict(test_sample)
            if p==1:

                pp[i]+=1
                #pp[j]-=1
            else:
                pp[j]+=1
                #pp[i]-=1
            #print i,j, p
        print u
        print pp
        return u[np.argmax(pp)]
Example #5
0
def test(args):

    home_prefix = os.getenv("HOME")
    model_file = args.model_file.replace("~", home_prefix)
    input_file = args.input_file.replace("~", home_prefix)
    output_prefix = args.output_prefix

    with open(model_file, "rb") as f:
        configs = pkl.load(f)

    seeker = predictor()
    seeker.fe = configs["fe"]
    seeker.atrans = configs["atrans"]
    seeker.model = model_from_json(configs["config"])
    seeker.model.set_weights(configs["weights"])

    with open(input_file, "r") as f:
        lines = f.readlines()

    seqs = [lines[i + 1][:-1] for i in range(0, len(lines), 2)]
    descs = [lines[i][:-1] for i in range(0, len(lines), 2)]
    probs = [predict_one(seeker, s) for s in seqs]

    with open(output_prefix + ".output", "w") as f:
        f.write("Probability\tDescription\n")
        for i in range(len(descs)):
            f.write("\t".join([str(float(probs[i])), descs[i]]) + "\n")
Example #6
0
def main(ticker):
    data = fetch_data.yahoo_fetcher(ticker)
    series = window_maker.data_filter(data)
    series, normalizer_cache = window_maker.scaler(series)
    Xs, ys = window_maker.windowed_dataset(series, 61, 1, 1)
    x_train, x_test, y_trian, y_test = predictor.split(Xs, ys)
    model = predictor.predictor(x_train, x_test, y_trian, y_test, normalizer_cache)
    predictor.next_day(ticker, normalizer_cache, model)
def overall_prediction(lstm_output, cnn_output, length_and_count_embeddings):
	# joint vector part
	joint_vector = []


	output = predictor.predictor(joint_vector)

	return output
Example #8
0
def predict_new(test_sample, c, path):
    dict = {
        '0.0': 0,
        '1.0': 1,
        '2.0': 2,
        '3.0': 3,
        '4.0': 4,
        '5.0': 5,
        '6.0': 6,
        '7.0': 7,
        '8.0': 8,
        '9.0': 9,
        'a': 11,
        'b': 12,
        'c': 13,
        'd': 14,
        'e': 15,
        'f': 16,
        'g': 17,
        'h': 18,
        'i': 19,
        'j': 20,
        'k': 21,
        'l': 22,
        'm': 23,
        'n': 24,
        'o': 25
    }
    u = c.get('labels')
    if (c.get('kernel') == 1):
        ker = kernel.Kernel.gaussian(6)
    elif (c.get('kernel') == 0):
        ker = kernel.Kernel.linear()
    else:
        print "kernel in multipredict1 error"

    pp = np.zeros(u.size)
    for k in c.keys():
        if k == 'kernel' or k == 'labels':
            continue
        i = dict.get(k.split(",")[0])
        j = dict.get(k.split(',')[1])
        #p=predictor.predictor_new(ker,c.get(k),test_sample)
        p1 = predictor.predictor(ker, k, path)
        p = p1.predict(test_sample)
        if p == 1:

            pp[i] += 1
            #pp[j]-=1
        else:
            pp[j] += 1
            #pp[i]-=1
        #print i,j, p
    print u
    print pp
    return u[np.argmax(pp)]
Example #9
0
 def predict_team():
     print("i was called")
     predict_this = {"team":request.form["team"],
                     "hg":request.form["hg"],
                     "attendance":request.form["attendance"],
                     "hthg":request.form["hthg"],
                     "htag":request.form["htag"]
                     }
     print(predict_this)
     ob = predictor().predict(predict_this)
     return ob
Example #10
0
def process(headline, description):
    tweets_filtered = []
    query = headline + ' ' + description
    prediction = predictor.predictor(query)
    prediction = sorted(prediction, key=lambda i: i[1], reverse=True)
    index = prediction[0][0]
    category = categories[index]
    r = Recommender(query, dataset[category])
    results = r.return_results()
    #category_index =
    return jsonify(results), 200
Example #11
0
 def __init__(self, dim):
     self.dim = dim
     self.predictor = predictor(dim[0], dim[1], dim[2])
     stime = time.time()
     self.arrive_record = [stime for i in range(dim[2])]
     self.elapsed_record = [0. for i in range(dim[2])]
     self.pnext = np.argmax(self.predictor.predict([self._format_data()]))
     self.record = list()
     self.hit = 0
     self.count = 0
     import threading
     self.lock = threading.Lock()
Example #12
0
def process():
    tweets_filtered = []
    headline = request.args.get('headline')
    description = request.args.get('short_description')
    query = headline + ' ' + description
    prediction = predictor.predictor(query)
    prediction = sorted(prediction, key=lambda i: i[1], reverse=True)
    index = prediction[0][0]
    category = categories[index]
    r = Recommender(query, dataset[category])
    results = r.return_results()
    #category_index =
    print(results)
    return jsonify(results), 200
Example #13
0
def predict():
    if request.method == "POST":
        temp = request.values["temperature"]
        humidity = request.values["humidity"]
        weather = request.values["weather"][0:1]
        predict_attr = {"weather": weather, "temp": temp, "humidity": humidity}
        ml_model = predictor.predictor(predict_attr)
        tmrw_demand = int(round(ml_model["tmrw_demand"]))
        score = (round(ml_model["score"], 3)) * 100

        return render_template("predict.html",
                               tmrw_demand=tmrw_demand,
                               score=score)
    else:
        return render_template("wrongaccess.html")
Example #14
0
def main(options):
    """
    Run Phenotype predictor. 
    """

    eff=effects.effects(options["effects"])
    
    if options["read"]:    
        raise Exception("Not implemented yet - todo")
    else: 
        data=snp_data.eigenstrat_data(options["data"], options["pops"], 
                                False, options["inbred"], sparse=0)
    
    pred=predictor.predictor(data, eff)
    pred.print_values()
Example #15
0
def main():
    now = get_now()[0]
    if ret.retrieve_data(lat, lon, unit, points, file_path_new, file_path_old):
        print('GREAT! XML READER EXECUTING...')

        read_output_df = read.read_xml(file_path_new)
        future_df = pred.predictor(read_output_df, DNI_model_fp, DHI_model_fp)

        print(future_df)

        print(pred.write_df(write_df_fp, future_df))
        print('csv updated at: ' + str(now))
    else:
        #NOTE, later I will have the ndfd reader actually return a false in the correct place
        print('error in reading from ndfd')
Example #16
0
 def __init__(self, test_sample,multiclass):
     u=multiclass.u
     self.k=u.size
     pp=np.zeros(self.k)
     for i in range(self.k):
         for j in range(i+1, self.k):
             p1=predictor.predictor(multiclass.kernel,str(u[i])+","+str(u[j]))
             p=p1.predict(test_sample)
             if p==1:
                 pp[i]+=1
             else:
                 #print i, j
                 pp[j]+=1
     print "pp: ", pp
     self.value=u[np.argmax(pp)]
Example #17
0
 def __init__(self, test_sample, multiclass):
     u = multiclass.u
     self.k = u.size
     pp = np.zeros(self.k)
     for i in range(self.k):
         for j in range(i + 1, self.k):
             p1 = predictor.predictor(multiclass.kernel,
                                      str(u[i]) + "," + str(u[j]))
             p = p1.predict(test_sample)
             if p == 1:
                 pp[i] += 1
             else:
                 #print i, j
                 pp[j] += 1
     print "pp: ", pp
     self.value = u[np.argmax(pp)]
Example #18
0
def show_post(post_id):
	# show the post with the given id, the id is an integer
	e=pred.predictor(post_id,"hmm")
	e.train()
	_index=ts.get_hist_data(post_id)

	temp="<body>\n"
	temp+="<p>open:"+str(_index['open'][0])+"</p>"
	temp+="<p>close:"+str(_index['close'][0])+"</p>"
	temp+="<p>ma5:"+str(_index['ma5'][0])+"</p>"
	temp+="<p>ma10:"+str(_index['ma10'][0])+"</p>"
	temp+="<p>ma20:"+str(_index['ma20'][0])+"</p>"
	temp+="<p>prediction result:"+str(e.test())+"</p>"
	#temp+="<p>pred:"+str()+"</p>"
	temp+="</body>"
	return temp;#render_template('dsv.html', post_id=post_id)
Example #19
0
def main():
    num_samples=100
    num_features=2
    samples = np.random.normal(size=num_samples * num_features).reshape(num_samples, num_features)
    labels = 2 * (samples.sum(axis=1) > 0) - 1.0

    svm01=trainer.trainer(kernel.Kernel.linear(), 20, '01')
    svm01.train(samples,labels)
    predictor01=predictor.predictor(samples,labels,kernel.Kernel.linear(),'01')
    print predictor01.predict(np.array([0,0]))
    print predictor01.predict(np.array([-1,-1]))
    print predictor01.predict(np.array([-2,-2]))
    print predictor01.predict(np.array([-5,-5]))

    #plt.subplot(2, 1, 1)
    #plt.scatter(samples[:,0].ravel(), samples[:,1].ravel(), c=labels, alpha=0.5)

    plt.show()
Example #20
0
    def add(choice, lang="python"):
        try:
            from . import predictor
        except:
            import predictor
        name, f = choice

        vobj = predictor.predictor(f)
        ans = vobj.generate_vector()

        ans.append(name)
        try:
            with open("model1/dataset.csv", "a", newline='') as file:
                writer = csv.writer(file)
                writer.writerow(ans)
        except:
            with open("dataset.csv", "a", newline='') as file:
                writer = csv.writer(file)
                writer.writerow(ans)
Example #21
0
def main():

    processList = ['dT', 'kNN', 'rF', 'adaBoost', 'sVM', 'xgBoost']
    #processList = ['dT', 'kNN', 'rF', 'adaBoost', 'sVM']
    count = 0
    ScoreValidBoxPlot = np.ndarray(shape=(5, len(processList)), dtype=float)
    ScoreTestBoxPlot = np.ndarray(shape=(5, len(processList)), dtype=float)
    algoNames = []
    for algo in processList:

        dT = predictor(enableLoggingTime=True)
        fileName = "%s/%sDataProj" % (algo, algo)
        data = dT.loadVariables(fileName=fileName)
        ValScoreList = data['ValScoreList']
        TestScoreList = data['TestScoreList']
        algoName = data['algorithm']
        ScoreValidBoxPlot[:, count] = ValScoreList
        ScoreTestBoxPlot[:, count] = TestScoreList
        algoNames.append(algoName.name)
        count += 1
        #    print ('%s & %0.2f & %s & %s & %s\\\\ \n \hline' % \


#           (state_ind, X_train_not_normalized[i], tmp_2004, \
#            tmp_pred, tmp_GT))
    figName = "All/validationScoreCompare"
    #algoNames = ['DT', 'kNN', 'RF', 'AdaBoost', 'SVM']
    myBoxPlot(ScoreValidBoxPlot,
              algo,
              figName,
              ylim=[0, 1.0],
              title='Validation MCC with different algorithms',
              ylabel='MCC',
              xticks=algoNames)
    figName = "All/testingScoreCompare"
    myBoxPlot(ScoreTestBoxPlot,
              algo,
              figName,
              ylim=[0, 1.0],
              title='Testing MCC with different algorithms',
              ylabel='MCC',
              xticks=algoNames)
Example #22
0
def capture():
    cap = cv2.VideoCapture(0)
    while (True):
        ret, frame = cap.read()

        frame = cv2.flip(frame, 1)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        edges = cv2.Canny(frame, 100, 200)
        roi = cropped(edges)

        keypress = cv2.waitKey(1)
        if keypress == ord('q'):
            break
        if keypress == ord('s'):
            save(roi)
            value = predictor()
            print(value)
        cv2.imshow("ROI", roi)
    cap.release()
    cv2.destroyAllWindows()
Example #23
0
 def __init__(self, test_sample):  # u is the array of  unique labels
     u = np.load('multipliers/labels.npz')['ulabels']
     if (np.load('multipliers/labels.npz')['k'] == 1):
         k = kernel.Kernel.gaussian(6)
     else:
         print "kernel in multipredict1 error"
     self.k = u.size
     pp = np.zeros(self.k)
     for i in range(self.k):
         for j in range(i + 1, self.k):
             p1 = predictor.predictor(k, str(u[i]) + "," + str(u[j]))
             p = p1.predict(test_sample)
             #print u[i],u[j], p
             if p == 1:
                 pp[i] += 1
                 pp[j] -= 1
             else:
                 #print i, j
                 pp[j] += 1
                 pp[i] -= 1
     print u
     print pp
     self.value = u[np.argmax(pp)]
Example #24
0
 def __init__(self, test_sample):   # u is the array of  unique labels
     u=np.load('multipliers/labels.npz')['ulabels']
     if(np.load('multipliers/labels.npz')['k']==1):
         k=kernel.Kernel.gaussian(6)
     else:
         print "kernel in multipredict1 error"
     self.k=u.size
     pp=np.zeros(self.k)
     for i in range(self.k):
         for j in range(i+1, self.k):
             p1=predictor.predictor(k,str(u[i])+","+str(u[j]))
             p=p1.predict(test_sample)
             #print u[i],u[j], p
             if p==1:
                 pp[i]+=1
                 pp[j]-=1
             else:
                 #print i, j
                 pp[j]+=1
                 pp[i]-=1
     print u
     print pp
     self.value=u[np.argmax(pp)]
Example #25
0
def update_output_div(input_value):
    location = geolocator.geocode(input_value)
    if location is None:
        return [html.P("Not found!")]

    prediction = predictor(lat = location.latitude, lon = location.longitude, severity = "Severe")
    closest_infrastructure = closest(lat = location.latitude, lon = location.longitude, n_samples = 1)

    investor_str = '''  Company name: {0}
                        Number of employees: {1}
                        Main product: {2}'''.format(
    location.longitude,
    location.latitude,
    prediction[0]
    )

    return [
        html.P(f"Longitude: {location.longitude}"),
        html.P(f"Latitude: {location.latitude}"),
        html.P(f"Cyclists at risk? {prediction[0]}"),
        html.P(f"Pedestrians at risk? {prediction[1]}"),
        html.P("Closest infrastructure:"),
        dataframe_to_table(closest_infrastructure)
    ]
    predictorSquaredErrors = []
    baselineSquaredErrors = []

    for i in range(n):
        #generate the testing and training sets for this fold of the validations
        testing = allbins[i]
        training = []
        for bin in allbins:
            if bin != testing:
                training.extend(bin)  # add the bin to the training set if it is not the testing bin, which yields n-1 bins for training and 1 bin for testing

        model = buildModel(training, args.attributes)

        for tweet in testing:
            prediction = predictor(tweet, model)
            actual = tweet['score']

            squaredError = (prediction - actual) ** 2
            predictorSquaredErrors.append(squaredError)

            baselineSquaredError = actual ** 2
            baselineSquaredErrors.append(baselineSquaredError)

    predictorMSE = mean(predictorSquaredErrors)
    baselineMSE = mean(baselineSquaredErrors)

    improvement = ((baselineMSE - predictorMSE) / baselineMSE) * 100
    improvements.append(improvement)

    print "Baseline mean squared error: " + str(baselineMSE)
from predictor import predictor
while True:
    print(predictor(input('enter url: ')))
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--embfile", type=str, help="The path of .emb file")
parser.add_argument("-dgf", "--drugfile", type=str, help="The path of drug id file")
parser.add_argument("-dsf", "--diseasefile", type=str, help="The path of one disease id file")
parser.add_argument("-mf", "--modelfile", type=str, help="The path of model file")
parser.add_argument("-o", "--outpath", type=str, help="The output path")

args = parser.parse_args()

graph = pd.read_csv(args.embfile, sep='\t', header=None)
graph = graph.set_index([0])
drug_curie_list = list(pd.read_csv(args.drugfile, sep='\t', header=0)['id'])
disease_curie_list = list(pd.read_csv(args.diseasefile, sep='\t', header=None)[0])

## build up the prediction model
pred = predictor(model_file=args.modelfile)

## pre-create an array of all drugs which will be used in create_array function.
drug_array = graph.loc[drug_curie_list, :].to_numpy()

def create_array(curie):

    #print(curie, flush=True)
    disease_array = graph.loc[[curie for _ in range(len(drug_curie_list))], :].to_numpy()
    return np.multiply(disease_array, drug_array)


array_list = [elem for elem in map(create_array, disease_curie_list)]
X = np.concatenate(array_list)
all_prob = list(pred.prob(X)[:, 1])
disease_col = list(itertools.chain.from_iterable(itertools.repeat(x, len(drug_curie_list)) for x in disease_curie_list))
Example #29
0
def start_loop(predictor, example):
    """
    The Prediction loop. This is where the logic happens.

    :input predictor: the predictor function. def predictor(inputs=[], batch_size=8)
    :input example: a pickled json of the example input.

    This function starts a loop. Does not return anything.
    """

    # warmup
    _utils.warmup(predictor, example)

    # find optimal batch size and get_time_per example
    batch_size, time_per_example = _utils.find_optimum_batch_sizes(
        predictor, example)

    max_wait_time = time_per_example * _utils.MAX_WAIT

    # write batch size to temp file for use in generating _run.sh
    os.system(f"echo {batch_size} > {_utils.batch_size_file_path}")

    # list of files/data to be processed is tracked here.
    to_process = None

    _utils.logger.info("Starting prediction loop")

    last_paused_time = 0
    while True:
        time.sleep(_utils.PREDICTION_LOOP_SLEEP)
        # Get the latest list of to process data
        to_process = _utils.get_to_process_list(_utils.FILE_MODE)

        if not to_process:
            continue

        _utils.logger.info(f"{len(to_process)} inputs left in queue.")

        if len(to_process) < batch_size - 1:
            # start the wait
            if not last_paused_time:
                last_paused_time = time.time()
                _utils.logger.info(f"Waiting for more inputs for batching.")
                continue
            # if waiting for less than max_wait_time, continue waiting
            if time.time() - last_paused_time < max_wait_time:
                _utils.logger.info(f"Waiting for more inputs for batching.")
                continue

        # waiting completed
        last_paused_time = 0

        # The "batch" here is a batch of inputs.
        # since, each input might contain more than one example (client side batching)
        # we pass the batch_size paramter to predictor
        # this is especially helpfull for most of the major deep learning libraries
        # that accept batch_size as a parameter to predict call
        # TLDR; predictor function should respect a parameter named batch_size
        for batch in _utils.get_batch(to_process, batch_size):
            _utils.logger.info(f"Processing batch with unique_ids: {batch}")

            # in_data will contain flattened list of user inputs.
            # batch = [['1', '2'], ['3'], ['4,5,6']] will result in
            # in_data = [1, 2, 3, 4, 5, 6]
            # number_of_examples_per_req = [2, 1, 3]
            # This way, we can pass the in_data to predictor function with above calculated batch_size
            # later, we can use number_of_examples_per_req to re-order preds in to batches.
            in_data = []
            number_of_examples_per_req = []
            for i, in_path in enumerate(batch):
                try:
                    if _utils.FILE_MODE:
                        in_list = glob.glob(in_path + "/*")
                    else:
                        in_list = pickle.load(open(in_path, "rb"))

                    in_data += in_list
                    number_of_examples_per_req.append(len(in_list))

                except Exception as ex:
                    batch[i] = None

            batch = [example for example in batch if example is not None]

            if len(in_data) == 0:
                continue

            try:
                results = predictor(in_data, batch_size=batch_size)
            except Exception as ex:
                _utils.logger.exception(ex, exc_info=True)
                results = [str(ex) for _ in in_data]

            for i, in_path in enumerate(batch):
                # we use number_of_examples_per_req to re-order preds in to batches.
                # result is the list of preds for the current batch
                result = results[:number_of_examples_per_req[i]]
                # remove current batch from list of all predictions
                results = results[number_of_examples_per_req[i]:]

                _in_data = in_data[:number_of_examples_per_req[i]]
                in_data = in_data[number_of_examples_per_req[i]:]

                if _utils.FILE_MODE:
                    _in_data = [os.path.basename(j) for j in _in_data]
                    remove_till = _in_data[0].index(".") + 1
                    _in_data = [j[remove_till:] for j in _in_data]

                    result = {
                        in_sub_path: sub_result
                        for in_sub_path, sub_result in zip(_in_data, result)
                    }
                    os.system(f"rm -rf {in_path}")

                    in_path = in_path[:-4]
                else:
                    os.system(f"rm -rf {in_path}")

                res_path = _utils.in_path_to_res_path(in_path)

                pickle.dump(result, open(res_path, "wb"), protocol=2)

                _utils.logger.info(f"result written for {res_path}")
                _utils.create_symlink_in_ram(res_path)
Example #30
0
def main():

    #processList = ['xgBoost']
    printConfMat = False
    processList = ['dT', 'kNN', 'rF', 'adaBoost', 'sVM', 'xgBoost']
    count = 0
    for algo in processList:

        dT = predictor(enableLoggingTime=True)
        fileName = "%s/%sDataProj" % (algo, algo)
        data = dT.loadVariables(fileName=fileName)
        ValScoreList = data['ValScoreList']
        ValScoreStdList = data['ValScoreStdList']
        TestScoreList = data['TestScoreList']
        TestConfList = data['TestConfList']
        bestParamList = data['bestParamList']
        scoring = data['scoring']
        scoring = scoring.name

        # Fold data [OuterFoldNo][ParamListIndex][Accu/Conf][InnerFoldNo]
        OuterInnerFoldData = data['OuterInnerFoldData']
        sweepingList = data['sweepingList']
        NoOfParam = len(sweepingList)
        print NoOfParam
        OuterFoldNo = data['OuterFoldNo']
        InnerFoldNo = data['InnerFoldNo']
        bestParamIndexInSwpList = data['bestParamIndexInSwpList']

        print("Fold no - Outer %d, Inner %d\n" % (OuterFoldNo, InnerFoldNo))
        #print TestAccuList
        print("Sweeping param list: %s\n" % (sweepingList))
        #print( "Each Inner Fold Size: %d\n" % len(eachInnerFold[0][1]) )
        print("best Params: %s\n" % (bestParamList))
        print("best Params List index in paramList : %s\n" %
              (bestParamIndexInSwpList))
        print("Outer Fold Size: %d\n" % len(OuterInnerFoldData))

        ScoreBoxPlot = np.ndarray(shape=(InnerFoldNo, OuterFoldNo),
                                  dtype=float)
        # Fold 1
        for outI in range(OuterFoldNo):
            print("Fold #%d\n" % (outI))
            FoldData = OuterInnerFoldData[outI]
            bestParamScore = np.array(
                FoldData[bestParamIndexInSwpList[outI]][0])
            ScoreBoxPlot[:, outI] = bestParamScore
            bestParamConf = np.array(
                FoldData[bestParamIndexInSwpList[outI]][3])
            print("\tBest param Avg. Valid. Score = %0.8f\n" %
                  (np.mean(bestParamScore)))
            print("\tBest param Valid. Score. = \t\t")
            print bestParamScore

            # mean of accuracy for all param in outer fold
            FoldAllAvgScore = np.ndarray(shape=(NoOfParam), dtype=float)
            for paramI in range(NoOfParam):
                paramAllScore = np.array(FoldData[paramI][0])
                paramMeanScore = paramAllScore.mean()
                FoldAllAvgScore[paramI] = paramMeanScore
            printForLatexTable(FoldAllAvgScore, outI)
            if printConfMat:
                for inn in range(InnerFoldNo):
                    fileName = "%s/O%d_I%d_conf" % (algo, outI, inn)
                    dT.printConfusionMatrix(bestParamConf[inn],
                                            filename=fileName)
                fileName = "%s/Test_O%d_conf" % (algo, outI)
                dT.printConfusionMatrix(TestConfList[outI], filename=fileName)
        printForLatexTableValidTest(ValScoreList, TestScoreList)
        print ValScoreList
        #print AccuracyBoxPlot
        # Create a figure instance
        figName = "%s/%s_bestParamValidScore.eps" % (algo, algo)
        myBoxPlot(ScoreBoxPlot,
                  algo,
                  figName,
                  ylim=[0, 1.0],
                  title='%s with optimal params in Validation Set' % (scoring),
                  ylabel='MCC')
        figName = "%s/%s_testingScore.eps" % (algo, algo)
        myPlot(TestScoreList,
               algo,
               figName,
               ylim=[0, 1.0],
               xlabel='Outer Fold No.',
               ylabel='MCC',
               title='%s with optimal params in Testing Set' % (scoring))
        count += 1
Example #31
0
def main():
    capture()
    predictor()
Example #32
0
    cl2.fit(train[label], train["Survived"])
    cl3.fit(train[label], train["Survived"])
    cl4.fit(train[label], train["Survived"])
    cl5.fit(train[label], train["Survived"])
    cl6.fit(train[label], train["Survived"])
    rf.fit(train[label], train["Survived"])

    test_predict = pd.DataFrame.copy(test)
    test_predict["Survived"] = rf.predict(test_predict[label])
    return test_predict


func_train = util.adaptData
func_test = util.adaptData
na = util.getNumAdaptData()
if na == 1:
    label = np.asarray(['Pclass', 'Sex', 'Age', 'SibSp', 'Parch'])
elif na == 2:
    label = np.asarray(['Pclass', 'Sex', 'Age', 'Fare'])
elif na == 5:
    label = np.asarray([
        "Age", "Pclass", "Sex", "SibSp", "Parch", "Fare_bin", "EC", "EQ", "ES",
        "Family", "Title", "Deck", "ASP"
    ])
else:
    label = util.getParam()
model = model_ensemble
path = "../Predictions/ensemble.csv"

p.predictor(func_test, func_test, label, model, path)
Example #33
0
from celery import Celery
from socket import gethostname
from predictor import predictor
from gcloud import datastore
clientds = datastore.Client()
key = clientds.key('booktable')
hostnm = gethostname()
import time

app = Celery('predictor', backend='amqp')

pred = predictor()

	
#define the functions we will call remotely here
@app.task
def predict(abstract, title, source):
	prediction = pred.predict(statement, source)
	entity = datastore.Entity(key=key)
	entity['partition'] = hostname'
	entity['date'] = str(time.time())
	entity['title' ] = title
	entity['prediction'] = str(prediction)
	clientds.put(entity)
	return [prediction]
Example #34
0
    if grid_elt is None:
        eclf1 = VotingClassifier(estimators=[('lr', clf1), ('gb', clf2),
                                             ('knn', clf3)],
                                 voting='soft',
                                 weights=[1, 1, 1])
    else:
        eclf1 = VotingClassifier(estimators=[('lr', clf1), ('gb', clf2),
                                             ('knn', clf3)],
                                 voting='soft',
                                 weights=grid_elt)

    eclf1.fit(train[label], train['hotel_cluster'])

    prediction = eclf1.predict_proba(test[label])

    return util.best_proba(prediction), eclf1


if __name__ == '__main__':

    if util.getPCA():
        label = util.getParam()
    else:
        label = util.getParam()

    model = model_voting
    path = "../Predictions/voting.csv"

    p.predictor(label, model, path)
        from QueryCOHD import QueryCOHD

from COHDUtilities import COHDUtilities
import SimilarNodesInCommon
import CustomExceptions
import numpy as np
import fisher_exact
import NormGoogleDistance
NormGoogleDistance = NormGoogleDistance.NormGoogleDistance()
# TODO: Temp file path names etc
sys.path.append(
    os.path.join(os.path.dirname(os.path.abspath(__file__)),
                 'MLDrugRepurposing/FWPredictor'))
import predictor
p = predictor.predictor(
    model_file=os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'MLDrugRepurposing/FWPredictor/LogModel.pkl'))
p.import_file(None,
              graph_file=os.path.join(
                  os.path.dirname(os.path.abspath(__file__)),
                  'MLDrugRepurposing/FWPredictor/rel_max.emb.gz'),
              map_file=os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                    'MLDrugRepurposing/FWPredictor/map.csv'))


class SMEDrugRepurposingFisher:
    def __init__(self):
        None

    @staticmethod
    def answer(disease_id, use_json=False, num_show=25):