Пример #1
0
 def test_test_value_oob_gets_error_message(self):
     """The 'predict' option with the 'test_value=<INT>' flag requires that
     <INT> be between 0 and 41608."""
     res = predict_model.predict(test_value=-1)
     assert res == self.err_msg
     res = predict_model.predict(test_value=40283)
     assert res == self.err_msg
def prediction():
    st.title('Buy or Not Buy')
    age = st.slider("Age", 18, 100)
    salary = st.number_input("Salary", min_value=5000, max_value=10000000000)
    label_map = {0: "Not Buying", 1: "Can Buy"}
    if st.button("Classify"):
        output = predict_model.predict([[age, salary]])[0]
        st.write(label_map[output])
Пример #3
0
def predict_(input: Input):
    probas = predict([input.text]).round(3)
    response = {
        'texto': input.text,
        'proba_no_confiable': probas[0, 0],
        'proba_confiable': probas[0, 1]
    }

    return response
Пример #4
0
 def test_correct_test_value_call_works(self):  # NOQA
     """Dumb reference test: calling predict with test_value=0 should
     result in an answer of exp(8.3232). TODO: consider mocking the
     calls to preprocess.preprocess() and load_learner(); might be
     faster."""
     res = predict_model.predict(data_path=self.data_path,
                                 models_path=self.models_path,
                                 test_value=0)
     assert abs(float(res) - 4198.543914975132) < 0.01
Пример #5
0
 def test_correct_new_value_call_works(self):
     """Dumb reference test: calling predict with new_value=<example>
     should result in an answer of exp(8.3232). TODO: consider mocking
     out the calls to preprocess.preprocess() and load_learner(); might be
     faster."""
     # Fake a test_value from the existing pre-made dataframe
     # Use .iloc[0] to make sure we're using a Series per expectations
     res = predict_model.predict(data_path=self.data_path,
                                 models_path=self.models_path,
                                 new_value='example_data_row.csv')
     assert abs(float(res) - 4198.543914975132) < 0.01
Пример #6
0
 def test_correct_test_value_call_with_context_works(self):
     """Dumb reference test: calling predict with test_value=0 and
     context=True should result in an answer of exp(8.3232), with
     appropriate context. TODO: consider mocking out the calls to
     preprocess.preprocess() and load_learner(); might be faster."""
     res = predict_model.predict(data_path=self.data_path,
                                 models_path=self.models_path,
                                 test_value=0,
                                 context=True)
     assert res == ('The predicted value is 4198.543914975132 and the '
                    'actual value is 4097.0.')
Пример #7
0
def predict_beer_type(request_body: beerType):
    """
    Returns a single beer style prediction.

    Parameters
    ----------
    * **review_aroma** (float): Score given by reviewer regarding beer aroma- ranges from 1 to 5.
    * **review_appearance** (float): Score given by reviewer regarding beer appearance - ranges from 1 to 5.
    * **review_palate** (float): Score given by reviewer regarding beer palate- ranges from 1 to 5.
    * **review_taste** (float): Score given by reviewer regarding beer taste - ranges from 1 to 5.
    * **brwery_name** (string): Name of brewery - ranges from 1 to 5.
    """
    data = create_beer_dataset(request_body, ohe, scaler)
    device = get_device()
    prediction = predict(data, model, device, y_encoder)
    print(prediction)
    return prediction
Пример #8
0
def postJsonHandler():
    content = request.get_json()
    user_id = "karunr"  #tmp fix
    user_folder = str.format("data/external/users/{0}", user_id)
    if not os.path.isdir(user_folder):
        os.makedirs(user_folder)
    user_file_path = str.format("data/external/users/{0}/{1}_{2}.json",
                                user_id, user_id, int(time.time()))
    csv_file_path = str.format("data/external/users/{0}/{1}_{2}.csv", user_id,
                               user_id, int(time.time()))
    with open(user_file_path, 'w') as outfile:
        json.dump(content, outfile)
    parse_json(user_file_path, csv_file_path)
    incoming_df = pd.read_csv(csv_file_path)
    processed_df = process_incoming_data(incoming_df)
    print(processed_df.columns)
    ml_model = load_model()
    output = predict(ml_model, processed_df)
    print(output)
    return output[0]
Пример #9
0
def service():
    '''Serve a html document returning a sorted table with the score for each category.'''
    # TODO: Add json serialized output
    try:
        # parse argument
        query = request.args.get('q')
        cat_only = request.args.get('cat_only')
        # predict category
        test_text, cats = predict(query,nlp=nlp)
        # store categories into dataframe
        cats_df=pd.Series(cats,name="Score").sort_values(ascending=False).to_frame()*100
        # flow control for testing
        if cat_only == "yes":
            cat = cats_df['Score'].idxmax()
            return cat
        # create the categories html table
        cats_str=cats_df.to_html(float_format='{:.0f}%'.format)
    except:
        # TODO: Catch exception by type to specialized the server error message.
        cats_str="Server error!"
    output = f'<!DOCTYPE html><body>{test_text}<P>{cats_str}:</body></html>'
    return output
Пример #10
0
        debug = False
        
    # set paths
    BASE_PATH = 'data/raw/training_data'
    BASE_PATH_NORMALIZED = 'data/processed/normalized-images'

    if args.prediction:
        # use main to predict a serie of test files. See predict doc-string for more info
        assert args.image != '', "no path prediction image, use -im"
        # get model dir
        image_list = os.listdir(args.image)
        if args.model == 'default':
            predict_model_path = 'models/default.h5'
        else:
            predict_model_path = args.model
        # predict
        p_model = get_model()
        p_model.load_weights(predict_model_path)
        predict(p_model, image_list)
        # find saved files in 'models/predictions'
    else:
        # generate training and validation data
        verse_dataset = VerseDataset(base_path=BASE_PATH_NORMALIZED, seed=args.seed, split=args.fraction, debug=debug)

        training_dataset = verse_dataset.get_dataset('train').batch(args.batch_size)
        validation_dataset = verse_dataset.get_dataset('validation').batch(args.batch_size)

        train_u_net(training_dataset, validation_dataset, args.epochs, args.steps_per_epoch)
    
    print("--DONE--")
Пример #11
0
def create_prediction():
    data = request.data or '{}'
    body = json.loads(data)
    return jsonify(predict(body))
Пример #12
0
def predict():
    if request.method == 'POST':
        age = request.form['age']
        salary = request.form['salary']
    output = predict_model.predict([[age, salary]])[0]
    return render_template('index.html', age=age, salary=salary, output=output)
Пример #13
0
def index():
    output = predict_model.predict([[15, 150000]])[0]
    return render_template('index.html')
Пример #14
0
 def test_both_parameters_gets_error_message(self):
     """The 'predict' option should either be called with the 'test_value=
     <INT>' flag, or with the 'new_value=<FILENAME>' flag - but not both"""
     res = predict_model.predict(test_value=42, new_value='fake_file.csv')
     assert res == self.err_msg
Пример #15
0
 def test_no_parameters_gets_error_message(self):
     """The 'predict' option should either be called with the 'test_value=
     <INT>' flag, or with the 'new_value=<FILENAME>' flag"""
     res = predict_model.predict()
     assert res == self.err_msg