def test_fit_reg_squared_l1(): clf = CDRegressor(C=1.0, random_state=0, penalty="l1", loss="squared", max_iter=100) clf.fit(digit.data, digit.target) y_pred = (clf.predict(digit.data) > 0.5).astype(int) acc = np.mean(digit.target == y_pred) assert_almost_equal(acc, 1.0, 3)
def test_fit_reg_squared_loss_nn_l2(): K = pairwise_kernels(digit.data, metric="poly", degree=4) clf = CDRegressor(C=1, random_state=0, penalty="nnl2", loss="squared", max_iter=100) clf.fit(K, digit.target) y_pred = (clf.predict(K) > 0.5).astype(int) acc = np.mean(digit.target == y_pred) assert_almost_equal(acc, 0.9444, 3)
def test_fit_reg_squared_multiple_outputs(): reg = CDRegressor(C=0.05, random_state=0, penalty="l1/l2", loss="squared", max_iter=100) lb = LabelBinarizer() Y = lb.fit_transform(mult_target) reg.fit(mult_dense, Y) y_pred = lb.inverse_transform(reg.predict(mult_dense)) assert_almost_equal(np.mean(y_pred == mult_target), 0.797, 3) assert_almost_equal(reg.n_nonzero(percentage=True), 0.5)
def test_fit_reg_squared_multiple_outputs(): reg = CDRegressor(C=1.0, random_state=0, penalty="l2", loss="squared", max_iter=100) Y = np.zeros((len(digit.target), 2)) Y[:, 0] = digit.target Y[:, 1] = digit.target reg.fit(digit.data, Y) y_pred = reg.predict(digit.data) assert_equal(y_pred.shape[0], len(digit.target)) assert_equal(y_pred.shape[1], 2)