def test_Averaged__init__(): c1 = Averaged(sgdc_1) c2 = Averaged(sgdc_2) assert c1._name != c2._name assert Averaged(sgdc_1)._name == c1._name with pytest.raises(TypeError): Averaged("not an estimator")
def test_fit_dask_array(): dXc = da.from_array(Xc, chunks=200) dyc = da.from_array(yc, chunks=200) c = Averaged(sgdc_1) fit_test(c, dXc, dyc, SGDClassifier) dXr = da.from_array(Xr, chunks=200) dyr = da.from_array(yr, chunks=200) c = Averaged(sgdr) fit_test(c, dXr, dyr, SGDRegressor)
def test_fit_dask_matrix(): X_bag = db.from_sequence([Xc[0:200], Xc[200:400], Xc[400:]]) y_bag = db.from_sequence([yc[0:200], yc[200:400], yc[400:]]) dX = dm.from_bag(X_bag) dy = dm.from_bag(y_bag) c = Averaged(sgdc_1) fit_test(c, dX, dy, SGDClassifier)
def test_score(): dX = da.from_array(Xc, chunks=200) dy = da.from_array(yc, chunks=200) c = Averaged(sgdc_1) fit = c.fit(dX, dy) s = fit.score(Xc, yc) assert isinstance(s, Delayed) res = s.compute() assert isinstance(res, float) s = fit.score(dX, dy) assert isinstance(s, Delayed) res = s.compute() assert isinstance(res, float) will_error = c.score(Xc, yc) with pytest.raises(NotFittedError): will_error.compute()
def test_predict(): dX = da.from_array(Xc, chunks=200) dy = da.from_array(yc, chunks=200) c = Averaged(sgdc_1) fit = c.fit(dX, dy) pred = fit.predict(Xc) assert isinstance(pred, Delayed) res = pred.compute() assert isinstance(res, np.ndarray) pred = fit.predict(dX) assert isinstance(pred, da.Array) res = pred.compute() assert isinstance(res, np.ndarray) will_error = c.predict(Xc) with pytest.raises(NotFittedError): will_error.compute()
def test_set_params(): c = Averaged(sgdc_1) c2 = c.set_params(penalty='l2') assert isinstance(c2, Averaged) c3 = Averaged(sgdc_2) assert c2._name == c3._name # set_params name equivalent to init # Check no mutation assert c2.get_params()['penalty'] == 'l2' assert c2.compute().penalty == 'l2' assert c.get_params()['penalty'] == 'l1' assert c.compute().penalty == 'l1'
def test_tokenize_Averaged(): c1 = Averaged(sgdc_1) c2 = Averaged(sgdc_2) assert tokenize(c1) == tokenize(c1) assert tokenize(c1) != tokenize(c2) assert tokenize(c1) != tokenize(Wrapped(sgdc_1))
def test_Averaged_from_sklearn(): c1 = Averaged(sgdc_1) assert Averaged.from_sklearn(sgdc_1)._name == c1._name assert Averaged.from_sklearn(c1) is c1
def test_repr(): c = Averaged(sgdc_1) res = repr(c) assert res.startswith('Averaged')
def test_dir(): c = Averaged(sgdc_1) attrs = dir(c) assert 'penalty' in attrs
def test_getattr(): c = Averaged(sgdc_1) assert c.penalty == sgdc_1.penalty with pytest.raises(AttributeError): c.not_a_real_parameter
def test_setattr(): c = Averaged(sgdc_1) with pytest.raises(AttributeError): c.penalty = 'l2'
def test_get_params(): c = Averaged(sgdc_1) assert c.get_params() == sgdc_1.get_params() assert c.get_params(deep=False) == sgdc_1.get_params(deep=False)
def test__estimator_type(): c = Averaged(sgdc_1) assert c._estimator_type == sgdc_1._estimator_type
def test_clone(): c = Averaged(sgdc_1) c2 = clone(c) assert isinstance(c2, Averaged) assert c._name == c2._name assert c._est is not c2._est