本文整理汇总了Python中sklearn.datasets.samples_generator.make_regression函数的典型用法代码示例。如果您正苦于以下问题:Python make_regression函数的具体用法?Python make_regression怎么用?Python make_regression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_regression函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_f_regression_select
def test_f_regression_select():
print "==> a lot of features"
X, y = make_regression(n_samples=20000, n_features=200, n_informative=150,
shuffle=False, random_state=0)
idx_sel = f_regression_select(X, y, verbose=2)
print "==> few ones"
X, y = make_regression(n_samples=200, n_features=20, n_informative=5, noise=0.5,
shuffle=False, random_state=0)
idx_sel = f_regression_select(X, y, verbose=1)
print "tests ok"
示例2: test_csr_sparse_center_data
def test_csr_sparse_center_data():
# Test output format of sparse_center_data, when input is csr
X, y = make_regression()
X[X < 2.5] = 0.0
csr = sparse.csr_matrix(X)
csr_, y, _, _, _ = sparse_center_data(csr, y, True)
assert_equal(csr_.getformat(), 'csr')
示例3: test_invalid_percentile
def test_invalid_percentile():
X, y = make_regression(n_samples=10, n_features=20, n_informative=2, shuffle=False, random_state=0)
assert_raises(ValueError, SelectPercentile(percentile=-1).fit, X, y)
assert_raises(ValueError, SelectPercentile(percentile=101).fit, X, y)
assert_raises(ValueError, GenericUnivariateSelect(mode="percentile", param=-1).fit, X, y)
assert_raises(ValueError, GenericUnivariateSelect(mode="percentile", param=101).fit, X, y)
示例4: single_fdr
def single_fdr(alpha, n_informative, random_state):
X, y = make_regression(
n_samples=150,
n_features=20,
n_informative=n_informative,
shuffle=False,
random_state=random_state,
noise=10,
)
with warnings.catch_warnings(record=True):
# Warnings can be raised when no features are selected
# (low alpha or very noisy data)
univariate_filter = SelectFdr(f_regression, alpha=alpha)
X_r = univariate_filter.fit(X, y).transform(X)
X_r2 = GenericUnivariateSelect(f_regression, mode="fdr", param=alpha).fit(X, y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
num_false_positives = np.sum(support[n_informative:] == 1)
num_true_positives = np.sum(support[:n_informative] == 1)
if num_false_positives == 0:
return 0.0
false_discovery_rate = num_false_positives / (num_true_positives + num_false_positives)
return false_discovery_rate
示例5: test_select_percentile_regression
def test_select_percentile_regression():
"""
Test whether the relative univariate feature selection
gets the correct items in a simple regression problem
with the percentile heuristic
"""
X, y = make_regression(n_samples=200, n_features=20,
n_informative=5, shuffle=False, random_state=0)
univariate_filter = SelectPercentile(f_regression, percentile=25)
X_r = univariate_filter.fit(X, y).transform(X)
assert_best_scores_kept(univariate_filter)
X_r2 = GenericUnivariateSelect(
f_regression, mode='percentile', param=25).fit(X, y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
gtruth = np.zeros(20)
gtruth[:5] = 1
assert_array_equal(support, gtruth)
X_2 = X.copy()
X_2[:, np.logical_not(support)] = 0
assert_array_equal(X_2, univariate_filter.inverse_transform(X_r))
# Check inverse_transform respects dtype
assert_array_equal(X_2.astype(bool),
univariate_filter.inverse_transform(X_r.astype(bool)))
示例6: prepare_data
def prepare_data(mydata = True):
'''
dim(X) -> (10,2)
each_row(X) -> training point
each_column(X) -> x_0, x_1
dim(Y) -> (10,1)
each_row(Y) -> result
dim(theta) ->(2,1)
theta[0][0] -> x_0
theta[1][0] -> x_1
Odd Even Linked List'''
if mydata:
num_trainingpoint = 3
X = np.array([range(num_trainingpoint)]).T
theta = np.array([[1],[2]])
x0 = np.ones(shape=(num_trainingpoint,1))
m, n = np.shape(X)
X = np.c_[ np.ones(m), X]
Y = X.dot(theta)
else:
X, Y = make_regression(n_samples=100, n_features=1, n_informative=1,
random_state=0, noise=35)
m, n = np.shape(X)
X = np.c_[ np.ones(m), X] # insert column
theta = np.ones(shape=(2,1))
return X, Y, theta
示例7: generate_dataset
def generate_dataset(n_train, n_test, n_features, noise=0.1, verbose=False):
"""Generate a regression dataset with the given parameters."""
if verbose:
print("generating dataset...")
X, y, coef = make_regression(n_samples=n_train + n_test,
n_features=n_features, noise=noise, coef=True)
X_train = X[:n_train]
y_train = y[:n_train]
X_test = X[n_train:]
y_test = y[n_train:]
idx = np.arange(n_train)
np.random.seed(13)
np.random.shuffle(idx)
X_train = X_train[idx]
y_train = y_train[idx]
std = X_train.std(axis=0)
mean = X_train.mean(axis=0)
X_train = (X_train - mean) / std
X_test = (X_test - mean) / std
std = y_train.std(axis=0)
mean = y_train.mean(axis=0)
y_train = (y_train - mean) / std
y_test = (y_test - mean) / std
gc.collect()
if verbose:
print("ok")
return X_train, y_train, X_test, y_test
示例8: create_regression
def create_regression():
x, y = make_regression(
n_samples=100,
n_features=1,
n_informative=1,
random_state=0,
noise=35
)
# learning rate
alpha = 1
# convergence criteria
ep = 1e-12
# max iterations
max_iter = 20
theta0, theta1, cost_f = gradient_descent(alpha, x, y, ep, max_iter)
slope, intercept, r_value, p_value, slope_std_error = stats.linregress(x[:, 0], y)
print ('intercept = %s slope = %s') % (intercept, slope)
for i in range(x.shape[0]):
y_predict = theta0 + theta1 * x
pylab.plot(x, y, 'o')
pylab.plot(x, y_predict, '-')
pylab.show()
print "Done."
示例9: test_mutual_info_regression
def test_mutual_info_regression():
X, y = make_regression(n_samples=100, n_features=10, n_informative=2,
shuffle=False, random_state=0, noise=10)
# Test in KBest mode.
univariate_filter = SelectKBest(mutual_info_regression, k=2)
X_r = univariate_filter.fit(X, y).transform(X)
assert_best_scores_kept(univariate_filter)
X_r2 = GenericUnivariateSelect(
mutual_info_regression, mode='k_best', param=2).fit(X, y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
gtruth = np.zeros(10)
gtruth[:2] = 1
assert_array_equal(support, gtruth)
# Test in Percentile mode.
univariate_filter = SelectPercentile(mutual_info_regression, percentile=20)
X_r = univariate_filter.fit(X, y).transform(X)
X_r2 = GenericUnivariateSelect(mutual_info_regression, mode='percentile',
param=20).fit(X, y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
gtruth = np.zeros(10)
gtruth[:2] = 1
assert_array_equal(support, gtruth)
示例10: test_regression_squared_loss
def test_regression_squared_loss():
X, y = make_regression(n_samples=100, n_features=10, n_informative=8, random_state=0)
reg = SGDRegressor(loss="squared", penalty="l2", learning_rate="constant", eta0=1e-2, random_state=0)
reg.fit(X, y)
pred = reg.predict(X)
assert_almost_equal(np.mean((pred - y) ** 2), 4.913, 3)
示例11: test_regression_squared_loss_multiple_output
def test_regression_squared_loss_multiple_output():
X, y = make_regression(n_samples=100, n_features=10, n_informative=8, random_state=0)
reg = SGDRegressor(loss="squared", penalty="l2", learning_rate="constant", eta0=1e-2, random_state=0, max_iter=10)
Y = np.zeros((len(y), 2))
Y[:, 0] = y
Y[:, 1] = y
reg.fit(X, Y)
pred = reg.predict(X)
assert_almost_equal(np.mean((pred - Y) ** 2), 4.541, 3)
示例12: main
def main():
# load the dataset to the two variables
X, y = make_regression(n_samples=100, n_features=1, n_informative=1, random_state=0, noise=35)
m = np.shape(X)[0]
X = np.c_[ np.ones(m), X]
# get the slope
theta = grad_desc_vector(X, y, 0.001, 1500)
print theta
示例13: test_select_percentile_regression_full
def test_select_percentile_regression_full():
# Test whether the relative univariate feature selection
# selects all features when '100%' is asked.
X, y = make_regression(n_samples=200, n_features=20, n_informative=5, shuffle=False, random_state=0)
univariate_filter = SelectPercentile(f_regression, percentile=100)
X_r = univariate_filter.fit(X, y).transform(X)
assert_best_scores_kept(univariate_filter)
X_r2 = GenericUnivariateSelect(f_regression, mode="percentile", param=100).fit(X, y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
gtruth = np.ones(20)
assert_array_equal(support, gtruth)
示例14: test_f_regression
def test_f_regression():
"""
Test whether the F test yields meaningful results
on a simple simulated regression problem
"""
X, Y = make_regression(n_samples=200, n_features=20, n_informative=5, shuffle=False, random_state=0)
F, pv = f_regression(X, Y)
assert (F > 0).all()
assert (pv > 0).all()
assert (pv < 1).all()
assert (pv[:5] < 0.05).all()
assert (pv[5:] > 1.0e-4).all()
示例15: test_regression_big
def test_regression_big():
X, y = make_regression(n_samples=200000,
n_features=10,
n_informative=5,
noise=30.0,
random_state=0)
X = pd.DataFrame(X)
y = pd.Series(y)
cls = MALSS(X, y, 'regression', n_jobs=3)
cls.execute()
# cls.make_report('test_regression_big')
assert len(cls.algorithms) == 1
assert cls.algorithms[0].best_score is not None