Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add linear least squares and ridge regression
This add linear ridge regression and a convenience class CLeastSquaresRegression calling CLinearRidgeRegression with regularization parameter tau=0. To not cause confusion KRR is renamed to KernelRidgeRegression throughout examples/code.
- Loading branch information
Soeren Sonnenburg
committed
Feb 14, 2012
1 parent
3649f3b
commit 3e3db13
Showing
27 changed files
with
446 additions
and
136 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
File renamed without changes.
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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
examples/undocumented/python_modular/regression_least_squares_modular.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
########################################################################### | ||
# kernel ridge regression | ||
########################################################################### | ||
from numpy import array | ||
from numpy.random import seed, rand | ||
from tools.load import LoadMatrix | ||
lm=LoadMatrix() | ||
|
||
traindat = lm.load_numbers('../data/fm_train_real.dat') | ||
testdat = lm.load_numbers('../data/fm_test_real.dat') | ||
label_traindat = lm.load_labels('../data/label_train_twoclass.dat') | ||
|
||
|
||
parameter_list = [[traindat,testdat,label_traindat]] | ||
|
||
def regression_least_squares_modular (fm_train=traindat,fm_test=testdat,label_train=label_traindat,tau=1e-6): | ||
|
||
from shogun.Features import Labels, RealFeatures | ||
from shogun.Kernel import GaussianKernel | ||
from shogun.Regression import LeastSquaresRegression | ||
|
||
ls=LeastSquaresRegression(RealFeatures(traindat), Labels(label_train)) | ||
ls.train() | ||
out = ls.apply(RealFeatures(fm_test)).get_labels() | ||
return out,ls | ||
|
||
if __name__=='__main__': | ||
print 'LeastSquaresRegression' | ||
regression_least_squares_modular(*parameter_list[0]) |
29 changes: 29 additions & 0 deletions
29
examples/undocumented/python_modular/regression_linear_ridge_modular.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
########################################################################### | ||
# linear ridge regression | ||
########################################################################### | ||
from numpy import array | ||
from numpy.random import seed, rand | ||
from tools.load import LoadMatrix | ||
lm=LoadMatrix() | ||
|
||
traindat = lm.load_numbers('../data/fm_train_real.dat') | ||
testdat = lm.load_numbers('../data/fm_test_real.dat') | ||
label_traindat = lm.load_labels('../data/label_train_twoclass.dat') | ||
|
||
|
||
parameter_list = [[traindat,testdat,label_traindat,1e-6],[traindat,testdat,label_traindat,100]] | ||
|
||
def regression_linear_ridge_modular (fm_train=traindat,fm_test=testdat,label_train=label_traindat,tau=1e-6): | ||
|
||
from shogun.Features import Labels, RealFeatures | ||
from shogun.Kernel import GaussianKernel | ||
from shogun.Regression import LinearRidgeRegression | ||
|
||
rr=LinearRidgeRegression(tau, RealFeatures(traindat), Labels(label_train)) | ||
rr.train() | ||
out = rr.apply(RealFeatures(fm_test)).get_labels() | ||
return out,rr | ||
|
||
if __name__=='__main__': | ||
print 'LinearRidgeRegression' | ||
regression_linear_ridge_modular(*parameter_list[0]) |
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
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
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
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
Oops, something went wrong.