本文整理汇总了Python中sklearn.dummy.DummyRegressor.predict方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRegressor.predict方法的具体用法?Python DummyRegressor.predict怎么用?Python DummyRegressor.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.dummy.DummyRegressor
的用法示例。
在下文中一共展示了DummyRegressor.predict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_quantile_strategy_multioutput_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_quantile_strategy_multioutput_regressor():
random_state = np.random.RandomState(seed=1)
X_learn = random_state.randn(10, 10)
y_learn = random_state.randn(10, 5)
median = np.median(y_learn, axis=0).reshape((1, -1))
quantile_values = np.percentile(y_learn, axis=0, q=80).reshape((1, -1))
X_test = random_state.randn(20, 10)
y_test = random_state.randn(20, 5)
# Correctness oracle
est = DummyRegressor(strategy="quantile", quantile=0.5)
est.fit(X_learn, y_learn)
y_pred_learn = est.predict(X_learn)
y_pred_test = est.predict(X_test)
_check_equality_regressor(
median, y_learn, y_pred_learn, y_test, y_pred_test)
_check_behavior_2d(est)
# Correctness oracle
est = DummyRegressor(strategy="quantile", quantile=0.8)
est.fit(X_learn, y_learn)
y_pred_learn = est.predict(X_learn)
y_pred_test = est.predict(X_test)
_check_equality_regressor(
quantile_values, y_learn, y_pred_learn, y_test, y_pred_test)
_check_behavior_2d(est)
示例2: test_regressor_prediction_independent_of_X
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_regressor_prediction_independent_of_X(strategy):
y = [0, 2, 1, 1]
X1 = [[0]] * 4
reg1 = DummyRegressor(strategy=strategy, constant=0, quantile=0.7)
reg1.fit(X1, y)
predictions1 = reg1.predict(X1)
X2 = [[1]] * 4
reg2 = DummyRegressor(strategy=strategy, constant=0, quantile=0.7)
reg2.fit(X2, y)
predictions2 = reg2.predict(X2)
assert_array_equal(predictions1, predictions2)
示例3: test_constant_strategy_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_constant_strategy_regressor():
random_state = np.random.RandomState(seed=1)
X = [[0]] * 5 # ignored
y = random_state.randn(5)
reg = DummyRegressor(strategy="constant", constant=[43])
reg.fit(X, y)
assert_array_equal(reg.predict(X), [43] * len(X))
reg = DummyRegressor(strategy="constant", constant=43)
reg.fit(X, y)
assert_array_equal(reg.predict(X), [43] * len(X))
示例4: test_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_regressor():
X = [[0]] * 4 # ignored
y = [1, 2, 1, 1]
reg = DummyRegressor()
reg.fit(X, y)
assert_array_equal(reg.predict(X), [5. / 4] * len(X))
示例5: train_classifier
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def train_classifier():
X_train = tfv.transform(video_captions_train)
X_test = tfv.transform(video_captions_test)
dummy = DummyRegressor(strategy="median")
dummy.fit(X_train, Y_train)
Y_pred_med = dummy.predict(X_test)
示例6: test_dummy_regressor_on_3D_array
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_dummy_regressor_on_3D_array():
X = np.array([[['foo']], [['bar']], [['baz']]])
y = np.array([2, 2, 2])
y_expected = np.array([2, 2, 2])
cls = DummyRegressor()
cls.fit(X, y)
y_pred = cls.predict(X)
assert_array_equal(y_pred, y_expected)
示例7: test_dummy_regressor_on_nan_value
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_dummy_regressor_on_nan_value():
X = [[np.NaN]]
y = [1]
y_expected = [1]
clf = DummyRegressor()
clf.fit(X, y)
y_pred = clf.predict(X)
assert_array_equal(y_pred, y_expected)
示例8: Regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
class Regressor(BaseEstimator):
def __init__(self):
self.clf = DummyRegressor()
def fit(self, X, y):
self.clf.fit(X, y)
def predict(self, X):
return self.clf.predict(X)
示例9: test_multioutput_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_multioutput_regressor():
X_learn = np.random.randn(10, 10)
y_learn = np.random.randn(10, 5)
mean = np.mean(y_learn, axis=0).reshape((1, -1))
X_test = np.random.randn(20, 10)
y_test = np.random.randn(20, 5)
# Correctness oracle
est = DummyRegressor()
est.fit(X_learn, y_learn)
y_pred_learn = est.predict(X_learn)
y_pred_test = est.predict(X_test)
assert_array_equal(np.tile(mean, (y_learn.shape[0], 1)), y_pred_learn)
assert_array_equal(np.tile(mean, (y_test.shape[0], 1)), y_pred_test)
_check_behavior_2d(est)
示例10: test_median_strategy_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_median_strategy_regressor():
random_state = np.random.RandomState(seed=1)
X = [[0]] * 5 # ignored
y = random_state.randn(5)
reg = DummyRegressor(strategy="median")
reg.fit(X, y)
assert_array_equal(reg.predict(X), [np.median(y)] * len(X))
示例11: test_dummy_regressor_return_std
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_dummy_regressor_return_std():
X = [[0]] * 3 # ignored
y = np.array([2, 2, 2])
y_std_expected = np.array([0, 0, 0])
cls = DummyRegressor()
cls.fit(X, y)
y_pred_list = cls.predict(X, return_std=True)
# there should be two elements when return_std is True
assert_equal(len(y_pred_list), 2)
# the second element should be all zeros
assert_array_equal(y_pred_list[1], y_std_expected)
示例12: test_mean_strategy_multioutput_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_mean_strategy_multioutput_regressor():
random_state = np.random.RandomState(seed=1)
X_learn = random_state.randn(10, 10)
y_learn = random_state.randn(10, 5)
mean = np.mean(y_learn, axis=0).reshape((1, -1))
X_test = random_state.randn(20, 10)
y_test = random_state.randn(20, 5)
# Correctness oracle
est = DummyRegressor()
est.fit(X_learn, y_learn)
y_pred_learn = est.predict(X_learn)
y_pred_test = est.predict(X_test)
_check_equality_regressor(mean, y_learn, y_pred_learn, y_test, y_pred_test)
_check_behavior_2d(est)
示例13: test_constant_strategy_multioutput_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_constant_strategy_multioutput_regressor():
random_state = np.random.RandomState(seed=1)
X_learn = random_state.randn(10, 10)
y_learn = random_state.randn(10, 5)
# test with 2d array
constants = random_state.randn(5)
X_test = random_state.randn(20, 10)
y_test = random_state.randn(20, 5)
# Correctness oracle
est = DummyRegressor(strategy="constant", constant=constants)
est.fit(X_learn, y_learn)
y_pred_learn = est.predict(X_learn)
y_pred_test = est.predict(X_test)
_check_equality_regressor(constants, y_learn, y_pred_learn, y_test, y_pred_test)
_check_behavior_2d_for_constant(est)
示例14: test_quantile_strategy_regressor
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def test_quantile_strategy_regressor():
random_state = np.random.RandomState(seed=1)
X = [[0]] * 5 # ignored
y = random_state.randn(5)
reg = DummyRegressor(strategy="quantile", quantile=0.5)
reg.fit(X, y)
assert_array_equal(reg.predict(X), [np.median(y)] * len(X))
reg = DummyRegressor(strategy="quantile", quantile=0)
reg.fit(X, y)
assert_array_equal(reg.predict(X), [np.min(y)] * len(X))
reg = DummyRegressor(strategy="quantile", quantile=1)
reg.fit(X, y)
assert_array_equal(reg.predict(X), [np.max(y)] * len(X))
reg = DummyRegressor(strategy="quantile", quantile=0.3)
reg.fit(X, y)
assert_array_equal(reg.predict(X), [np.percentile(y, q=30)] * len(X))
示例15: _minimize_simbo_general
# 需要导入模块: from sklearn.dummy import DummyRegressor [as 别名]
# 或者: from sklearn.dummy.DummyRegressor import predict [as 别名]
def _minimize_simbo_general(fun,
x0, # only used to get number of features
args=(),
callback=None,
batch_size=100,
population_size=10000,
maxiter=10000,
scorer=None, # if no scorer given, scores are constant
selector=None, # only relevant is sampler is given
sampler=None):
n_iter = int(maxiter / batch_size)
assert n_iter > 0
dummy_generator = generative_models.DummyGenerator(len(x0))
if scorer is None:
scorer = DummyRegressor()
if sampler is None:
sampler = dummy_generator
if isinstance(selector, float) and 0 < selector < 1:
selector = percentile_selector(selector)
for i in range(n_iter):
if i == 0:
batch = dummy_generator.sample(batch_size)
else:
population = sampler.sample(population_size)
scores = scorer.predict(population)
batch_w_score = heapq.nsmallest(batch_size, zip(scores, population),
key=lambda x: x[0])
batch = [v for score, v in batch_w_score]
results = optimize_utils.score_multi(fun, batch, args, callback)
selected = selector(results, batch) if selector is not None else batch
scorer.fit(batch, results)
sampler.fit(selected)
best_fval, best_x = max(zip(results, batch), key=lambda x: x[0])
nfev = batch_size * n_iter
return optimize_utils.to_result(x=best_x, fun=best_fval,
niter=n_iter, nfev=nfev)