Пример #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])
Пример #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))
Пример #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])
Пример #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))
Пример #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))
Пример #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.])
Пример #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])
Пример #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))
Пример #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))
Пример #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))
Пример #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
Пример #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)
Пример #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_
Пример #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])
Пример #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_
Пример #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])
Пример #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)
Пример #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)
Пример #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
Пример #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)
Пример #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_
Пример #22
0
 def test_init(self):
     assert isinstance(VW(), VW)
Пример #23
0
 def test_get_intercept(self, data):
     model = VW()
     model.fit(data.x, data.y)
     intercept = model.get_intercept()
     assert isinstance(intercept, float)
Пример #24
0
 def test_delete(self):
     raw_model = VW()
     del raw_model
Пример #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)
Пример #26
0
 def test_predict_not_fit(self, data):
     model = VW(loss_function='logistic')
     with pytest.raises(NotFittedError):
         model.predict(data.x[0])
Пример #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)
Пример #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)