Ejemplo n.º 1
0
 def test_get_coefs(self, data):
     model = VW()
     model.fit(data.x, data.y)
     weights = model.get_coefs()
     print weights.data
     assert np.allclose(weights.indices,
                        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 116060])
Ejemplo n.º 2
0
    def test_predict(self, data):
        raw_model = VW()
        raw_model.fit(data.x, data.y)

        model = VWRegressor()
        model.fit(data.x, data.y)

        assert np.allclose(raw_model.predict(data.x), model.predict(data.x))
Ejemplo n.º 3
0
 def test_get_coefs(self, data):
     model = VW()
     model.fit(data.x, data.y)
     weights = model.get_coefs()
     print weights.data
     assert np.allclose(weights.indices, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 116060])
     assert np.allclose(weights.data, [0.11553502, -0.0166647, -0.00349924, 0.06911729, 0.00252684,
                                       -0.00826817, 0.01991862, -0.02473332, 0.00483846, -0.04616702, -0.00744559])
Ejemplo n.º 4
0
    def test_predict(self, data):
        raw_model = VW()
        raw_model.fit(data.x, data.y)

        model = VWRegressor()
        model.fit(data.x, data.y)

        assert np.allclose(raw_model.predict(data.x), model.predict(data.x))
Ejemplo n.º 5
0
    def test_predict(self, data):
        raw_model = VW()
        raw_model.fit(data.x, data.y)

        model = VWRegressor()
        model.fit(data.x, data.y)

        assert np.allclose(raw_model.predict(data.x), model.predict(data.x))
        # ensure model can make multiple calls to predict
        assert np.allclose(raw_model.predict(data.x), model.predict(data.x))
Ejemplo n.º 6
0
 def test_oaa(self):
     X = [
         '1 | feature1:2.5', '2 | feature1:0.11 feature2:-0.0741',
         '3 | feature3:2.33 feature4:0.8 feature5:-3.1',
         '1 | feature2:-0.028 feature1:4.43',
         '2 | feature5:1.532 feature6:-3.2'
     ]
     model = VW(convert_to_vw=False, oaa=3)
     model.fit(X)
     assert np.allclose(model.predict(X), [1., 2., 3., 1., 2.])
Ejemplo n.º 7
0
 def test_oaa(self):
     X = [
         "1 | feature1:2.5",
         "2 | feature1:0.11 feature2:-0.0741",
         "3 | feature3:2.33 feature4:0.8 feature5:-3.1",
         "1 | feature2:-0.028 feature1:4.43",
         "2 | feature5:1.532 feature6:-3.2",
     ]
     model = VW(convert_to_vw=False, oaa=3)
     model.fit(X)
     assert np.allclose(model.predict(X), [1.0, 2.0, 3.0, 1.0, 2.0])
Ejemplo n.º 8
0
    def test_decision_function(self, data):
        classes = np.array([-1., 1.])
        raw_model = VW(loss_function='logistic')
        raw_model.fit(data.x, data.y)
        predictions = raw_model.predict(data.x)
        class_indices = (predictions > 0).astype(np.int)
        class_predictions = classes[class_indices]

        model = VWClassifier()
        model.fit(data.x, data.y)

        assert np.allclose(class_predictions, model.predict(data.x))
Ejemplo n.º 9
0
    def test_decision_function(self, data):
        classes = np.array([-1., 1.])
        raw_model = VW(loss_function='logistic')
        raw_model.fit(data.x, data.y)
        predictions = raw_model.predict(data.x)
        class_indices = (predictions > 0).astype(np.int)
        class_predictions = classes[class_indices]

        model = VWClassifier()
        model.fit(data.x, data.y)

        assert np.allclose(class_predictions, model.predict(data.x))
Ejemplo n.º 10
0
    def test_predict(self, data):
        raw_model = VW()
        raw_model.fit(data.x, data.y)

        model = VWRegressor()
        model.fit(data.x, data.y)

        assert np.allclose(raw_model.predict(data.x), model.predict(data.x))
        # ensure model can make multiple calls to predict
        assert np.allclose(raw_model.predict(data.x), model.predict(data.x))
Ejemplo n.º 11
0
    def test_set_params(self):
        model = VW()
        assert 'l' not in model.params

        model.set_params(l=0.1)
        assert model.params['l'] == 0.1

        # confirm model params reset with new construction
        model = VW()
        assert 'l' not in model.params
Ejemplo n.º 12
0
 def test_predict(self, data):
     model = VW(loss_function='logistic')
     model.fit(data.x, data.y)
     assert np.isclose(model.predict(data.x[:1][:1])[0], 0.406929)
Ejemplo n.º 13
0
    def test_fit(self, data):
        model = VW(loss_function='logistic')
        assert not hasattr(model, 'fit_')

        model.fit(data.x, data.y)
        assert model.fit_
Ejemplo n.º 14
0
 def test_predict_not_fit(self, data):
     model = VW(loss_function='logistic')
     with pytest.raises(NotFittedError):
         model.predict(data.x[0], data.y[0])
Ejemplo n.º 15
0
    def test_fit(self, data):
        model = VW(loss_function="logistic")
        assert not hasattr(model, "fit_")

        model.fit(data.x, data.y)
        assert model.fit_
Ejemplo n.º 16
0
 def test_get_coefs(self, data):
     model = VW()
     model.fit(data.x, data.y)
     weights = model.get_coefs()
     print weights.data
     assert np.allclose(weights.indices, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 116060])
Ejemplo n.º 17
0
 def test_get_intercept(self, data):
     model = VW()
     model.fit(data.x, data.y)
     intercept = model.get_intercept()
     assert np.isclose(intercept, -0.00744559)
Ejemplo n.º 18
0
 def test_predict_no_convert(self):
     model = VW(loss_function='logistic', convert_to_vw=False)
     model.fit(['-1 | bad', '1 | good'])
     assert np.isclose(model.predict(['| good'])[0], 0.245515)
Ejemplo n.º 19
0
    def test_set_params(self):
        model = VW()
        assert 'l' not in model.params

        model.set_params(l=0.1)
        assert model.params['l'] == 0.1
Ejemplo n.º 20
0
    def test_passes(self, data):
        n_passes = 2
        model = VW(loss_function='logistic', passes=n_passes)
        assert model.passes_ == n_passes

        model.fit(data.x, data.y)
        weights = model.get_coefs()

        model = VW(loss_function='logistic')
        # first pass weights should not be the same
        model.fit(data.x, data.y)
        assert not np.allclose(weights.data, model.get_coefs().data)

        # second pass weights should match
        model.fit(data.x, data.y)
        assert np.allclose(weights.data, model.get_coefs().data)
Ejemplo n.º 21
0
    def test_fit(self, data):
        model = VW(loss_function='logistic')
        assert not hasattr(model, 'fit_')

        model.fit(data.x, data.y)
        assert model.fit_
Ejemplo n.º 22
0
 def test_init(self):
     assert isinstance(VW(), VW)
Ejemplo n.º 23
0
 def test_get_intercept(self, data):
     model = VW()
     model.fit(data.x, data.y)
     intercept = model.get_intercept()
     assert isinstance(intercept, float)
Ejemplo n.º 24
0
 def test_delete(self):
     raw_model = VW()
     del raw_model
Ejemplo n.º 25
0
 def test_predict(self, data):
     model = VW(loss_function='logistic')
     model.fit(data.x, data.y)
     assert np.isclose(model.predict(data.x[:1][:1])[0], 0.406929)
Ejemplo n.º 26
0
 def test_predict_not_fit(self, data):
     model = VW(loss_function='logistic')
     with pytest.raises(NotFittedError):
         model.predict(data.x[0])
Ejemplo n.º 27
0
 def test_predict_no_convert(self):
     model = VW(loss_function="logistic", convert_to_vw=False)
     model.fit(["-1 | bad", "1 | good"])
     assert np.isclose(model.predict(["| good"])[0], 0.245515)
Ejemplo n.º 28
-1
 def test_predict_no_convert(self):
     model = VW(loss_function='logistic')
     model.fit(['-1 | bad', '1 | good'], convert_to_vw=False)
     assert np.isclose(model.predict(['| good'], convert_to_vw=False)[0], 0.245515)