Пример #1
0
def process(search_code):
    data = fetch_data(search_code)
    matched_sessions = filter(data)
    if matched_sessions:
        playsound("src/Rooster.mp3")
    else:
        print("No Match found")
Пример #2
0
def process(district_code):
    data = fetch_data(district_code)
    matched_sessions = filter(data)
    if matched_sessions:
        pass
#         filename = '/tmp/sessions.csv'
#         write_data(filename, matched_sessions)
#         send_email(filename)
#         send_data(matched_sessions)
    else:
        print("No Match found")
Пример #3
0
def post_rec():
    if request.args.get('max_price', '') != '':
        max_price = float(re.sub("[\$]", "", request.args.get('max_price',
                                                              '')))
    else:
        max_price = None
    if request.args.get('min_price', '') != '':
        min_price = float(re.sub("[\$]", "", request.args.get('min_price',
                                                              '')))
    else:
        min_price = None
    if request.args.get('movein', '') != '':
        movein = datetime.strptime(request.args.get('movein', ''), '%Y-%m-%d')
    else:
        movein = None
    if request.args.get('work', '') != '':
        work = str(request.args.get('work', ''))
    else:
        work = None
    # print str(request.args.get('local', '')), len(str(request.args.get('local', '')))
    if request.args.get('local', '') in types:
        local = str(request.args.get('local', ''))
    else:
        local = None
    neighborhoods = request.args.getlist('neighborhood[]')
    attributes = request.args.getlist('attributes[]')
    description = re.sub(r'\\[ntr]', ' ', request.args.get('description', ''))
    description = re.sub('\\s+', ' ', description)
    input = [
        max_price, min_price, movein, neighborhoods, attributes, description,
        work, local
    ]
    keep = filter(listings, input)
    filtered_listings = listings.ix[keep]
    match = cluster(filtered_listings, description, keep)
    df_match = listings.ix[match]
    df_match = df_match[[
        'title', 'price', 'neighborhood', 'movein', 'attributes',
        'description', 'latitude', 'longitude'
    ]]
    # print input[6], input[7]
    if bool(input[6] and input[7]):
        final_listings = add_gmaps_cols(df_match, input[6], input[7])
        json = final_listings.to_json()
        return recpage(json)
    else:
        json = df_match.to_json()
        return recpage(json)
Пример #4
0
def main():
    [X_train, y_train, X_test, y_test] = example0()
    valid_col = filter(X_train)
    print len(valid_col)
    valid_col = dimension_reduce(X_train, valid_col)
    print len(valid_col)
    X_train = format(X_train, valid_col)
    X_test = format(X_test, valid_col)

    N, sl = X_train.shape
    num_classes = len(np.unique(y_train))
    """Hyperparamaters"""
    batch_size = 128
    max_iterations = 1000
    dropout = 0.8
    config = {
        'num_layers': 3,  #number of layers of stacked RNN's
        'hidden_size': 128,  #memory cells in a layer
        'max_grad_norm': 5,  #maximum gradient norm during training
        'batch_size': batch_size,
        'learning_rate': .003,
        'sl': sl,
        'num_classes': num_classes
    }

    epochs = np.floor(batch_size * max_iterations / N)
    print('Train %.0f samples in approximately %d epochs' % (N, epochs))

    model = Model(config)
    """Session time"""
    sess = tf.Session()
    sess.run(model.init_op)

    cost_train_ma = -np.log(
        1 / float(num_classes) + 1e-9)  #Moving average training cost
    acc_train_ma = 0.0
    for i in range(max_iterations):
        X_batch, y_batch = sample_batch(X_train, y_train, batch_size)
        cost_train, acc_train, _ = sess.run(
            [model.cost, model.accuracy, model.train_op],
            feed_dict={
                model.input: X_batch,
                model.labels: y_batch,
                model.keep_prob: dropout
            })
        cost_train_ma = cost_train_ma * 0.99 + cost_train * 0.01
        acc_train_ma = acc_train_ma * 0.99 + acc_train * 0.01

        #Evaluate validation performance
        if i % 20 == 0:
            X_batch, y_batch = sample_batch(X_test, y_test, batch_size)
            cost_val, summ, acc_val = sess.run(
                [model.cost, model.merged, model.accuracy],
                feed_dict={
                    model.input: X_batch,
                    model.labels: y_batch,
                    model.keep_prob: 1.0
                })
            print(
                'At %5.0f/%5.0f: COST %5.3f/%5.3f(%5.3f) -- Acc %5.3f/%5.3f(%5.3f)'
                % (i, max_iterations, cost_train, cost_val, cost_train_ma,
                   acc_train, acc_val, acc_train_ma))
            plt.plot(i, acc_train, 'r*')
            plt.plot(i, cost_train, 'kd')

    cost_val, summ, acc_val = sess.run(
        [model.cost, model.merged, model.accuracy],
        feed_dict={
            model.input: X_test,
            model.labels: y_test,
            model.keep_prob: 1.0
        })
    epoch = float(i) * batch_size / N
    print('Trained %.1f epochs, accuracy is %5.3f and cost is %5.3f' %
          (epoch, acc_val, cost_val))
    plt.xlabel('Iteration')
    plt.ylabel('Accuracy & Cost')
    plt.show()