Skip to content

Instantly share code, notes, and snippets.

@yamaguchiyuto
Created December 5, 2014 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamaguchiyuto/602e416dcabd30aafe99 to your computer and use it in GitHub Desktop.
Save yamaguchiyuto/602e416dcabd30aafe99 to your computer and use it in GitHub Desktop.
Cross validation for oreore regression
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