python 单元测试

unittest

https://docs.python.org/2/library/unittest.html

A test­case is cre­at­ed by sub­class­ing unittest.TestCase. The three indi­vid­u­al tests are defined with meth­ods whose names start with the let­ters test. This nam­ing con­ven­tion informs the test run­ner about which meth­ods rep­re­sent tests.

The crux of each test is a call to assertE­qual() to check for an expect­ed result; assert­True() or assert­False() to ver­i­fy a con­di­tion; or asser­tRais­es() to ver­i­fy that a speci­fic excep­tion gets raised. The­se meth­ods are used instead of the assert state­ment so the test run­ner can accu­mu­late all test results and pro­duce a report.

The setUp() and tear­Down() meth­ods allow you to define instruc­tions that will be exe­cut­ed before and after each test method. They are cov­ered in more detail in the sec­tion Orga­niz­ing test code.

The final block shows a sim­ple way to run the tests. unittest.main() pro­vides a com­mand-line inter­face to the test script. When run from the com­mand line, the above script pro­duces an out­put that looks like this:

PCA — 数据降维

原数据,2维:(3,4),(6,8)

新数据,2维:(5,0), (10,0)

最终简化为一维:5, 10

从几何来理解,就是坐标轴的旋转。

这里降维的理由:所有的点实际上都是分布在y=(4/3)X这条斜线上的。

relat­ed posts:

1. http://www.iro.umontreal.ca/~pift6080/H09/documents/papers/pca_tutorial.pdf

2. https://stats.stackexchange.com/questions/90331/step-by-step-implementation-of-pca-in-r-using-lindsay-smiths-tutorial

3. http://www.cnblogs.com/pangxiaodong/archive/2011/10/15/2212786.html

 

 

git

1. 提交

git add .

git com­mit –m “your com­ments about this sub­mis­sion”

git push orig­in mas­ter

2. 下载