Back to index

python-biopython  1.60
Public Member Functions
test_LogisticRegression.TestLogisticRegression Class Reference

List of all members.

Public Member Functions

def test_calculate_model
def test_classify
def test_calculate_probability
def test_model_accuracy
def test_leave_one_out

Detailed Description

Definition at line 58 of file test_LogisticRegression.py.


Member Function Documentation

Definition at line 60 of file test_LogisticRegression.py.

00060 
00061     def test_calculate_model(self):
00062         model = LogisticRegression.train(xs, ys)
00063         beta = model.beta
00064         self.assertAlmostEqual(beta[0],  8.9830, places=4)
00065         self.assertAlmostEqual(beta[1], -0.0360, places=4)
00066         self.assertAlmostEqual(beta[2],  0.0218, places=4)

Definition at line 74 of file test_LogisticRegression.py.

00074 
00075     def test_calculate_probability(self):
00076         model = LogisticRegression.train(xs, ys)
00077         q, p = LogisticRegression.calculate(model, [6,-173.143442352])
00078         self.assertAlmostEqual(p, 0.993242, places=6)
00079         self.assertAlmostEqual(q, 0.006758, places=6)
00080         q, p = LogisticRegression.calculate(model, [309, -271.005880394])
00081         self.assertAlmostEqual(p, 0.000321, places=6)
00082         self.assertAlmostEqual(q, 0.999679, places=6)

Definition at line 67 of file test_LogisticRegression.py.

00067 
00068     def test_classify(self):
00069         model = LogisticRegression.train(xs, ys)
00070         result = LogisticRegression.classify(model, [6,-173.143442352])
00071         self.assertEqual(result, 1)
00072         result = LogisticRegression.classify(model, [309, -271.005880394])
00073         self.assertEqual(result, 0)

Definition at line 94 of file test_LogisticRegression.py.

00094 
00095     def test_leave_one_out(self):
00096         correct = 0
00097         predictions = [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0]
00098         for i in range(len(predictions)):
00099             model = LogisticRegression.train(xs[:i]+xs[i+1:], ys[:i]+ys[i+1:])
00100             prediction = LogisticRegression.classify(model, xs[i])
00101             self.assertEqual(prediction, predictions[i])
00102             if prediction==ys[i]:
00103                 correct+=1
00104         self.assertEqual(correct, 15)

Definition at line 83 of file test_LogisticRegression.py.

00083 
00084     def test_model_accuracy(self):
00085         correct = 0
00086         model = LogisticRegression.train(xs, ys)
00087         predictions = [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
00088         for i in range(len(predictions)):
00089             prediction = LogisticRegression.classify(model, xs[i])
00090             self.assertEqual(prediction, predictions[i])
00091             if prediction==ys[i]:
00092                 correct+=1
00093         self.assertEqual(correct, 16)


The documentation for this class was generated from the following file: