Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(7)  |  Call(7)  |  Derive(0)  |  Import(0)

src/m/o/mozsci-HEAD/test/test_logistic_regression.py   mozsci(Download)
    def test_sigmoid(self):
        y = LogisticRegression._sigmoid(self.x, self.b, self.w)
        yact = np.array([1.0 / (1.0 + np.exp(-6)), 1.0 / (1.0 + np.exp(-1.5))])
 
        self.assertTrue(np.all(np.abs(y - yact) < 1.0e-12))
 
        # this assumes test_sigmoid pases
        err_act = -np.log(LogisticRegression._sigmoid(x1, self.b, self.w)) - np.log(1.0 - LogisticRegression._sigmoid(x0, self.b, self.w)) + 0.5 * 7 * 10
 
        pred_error = LogisticRegression._sigmoid(self.x, self.b, self.w) - self.t
        x00 = np.array([self.x[0], [55, -2]])
        error_weighted, gradient_weighted = LogisticRegression._loss_gradient(x00, x1, self.b, self.w, self.lam, [np.array([0.4, 0.75]), np.array(0.35)])
        err_weighted_act = -np.log(LogisticRegression._sigmoid(x1, self.b, self.w)) * 0.35 - np.log(1.0 - LogisticRegression._sigmoid(x0, self.b, self.w)) * 0.4 - np.log(1.0 - LogisticRegression._sigmoid([x00[1, :]], self.b, self.w)) * 0.75 + 0.5 * 7 * 10
        self.assertTrue( abs(float(err_weighted_act) - error_weighted) < 1.0e-12 )