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))
def test_repr(): model = VW() expected = "VW('convert_labels:False', 'quiet:True', 'sgd:False')" assert expected == model.__repr__() model = VWClassifier() expected = "VWClassifier('convert_labels:False', "\ "'loss_function:logistic', 'quiet:True', 'sgd:False')" assert expected == model.__repr__() model = VWRegressor() expected = "VWRegressor('convert_labels:False', 'quiet:True', 'sgd:False')" assert expected == model.__repr__() model = VW(convert_to_vw=False, oaa=3, loss_function='logistic', probabilities=True) expected = "VW('convert_labels:False', 'loss_function:logistic', "\ "'oaa:3', 'probabilities:True', 'quiet:True', 'sgd:False')" assert expected == model.__repr__()
def test_sgd_param(): model1 = VWRegressor(sgd=True) model2 = VWClassifier(sgd=True) assert model1.get_params()['sgd'] == True assert model2.get_params()['sgd'] == True
def test_save_load(tmp_path): train_file = str(tmp_path / "train.model") X = [[1, 2], [3, 4], [5, 6], [7, 8]] y = [1, 2, 3, 4] model_before = VWRegressor(l=100) model_before.fit(X, y) before_saving = model_before.predict(X) model_before.save(train_file) model_after = VWRegressor(l=100) model_after.load(train_file) after_loading = model_after.predict(X) assert all([a == b for a, b in zip(before_saving, after_loading)])
def test_init(self): assert isinstance(VWRegressor(), VWRegressor)
from vowpalwabbit.sklearn_vw import VWRegressor X = [[1, 2], [3, 4], [5, 6], [7, 8]] y = [1, 2, 3, 4] model = VWRegressor(l=100) model.fit(X, y) print(model.predict(X)) model.save("/tmp/train.model") model2 = VWRegressor(l=100) model2.load("/tmp/train.model") print(model2.predict(X))