예제 #1
0
def single_emp():
    # create instance of PredictionForm class
    form = PredictionForm()
    # if the WTForm validators validate:
    if form.validate_on_submit():
        # read and preprocess the form data
        data = read_prediction_form_data(form)
        prep_data = preprocess_prediction_form_data(data)
        # unpickle the model
        model = import_model()
        # predict probability of quitting
        y_pred = round(model.predict_proba(prep_data)[0][1] * 100, 2)
        # write user input to database for future reference
        write_prediction_form_data(data, y_pred)
        # given the predicted proba, what is the best course of action?
        # use the giverecommendation function to find out
        text = give_recommendation(y_pred, model, prep_data)
        # show results
        if len(text) > 1:
            return render_template('single_results.html',
                                   perc=y_pred,
                                   text1=text[0],
                                   text2=text[1],
                                   sentences=text[2:len(text)],
                                   num3='12%',
                                   num4='12%',
                                   num5='12%')
        else:
            return render_template('single_results.html',
                                   perc=y_pred,
                                   text1=text[0])

    return render_template('single_form.html', form=form)
예제 #2
0
def main():
    form = PredictionForm()
    if form.validate_on_submit():
        prediction = client.predict(form.precip.data, form.snow.data,
                                    form.tavg.data, form.tmax.data,
                                    form.tmin.data)
        flash('Login requested for user {}, remember_me={}, {}'.format(
            form.precip.data, form.snow.data, love))
        return redirect('/main')
    return render_template('index.html', form=form)
예제 #3
0
def predict():
    """ Prediction Form """
    form = PredictionForm()
    players = Player.query.order_by(Player.name).all()

    if form.validate_on_submit():

        # Redirect to a prediction between two players
        p1 = Player.query.filter_by(name=form.player1.data).first()
        p2 = Player.query.filter_by(name=form.player2.data).first()
        return redirect(url_for('prediction', p1=p1.id, p2=p2.id))

    return render_template('predict.html',
                           form=form,
                           players=players,
                           title='New Prediction')
예제 #4
0
    def prediction():
        title = 'Введите данные клиента'
        form = PredictionForm()
        if form.validate_on_submit():
            # if request.form.post['predict_btn'] == 'qqq':
            # flash(request.form.post['predict_btn'])

            json_data = preprocess_form_data(form.data)
            proba = get_probability(json_data)
            #     form.probability.data = proba
            proba_massage = round(float(proba[1:-1]), 3) * 100
            prediction_exists = Predictions.query.filter(
                Predictions.customer_id == form.customer_id.data).count()
            if not prediction_exists:
                new_prediction = Predictions(
                    customer_id=form.customer_id.data,
                    gender=form.gender.data,
                    senior_citizen=form.senior_citizen.data,
                    partner=form.partner.data,
                    dependents=form.dependents.data,
                    tenure=form.tenure.data,
                    phone_service=form.phone_service.data,
                    multiplelines=form.multiplelines.data,
                    internet_service=form.internet_service.data,
                    online_security=form.online_security.data,
                    streaming_tv=form.streaming_tv.data,
                    online_backup=form.online_backup.data,
                    streaming_movies=form.streaming_movies.data,
                    device_protection=form.device_protection.data,
                    techsupport=form.techsupport.data,
                    contract=form.contract.data,
                    paperless=form.paperless.data,
                    payment_method=form.payment_method.data,
                    monthly_charges=form.monthly_charges.data,
                    total_charges=form.total_charges.data,
                    probability=form.probability.data,
                )
                db.session.add(new_prediction)
                db.session.commit()
                flash(f'Вероятность ухода: {proba_massage} %')
                flash('Клиент добавлен.')
                return redirect('/')
            else:
                flash('Такой клиент уже существует')

        return render_template('prediction.html', form=form)
예제 #5
0
def prediction_submit():
    """Provide HTML form to submit a prediction."""
    Trending = get_TT()
    form = PredictionForm(request.form)
    if request.method == 'POST' and form.validate():
        # whatever we do with text etc
        text = form.text.data
        return redirect(url_for('prediction_made', text=text))
    TT_nohas = []
    for i in range(0, 10):
        if ("#" in Trending[i]):
            TT_nohas.append(Trending[i].strip('#'))
        else:
            TT_nohas.append(Trending[i])
    return render_template('prediction/submit.html',
                           form=form,
                           TT=Trending,
                           TTno=TT_nohas)
예제 #6
0
def upload_form():
    form = PredictionForm()
    return render_template('upload.html', form=form)
예제 #7
0
def home():
    form = PredictionForm()
    if form.validate_on_submit():
        return redirect(url_for('prediction'))
    return render_template('home.html', form=form, template='form-template')