def test_mse_max_features(): sk = 0 iv = 0 n_times = 30 for X, y in _make_regression_datasets(n_times): reg = skRegTree(max_depth=5, max_features=4, random_state=0) reg.fit(X, y) y_pred = reg.predict(X) sk += np.mean((y - y_pred) ** 2) reg = TreeRegressor(max_depth=5, max_features=4, random_state=0) reg.fit(X, y) y_pred = reg.predict(X) iv += np.mean((y - y_pred) ** 2) sk /= n_times iv /= n_times assert_almost_equal(sk, 4588.4, 1) assert_almost_equal(iv, 4921.1, 1)
def test_mse_duplicate_features(): diabetes = load_diabetes() X, y = diabetes.data, diabetes.target reg = skRegTree(max_depth=5) reg.fit(X, y) y_pred = reg.predict(X) sk = np.mean((y - y_pred)**2) reg = TreeRegressor(max_depth=5) reg.fit(X, y) y_pred = reg.predict(X) iv = np.mean((y - y_pred)**2) assert_almost_equal(sk, iv)
def test_mse_duplicate_features(): diabetes = load_diabetes() X, y = diabetes.data, diabetes.target reg = skRegTree(max_depth=5) reg.fit(X, y) y_pred = reg.predict(X) sk = np.mean((y - y_pred) ** 2) reg = TreeRegressor(max_depth=5) reg.fit(X, y) y_pred = reg.predict(X) iv = np.mean((y - y_pred) ** 2) assert_almost_equal(sk, iv)
def test_mse_fully_developed(): sk = 0 iv = 0 for X, y in _make_regression_datasets(10): reg = skRegTree(max_depth=None) reg.fit(X, y) y_pred = reg.predict(X) sk += np.mean((y - y_pred)**2) reg = TreeRegressor(max_depth=None) reg.fit(X, y) y_pred = reg.predict(X) iv += np.mean((y - y_pred)**2) assert_almost_equal(sk, iv)
def test_mse_fully_developed(): sk = 0 iv = 0 for X, y in _make_regression_datasets(10): reg = skRegTree(max_depth=None) reg.fit(X, y) y_pred = reg.predict(X) sk += np.mean((y - y_pred) ** 2) reg = TreeRegressor(max_depth=None) reg.fit(X, y) y_pred = reg.predict(X) iv += np.mean((y - y_pred) ** 2) assert_almost_equal(sk, iv)
def test_mse_min_samples(): sk = 0 iv = 0 for X, y in _make_regression_datasets(10): reg = skRegTree(max_depth=5, min_samples_split=4, min_samples_leaf=2) reg.fit(X, y) y_pred = reg.predict(X) sk += np.mean((y - y_pred)**2) reg = TreeRegressor(max_depth=5, min_samples_split=4, min_samples_leaf=2) reg.fit(X, y) y_pred = reg.predict(X) iv += np.mean((y - y_pred)**2) assert_almost_equal(sk, iv)
def test_mse_sample_weight(): sk = 0 iv = 0 n_times = 10 for X, y, w in _make_regression_datasets(n_times, sw=True): reg = skRegTree(max_depth=5) reg.fit(X, y, w) y_pred = reg.predict(X) sk += mean_squared_error(y, y_pred, sample_weight=w) reg = TreeRegressor(max_depth=5) reg.fit(X, y, w) y_pred = reg.predict(X) iv += mean_squared_error(y, y_pred, sample_weight=w) sk /= n_times iv /= n_times assert_almost_equal(sk, iv)
def test_mse_min_samples(): sk = 0 iv = 0 for X, y in _make_regression_datasets(10): reg = skRegTree(max_depth=5, min_samples_split=4, min_samples_leaf=2) reg.fit(X, y) y_pred = reg.predict(X) sk += np.mean((y - y_pred) ** 2) reg = TreeRegressor(max_depth=5, min_samples_split=4, min_samples_leaf=2) reg.fit(X, y) y_pred = reg.predict(X) iv += np.mean((y - y_pred) ** 2) assert_almost_equal(sk, iv)
def test_mse_max_features(): sk = 0 iv = 0 n_times = 30 for X, y in _make_regression_datasets(n_times): reg = skRegTree(max_depth=5, max_features=4, random_state=0) reg.fit(X, y) y_pred = reg.predict(X) sk += np.mean((y - y_pred)**2) reg = TreeRegressor(max_depth=5, max_features=4, random_state=0) reg.fit(X, y) y_pred = reg.predict(X) iv += np.mean((y - y_pred)**2) sk /= n_times iv /= n_times assert_almost_equal(sk, 4588.4, 1) assert_almost_equal(iv, 4921.1, 1)