def try_different_method(clf, x_train, y_train, x_test, y_test):
    clf.fit(x_train, y_train)

    score = clf.score(x_test, y_test)
    print('score: ', score)

    result = clf.predict(x_test)

    plt.figure()
    plt.plot(np.arange(len(result)), y_test, 'go-', label='true value')
    plt.plot(np.arange(len(result)), result, 'ro-', label='predict value')
    plt.title('score: %f' % score)
    plt.legend()
    plt.show()

    # 保存Model
    with open('./clf.pickle', 'wb') as f:
        pickle.dump(clf, f)

    # 读取Model
    with open('./clf.pickle', 'rb') as f:
        clf2 = pickle.load(f)
        # 测试读取后的Model
        print(clf2.predict(x_test[0:1]), y_test[0:1])

    print('relative x error: ', x_err_esti(result, y_test))
    print('mean absolute error: ', vx_err_esti(result, y_test))
    result = clf2.predict([x_test[0]])
    print(x_test[0])
    print(result)
Example #2
0
def train_model(clf, t_smples, t_targets):
    x_train, x_test, y_train, y_test = train_test_split(t_smples,
                                                        t_targets,
                                                        test_size=0.1,
                                                        random_state=42)
    clf.fit(x_train, y_train)
    result = clf.predict(x_test)
    print('Train relative x error: ', x_err_esti(result, y_test))
    # print('Train mean absolute error: ', vx_err_esti(result, y_test))
    return clf
Example #3
0
def test(x_test, y_test):
    # 读取Model
    with open('./clf.pickle', 'rb') as f:
        clf = pickle.load(f)
        # 测试读取后的Model
        print(clf.predict(x_test[0:1]), y_test[0:1])

    result = clf.predict(x_test)
    print('relative x error: ', x_err_esti(result, y_test))
    print('mean absolute error: ', vx_err_esti(result, y_test))
Example #4
0
    def err_estimation(self, gt_file, before):
        result = self.result
        fids = [r['fid'] for r in result]
        vx = [r['vx'] for r in result]
        x = [r['x'] for r in result]

        with open(gt_file) as f:
            ground_truth = json.load(f)
            gt_x = [gt['x'] for gt in ground_truth["frame_data"]]
            gt_vx = [gt['vx'] for gt in ground_truth["frame_data"]]
        # before = 10
        err_x = x_err_esti(x[:before], gt_x[:before])
        err_vx = vx_err_esti(vx[:before], gt_vx[:before])
        high = high_esti(x[:before], gt_x[:before])
        print('Error for x :', err_x)
        print('Error for vx:', err_vx)
        print('high        :', high)
Example #5
0
def err(prediction, gt_x):
    prediction = np.asarray(prediction, np.float32)
    gt_x = np.asarray(gt_x, np.float32)
    return x_err_esti(prediction, gt_x)
Example #6
0
                        X_test, y_test, M, ind)
                    print("test video :", test_flies[ind])

                    feed_dict = {
                        model.xs: X_test_batch,
                        # model.cell_init_state: state  # use last state as the initial state for this run
                    }
                    y_test_pred, outputs = sess.run(
                        [model.pred, model.cell_outputs], feed_dict=feed_dict)
                    # print('*'*50+'outputs'+'*'*50)
                    # print(outputs)
                    xs = np.arange(500)
                    if x_vx_mode == 'x':
                        print(
                            'error for x:',
                            x_err_esti(y_test_pred[:, :, 0], y_test_batch[:, :,
                                                                          0]))
                        draw_line(xs,
                                  y_test_pred,
                                  y_test_batch,
                                  name='show/curve_train/x_%s.png' %
                                  test_flies[ind][:-7])
                    elif x_vx_mode == 'vx':
                        print(
                            'error for vx:',
                            vx_err_esti(y_test_pred[:, :, 0],
                                        y_test_batch[:, :, 0]))
                        draw_line(xs,
                                  y_test_pred,
                                  y_test_batch,
                                  name='show/curve_train/vx_%s.png' %
                                  test_flies[ind][:-7])
Example #7
0
def test_model(clf, x_test, y_test):
    result = clf.predict(x_test)
    print('Test  relative x error: ', x_err_esti(result, y_test))