def show_result(poly_data: pandas.DataFrame,
                regression_model: RegressionResultsWrapper,
                predict_model: pandas.DataFrame, y_param: str, degree: int):

    poly_features = [
        i for i in poly_data.columns.values if i.startswith('power_')
    ]

    # #7
    pred_model = regression_model.predict(
        sm.add_constant(predict_model[poly_features]))

    plot_polynomial(poly_data, pred_model, y_param)

    # #9
    print('-----coefficient of degree {deg}------'.format(deg=degree))

    print_coefficient(regression_model.params)
Exemplo n.º 2
0
def expression_fields(
    xs: np.ndarray,
    ys: np.ndarray,
    results: regres,
    n_ticks: int = 400,
) -> Tuple[np.ndarray, np.ndarray, Tuple[int, int]]:

    mx = np.max((xs[:, 1]))
    mn = np.min(xs[:, 1])
    xx = np.linspace(mn, mx, n_ticks)
    mx = np.max((xs[:, 2]))
    mn = np.min(xs[:, 2])
    yy = np.linspace(mn, mx, n_ticks)
    X, Y = np.meshgrid(xx, yy)
    shape = X.shape
    Xf = X.flatten()
    Yf = Y.flatten()
    XY = np.hstack((np.ones(
        (Xf.shape[0], 1)), Xf[:, np.newaxis], Yf[:, np.newaxis]))
    Z = results.predict(XY)

    return (XY[:, 1::], Z, shape)
def get_rss(model: RegressionResultsWrapper, data: list, input_model: list,
            param_name: str) -> float:
    prediction = model.predict(sm.add_constant(data[input_model]))
    residuals = data[param_name] - prediction
    rss = (residuals**2).sum()
    return rss