示例#1
0
文件: trendfit.py 项目: sjl421/code-2
def lstsq_cv(y, x=None, cv=10, max_deg=3):
    """LSTSQ fit."""
    if np.isnan(y).all():
        y_pred = y
    else:
        y_pred = ap.lstsq_cv(x, y, cv=cv, max_deg=max_deg)
    return y_pred
示例#2
0
def lstsq_cv(y, x=None, cv=10, max_deg=3):
    """LSTSQ fit."""
    if np.isnan(y).all():
        y_pred = y
    else:
        y_pred = ap.lstsq_cv(x, y, cv=cv, max_deg=max_deg)
    return y_pred
示例#3
0
import altimpy as ap


sin_data = DataFrame({'x' : np.linspace(0, 1, 101)})
noise = np.random.normal(0, 0.5, 101)
#noise = np.random.uniform(-1, 1, 101)
sin_data['y'] = np.sin(2 * pi * sin_data['x']) + noise
x = sin_data['x'].values
y = sin_data['y'].values
X = dmatrix('C(x, Poly)')

N = 5

w = 1/noise
out = ap.lstsq_cv(x, y, cv=10, max_deg=N, weight=w, randomise=True, return_coef=True)
y_wls, coef, deg, mse, var = out

y_ols = ap.lstsq_cv(x, y, cv=10, max_deg=N, weight=None, randomise=True)

a2 = np.polyfit(x, y, 1, w=None)#w)
y_line = np.polyval(a2, x)

m, c = ap.linear_fit(x, y, return_coef=True)
m2, c2 = ap.linear_fit_robust(x, y, return_coef=True)

out = ap.lasso_cv(x, y, cv=10, max_deg=N, return_model=True)
y_lasso, lasso = out

a = np.append(lasso.intercept_, lasso.coef_)