Mercurial > pylearn
annotate _test_linear_regression.py @ 474:40c8a46b3da7
added Stopper.find_min
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Thu, 23 Oct 2008 18:05:46 -0400 |
parents | 8e4d2ebd816a |
children | 317a052f9b14 |
rev | line source |
---|---|
432
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
1 |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
2 import unittest |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
3 from linear_regression import * |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
4 from make_test_datasets import * |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
5 import numpy |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
6 |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
7 class test_linear_regression(unittest.TestCase): |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
8 |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
9 def test1(self): |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
10 trainset,testset,theta=make_artificial_datasets_from_function(n_inputs=3, |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
11 n_targets=2, |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
12 n_examples=100, |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
13 f=linear_predictor) |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
14 |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
15 assert trainset.fields()['input'].shape==(50,3) |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
16 assert testset.fields()['target'].shape==(50,2) |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
17 regressor = LinearRegression(L2_regularizer=0.1) |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
18 predictor = regressor(trainset) |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
19 test_data = testset.fields() |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
20 mse = predictor.compute_mse(test_data['input'],test_data['target']) |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
21 print 'mse = ',mse |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
22 |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
23 if __name__ == '__main__': |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
24 unittest.main() |
8e4d2ebd816a
added a test for LinearRegression
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff
changeset
|
25 |