def test_dot(self): from scipy.sparse import lil_matrix lil = lil_matrix((4, 1)) lil[1, 0] = 1 lil[3, 0] = 2 dv = array([1., 2., 3., 4.]) sv = SparseVector(4, {0: 1, 1: 2, 2: 3, 3: 4}) mat = array([[1., 2., 3., 4.], [1., 2., 3., 4.], [1., 2., 3., 4.], [1., 2., 3., 4.]]) self.assertEquals(10.0, _dot(lil, dv)) self.assertTrue(array_equal(array([3., 6., 9., 12.]), _dot(lil, mat)))
def test_dot(self): from scipy.sparse import lil_matrix lil = lil_matrix((4, 1)) lil[1, 0] = 1 lil[3, 0] = 2 dv = array([1.0, 2.0, 3.0, 4.0]) sv = SparseVector(4, {0: 1, 1: 2, 2: 3, 3: 4}) mat = array([[1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0]]) self.assertEquals(10.0, _dot(lil, dv)) self.assertTrue(array_equal(array([3.0, 6.0, 9.0, 12.0]), _dot(lil, mat)))
def predict(self, x): _linear_predictor_typecheck(x, self._coeff) margin = _dot(x, self._coeff) + self._intercept if margin > 0: prob = 1 / (1 + exp(-margin)) else: prob = 1 - 1 / (1 + exp(margin)) return 1 if prob > 0.5 else 0
def test_dot(self): sv = SparseVector(4, {1: 1, 3: 2}) dv = array([1.0, 2.0, 3.0, 4.0]) lst = [1, 2, 3, 4] mat = array([[1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0]]) self.assertEquals(10.0, _dot(sv, dv)) self.assertTrue(array_equal(array([3.0, 6.0, 9.0, 12.0]), _dot(sv, mat))) self.assertEquals(30.0, _dot(dv, dv)) self.assertTrue(array_equal(array([10.0, 20.0, 30.0, 40.0]), _dot(dv, mat))) self.assertEquals(30.0, _dot(lst, dv)) self.assertTrue(array_equal(array([10.0, 20.0, 30.0, 40.0]), _dot(lst, mat)))
def test_dot(self): sv = SparseVector(4, {1: 1, 3: 2}) dv = array([1., 2., 3., 4.]) lst = [1, 2, 3, 4] mat = array([[1., 2., 3., 4.], [1., 2., 3., 4.], [1., 2., 3., 4.], [1., 2., 3., 4.]]) self.assertEquals(10.0, _dot(sv, dv)) self.assertTrue(array_equal(array([3., 6., 9., 12.]), _dot(sv, mat))) self.assertEquals(30.0, _dot(dv, dv)) self.assertTrue(array_equal(array([10., 20., 30., 40.]), _dot(dv, mat))) self.assertEquals(30.0, _dot(lst, dv)) self.assertTrue( array_equal(array([10., 20., 30., 40.]), _dot(lst, mat)))
def predict(self, x): """Return the most likely class for a data vector x""" return self.labels[numpy.argmax(self.pi + _dot(x, self.theta.transpose()))]
def predict(self, x): _linear_predictor_typecheck(x, self._coeff) margin = _dot(x, self._coeff) + self._intercept return ('1', abs(margin)) if margin >= 0 else ('0', abs(margin))
def predict(self, x): _linear_predictor_typecheck(x, self._coeff) margin = _dot(x, self._coeff) + self._intercept return 1 if margin >= 0 else 0
def predict(self, x): """Predict the value of the dependent variable given a vector x""" """containing values for the independent variables.""" _linear_predictor_typecheck(x, self._coeff) return _dot(x, self._coeff) + self._intercept