Created
December 5, 2014 04:06
-
-
Save yamaguchiyuto/602e416dcabd30aafe99 to your computer and use it in GitHub Desktop.
Cross validation for oreore regression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import numpy as np | |
from sklearn import cross_validation | |
from oreore_ridge import RidgeRegression | |
def psi(xlist,M): | |
""" make a design matrix """ | |
ret = [] | |
for x in xlist: | |
ret.append([x**i for i in range(0,M+1)]) | |
return np.array(ret) | |
np.random.seed(1) | |
""" Data """ | |
N = 100 | |
M = 3 | |
xlist = np.linspace(0, 1, N) | |
ylist = np.sin(2 * np.pi * xlist) + np.random.normal(0, 0.2, xlist.size) | |
X = psi(xlist,M) | |
y = ylist | |
""" Cross validation""" | |
parameter = {'lamb':0} | |
reg = RidgeRegression(**parameter) | |
scores = cross_validation.cross_val_score(reg, X, y, cv=5, scoring='mean_squared_error') | |
print scores.mean() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment