示例#1
0
def main(argv):
    args = parser.parse_args(argv[1:])
    batch_size = args.batch_size

    (train_x, train_y), (test_x, test_y), unlabeled = meo_data.load_data()

    # construct classifier
    classifier = tf.estimator.Estimator(model_fn=model.story_model,
                                        params={
                                            'feature_columns':
                                            fc.story_model_columns(
                                                train_x, test_x, unlabeled),
                                            'n_classes':
                                            args.classes,
                                        })

    # train model
    classifier.train(
        input_fn=lambda: meo_data.train_input_fn(train_x, train_y, batch_size),
        steps=args.train_steps)

    # evaluate and print results
    eval_result = classifier.evaluate(
        input_fn=lambda: meo_data.eval_input_fn(test_x, test_y, batch_size))
    m.print_eval(eval_result)

    # predict classes in test data, print a random sample
    p.predict(classifier, test_x, test_y, unlabeled, batch_size)
示例#2
0
def main(argv):
    args = parser.parse_args(argv[1:])
    batch_size = args.batch_size

    (train_x, train_y), (test_x, test_y), unlabeled = meo_data.load_data()

    # construct classifier
    classifier = tf.estimator.Estimator(
        model_fn=model.story_model,
        params={
            'feature_columns': fc.story_model_columns(train_x, test_x,
                                                      unlabeled),
            'n_classes': args.classes,
        })

    # train model
    classifier.train(
        input_fn=lambda: meo_data.train_input_fn(train_x, train_y, batch_size),
        steps=args.train_steps)

    # evaluate and print results
    eval_result = classifier.evaluate(
        input_fn=lambda: meo_data.eval_input_fn(test_x, test_y, batch_size))
    m.print_eval(eval_result)

    # predict classes in test data, print a random sample
    p.predict(classifier, test_x, test_y, unlabeled, batch_size)
示例#3
0
def predict(species, data_name):
    '''
    This function makes use of the predictions file to predict the
    reliability of a given set of observations using a pre trained model.
    :param species:
    :param data_name:
    :return:
    '''
    p.predict(species, data_name)
    cwd = os.getcwd()
    os.remove(os.path.join(cwd, 'temp.csv'))
示例#4
0
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            predicts = predictions.predict(
                os.path.join(app.config['UPLOAD_FOLDER'], filename))
            facts = get_poke_facts.get_facts(predicts[0])
            print(facts)
            return render_template("pokemon.html",
                                   facts=facts,
                                   pokemon_name=predicts[0],
                                   image_data=predicts[1],
                                   pokemon_percentage=predicts[2],
                                   image_pokemon=predicts[3])
            #return 'Jeg tror det er en: {}'.format(str(predicts[0]))
    return render_template("upload.html", )
示例#5
0
文件: server.py 项目: belya/troll2vec
def predict():
    messages = request.get_json(force=True)
    messages = delete_empty_messages(messages)
    keys = list(messages.keys())
    values = [messages[key] for key in keys]
    if values:
        toxicity = predictions.predict(values)
        toxic_messages = {
            keys[index]: float(toxic)
            for index, toxic in enumerate(toxicity)
        }
        return jsonify(toxic_messages)
    else:
        return jsonify([])
示例#6
0
def query():
    if request.method == 'GET':
        error = 0
        error_msg = ''
        q = request.args.get('q')
        if q:
            result = ip_info.find_one({'ip': q})
            if result:
                results = {
                    'ip': result['ip'],
                    'country': result['country'],
                    'city': result['city'],
                    'country_id': result['country_id']
                }
            else:
                result = otx.get_indicator_details_full(IndicatorTypes.IPv4, q)
                if result:
                    results = {
                        'ip': result['general']['indicator'],
                        'country': result['general']['country_name'],
                        'city': result['general']['city']
                    }
                    ip.search_ip(q)
                else:
                    results = {}
                    error = 1
            if error:
                city_pre = ''
            else:
                city_pre = predictions.predict(results['city'])
                city_pre = city_pre[0:2]
                result = []
                for cp in city_pre:
                    r = ip_info.find({'city': cp[0]})
                    for rs in r[0:10]:
                        result.append(rs)
            return render_template('index.html',
                                   q=q,
                                   error=error,
                                   error_msg=error_msg,
                                   results=results,
                                   pre=result,
                                   city_pre=city_pre)
        else:
            return render_template('index.html')
示例#7
0
    def post(self, request):
        form = PortfolioForm(request.POST)
        if form.is_valid():
            holding = form.cleaned_data['holding']
            if holding != 0:
                span = 'Short-Term'
            else:
                span = 'Long-Term'

            #asset1
            asset1 = form.cleaned_data['asset1']
            name1 = dict(form.fields['asset1'].widget.choices)[asset1]
            weight1 = form.cleaned_data['weight1']

            # asset2
            asset2 = form.cleaned_data['asset2']
            name2 = dict(form.fields['asset2'].widget.choices)[asset2]
            weight2 = form.cleaned_data['weight2']

            # asset3
            asset3 = form.cleaned_data['asset3']
            name3 = dict(form.fields['asset3'].widget.choices)[asset3]
            weight3 = form.cleaned_data['weight3']

            # asset4
            asset4 = form.cleaned_data['asset4']
            name4 = dict(form.fields['asset4'].widget.choices)[asset4]
            weight4 = form.cleaned_data['weight4']

            # Short-term holding
            if span == 'Short-Term':
                start_date = datetime.today() + timedelta(days=-100)
                end_date = datetime.today()
                #holidays = get_calendar('USFederalHolidayCalendar').holidays(start_date, end_date)
                #period = [x for x in period if x not in holidays.date]
                #period = pd.DatetimeIndex(period)
                prices1 = web.DataReader(asset1, 'yahoo', start_date, end_date)
                df1 = pd.DataFrame(predict(prices1, holding))
                df1.rename(columns={df1.columns[0]: 'Close1'}, inplace=True)

                prices2 = web.DataReader(asset2, 'yahoo', start_date, end_date)
                df2 = pd.DataFrame(predict(prices2, holding))
                df2.rename(columns={df2.columns[0]: 'Close2'}, inplace=True)

                prices3 = web.DataReader(asset3, 'yahoo', start_date, end_date)
                df3 = pd.DataFrame(predict(prices3, holding))
                df3.rename(columns={df3.columns[0]: 'Close3'}, inplace=True)

                prices4 = web.DataReader(asset4, 'yahoo', start_date, end_date)
                df4 = pd.DataFrame(predict(prices4, holding))
                df4.rename(columns={df4.columns[0]: 'Close4'}, inplace=True)

            #Long-term Holding
            else:
                start_date = form.cleaned_data['start_date']
                end_date = form.cleaned_data['end_date']
                df1 = web.DataReader(asset1, 'yahoo', start_date, end_date)
                df2 = web.DataReader(asset2, 'yahoo', start_date, end_date)
                df3 = web.DataReader(asset3, 'yahoo', start_date, end_date)
                df4 = web.DataReader(asset4, 'yahoo', start_date, end_date)

                df1 = pd.DataFrame({'Close1': df1['Close']})
                df2 = pd.DataFrame({'Close2': df2['Close']})
                df3 = pd.DataFrame({'Close3': df3['Close']})
                df4 = pd.DataFrame({'Close4': df4['Close']})


            portfolio_prices = df1.merge(df2, left_index=True, right_index=True) \
                .merge(df3, left_index=True, right_index=True) \
                .merge(df4, left_index=True, right_index=True)

            print portfolio_prices

            period = pd.bdate_range(start_date, end_date).date

            weights = []
            weights.append(weight1)
            weights.append(weight2)
            weights.append(weight3)
            weights.append(weight4)

            opti_model = MarkowitzOptimize(portfolio_prices, weights)
            new_weights = opti_model.minimizeSharpeRatio()

            attributes = list(portfolio_prices.columns.values)
            return_prices = portfolio_prices / portfolio_prices.iloc[0]
            return1 = return_prices[attributes].mul(weights).sum(1)

            portfolio = pd.DataFrame(portfolio_prices)
            attributes = list(portfolio.columns.values)
            portfolio = portfolio[attributes].sum(1)
            return2 = portfolio / portfolio.iloc[0]

            ts_list = period.tolist()
            date_string = [str(date) for date in ts_list]

        args = {
            'form': form,
            'start_date': start_date,
            'end_date': end_date,
            'name1': name1,
            'name2': name2,
            'name3': name3,
            'name4': name4,
            'new_weights1': new_weights[0],
            'new_weights2': new_weights[1],
            'new_weights3': new_weights[2],
            'new_weights4': new_weights[3],
            'values1': return1.values.tolist(),
            'values2': return2.values.tolist(),
            'dates': date_string
        }

        return render(request, 'portimize/results.html', args)
示例#8
0
def predict():
    data = request.json
    return predictions.predict(data)
    description=
    'Query for twitter mining, can be "search" or @username or #hashtag')
parser.add_argument('-q', '--query', help='Add your query', required=False)
parser.add_argument('-d', '--debug', help='Debug', required=False)
parser.add_argument('--all',
                    help='Model Selection',
                    required=False,
                    action='store_true')
args = parser.parse_args()

if __name__ == '__main__':
    if args.query is None:
        text = input("Enter Query: ")
    else:
        text = args.query
    if args.debug:
        debug = True
    if args.all:
        accuracy = False
    else:
        accuracy = True

    tweets = findTweets(text)
    predictions = predict(tweets[0], debug=debug, accuracy=accuracy)
    for t, p in zip(tweets[1], predictions):
        print('-' * 80)
        print("Tweet:")
        print('')
        print(t, " \n### Predicted Sentiment[neg, pos]: ", p)
    # print(predictions)
示例#10
0
        parsed = json.loads(lines[0])
        return (parsed)


params = read_in()

#물가 예상
price_index = pr.index_predict(params["startdate"], params["year"],
                               params["price_index"])
price_index.name = "price_index"
solar_index = pr.index_predict(params["startdate"], params["year"],
                               params["solar_index"])
solar_index.name = "solar_index"

#수입예상 및 전체적인 지표구성
revenue = pr.predict(params["scene"], params["startdate"], params["year"])
revenue["rec_price"] = 100
revenue["days"] = revenue.index.day
start = pd.to_datetime(params["startdate"], format='%Y-%m-%d',
                       errors='ignore')  #초기 기간 설정
startday = start.date().timetuple()
revenue.days[0] = revenue.days[0] - startday.tm_mday
revenue.days[revenue.shape[0] - 1] = startday.tm_mday

revenue = pd.concat([revenue, price_index, solar_index], axis=1)
revenue["generation"] = revenue['days'] * params['size'] * params[
    'average_time'] * revenue["solar_index"]
revenue['smp_revenue'] = revenue['smp_price'] * revenue['generation']
revenue['rec_revenue'] = revenue['rec_price'] * revenue['generation'] * params[
    'weight']
revenue["smp_revenue"] = revenue["smp_revenue"].astype(int)
示例#11
0
# Init file
# All occurs here
# Execute this file tu start your machine

import sys
import training
import predictions

# Main Program
if __name__ == '__main__':
    X_train, X_validation, Y_train, Y_validation = training.evaluate_data()

    if 'plot' in str(sys.argv):
        training.show_plots()

    if 'predict' in str(sys.argv):
        predictions.predict(X_train, X_validation, Y_train, Y_validation)
示例#12
0
                  type="denac2",
                  _timebloc=timebloc,
                  n_scans_use=vd['num_scans_use'],
                  _shuffle=vd['shuffle_samples'],
                  _reduce=vd['reduced_timesteps'],
                  _avgpath=vd['path_to_avg'])
'''Callbacks and model fit'''
if (vd['UseObjective'] == 0 or vd['UseObjective'] == 1):
    chkpt = ModelCheckpoint(vd['Modelpath'],
                            monitor='loss',
                            mode='min',
                            save_best_only=True,
                            verbose=1)
    lrs = LearningRateScheduler(helpers.scheduler)

    foo.model.fit(doo,
                  epochs=vd['epochs'],
                  verbose=1,
                  callbacks=[chkpt, lrs],
                  max_queue_size=vd['max_queue'])
'''Predictions'''
if (vd['UseObjective'] == 2):
    predict(model=foo.model,
            doo=doo,
            type=vd['UseCase'],
            predsavepath=vd['predsavepath'],
            scaler=doo.scaler)

# '''Testing and Validation'''
# # test(doo, type = "denac" ,model_path = "post/model_den2.h5", item = 5772)