コード例 #1
0
def generate_set_vals(X_data, Y_data, _rev_data, pr = True):
    print("----------------------------------------     Data Set     ----------------------------------------")
    print('Model: ' + model_name)
    prediction = model.predict(X_data)

    total = 0
    right = 0
    for i in range(len(X_data)):
        predict = prediction[i][0]

        difference = abs(predict - Y_data[i])

        predict_stars = dm.to_stars(predict)
        actual_stars = dm.to_stars(Y_data[i])

        text = str(i + 1) + ') ' + _rev_data[i]

        if difference <= allowed_difference:
            if pr:
                print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars + '----- actually ' + actual_stars)
            right += 1
        else:
            if pr:
                print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars + '----- actually ' + actual_stars + ' *****')
        total += 1

    print('Accuracy:', str(right / total * 100) + '% |', str(right) + '/' + str(total))
コード例 #2
0
def predict(txt):
    inp = dm.data_to_input(txt)

    prediction = model.predict(inp)
    predict = prediction[0][0]
    predict_stars = dm.to_stars(predict)

    return predict_stars
コード例 #3
0
def generate_set_naive(X_data):
    print("----------------------------------------     Data Set     ----------------------------------------")
    print('Model: ' + model_name)
    prediction = naive_predict_data(X_data)

    for i in range(len(X_data)):
        predict = prediction[i]

        predict_stars = dm.to_stars(predict)

        text = str(i + 1) + ') ' + X_data[i]

        print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars)
コード例 #4
0
def generate(forever = False):
    inp = ''
    print('Model: ' + model_name)
    while forever or not any(inp == w for w in stop_words):
        inp = input('Sample review:\n')
    
        z = dm.data_to_input(inp)

        prediction = model.predict(z)
        predict = prediction[0][0]
        
        predict_stars = dm.to_stars(predict)

        print(dm.truncate_text('', char_to_display) + ' ----- predicted ' + predict_stars)
コード例 #5
0
def generate_set(X_data, _rev_data):
    print("----------------------------------------     Data Set     ----------------------------------------")
    print('Model: ' + model_name)
    z = []
    for data in X_data:
        z.append(dm.data_to_input(data)[0])
    X_data = np.array(z)

    prediction = model.predict(X_data)

    for i in range(len(_rev_data)):
        predict = prediction[i][0]

        predict_stars = dm.to_stars(predict)

        text = str(i + 1) + ') ' + _rev_data[i]

        print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars)
コード例 #6
0
loss, acc = model.evaluate(X_train, Y_train, verbose = 0)


prediction = model.predict(X_train)

char_to_display = 140
allowed_difference = 0.1

total = 0
right = 0
for i in range(len(X_train)):
    predict = prediction[i][0]

    difference = abs(predict - Y_train[i])

    predict_stars = dm.to_stars(predict)
    actual_stars = dm.to_stars(Y_train[i])

    text = str(i + 1) + ') ' + _rev_train[i]

    if difference <= allowed_difference:
        print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars + '----- actually ' + actual_stars)
        right += 1
    else:
        print(dm.truncate_text(text, char_to_display) + ' ----- predicted ' + predict_stars + '----- actually ' + actual_stars + ' *****')
    total += 1

print('Loss:', loss, 'Accuracy:', str(right / total * 100) + '% |', str(right) + '/' + str(total))

print("----------------------------------------     TEST SET     ----------------------------------------")