本文整理汇总了Python中sklearn.datasets.make_friedman1函数的典型用法代码示例。如果您正苦于以下问题:Python make_friedman1函数的具体用法?Python make_friedman1怎么用?Python make_friedman1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_friedman1函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _create_test_data
def _create_test_data(self):
X, y = datasets.make_friedman1(n_samples=20, random_state=13)
X = pd.DataFrame(X)
Y = Response.from_array(y / y.max())
Z = Partition(size=X.shape[0], folds=5, reps=1, total_size=X.shape[0])
Z.set(max_reps=1, max_folds=0)
return Container(X), Y, Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:7,代码来源:test_calib.py
示例2: setUp
def setUp(self):
# Friedman1
self.X, self.y = datasets.make_friedman1(n_samples=500,
random_state=1,
noise=1.0)
self.X_train, self.y_train = self.X[:400], self.y[:400]
self.X_test, self.y_test = self.X[400:], self.y[400:]
开发者ID:Kjeanclaude,项目名称:rgf_python,代码行数:7,代码来源:test.py
示例3: gradient_boosting
def gradient_boosting(features_values_temp, rows_temp, columns_temp, prediction_values_temp, kernel, threshold):
#kernel: linear, poly, rbf, sigmoid, precomputed
rows = 0
while rows_temp > 0:
rows = rows + 1
rows_temp = rows_temp - 1
columns = 0
while columns_temp > 0:
columns = columns + 1
columns_temp = columns_temp - 1
features_values = [x for x in features_values_temp]
prediction_values = [y for y in prediction_values_temp]
rotated = convert_list_to_matrix(features_values, rows, columns)
scores = np.array(prediction_values)
threshold = float(threshold)
estimator = SVR(kernel=kernel) # try to change to the model for which the test is gonna run (lasso, ridge, etc.)
X, y = make_friedman1(n_samples=1200, random_state=0, noise=1.0)
X_train, X_test = X[:200], X[200:]
y_train, y_test = y[:200], y[200:]
est = GradientBoostingRegressor(n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0, loss='ls').fit(X_train, y_train)
mean_squared_error(y_test, est.predict(X_test))
开发者ID:adityasubramanian,项目名称:kaggle_titanic,代码行数:30,代码来源:feature_selection.py
示例4: test_regression_synthetic
def test_regression_synthetic():
"""Test on synthetic regression datasets used in Leo Breiman,
`Bagging Predictors?. Machine Learning 24(2): 123-140 (1996). """
random_state = check_random_state(1)
regression_params = {'n_estimators': 100, 'max_depth': 4,
'min_samples_split': 1, 'learning_rate': 0.1,
'loss': 'ls'}
# Friedman1
X, y = datasets.make_friedman1(n_samples=1200,
random_state=random_state, noise=1.0)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
clf = GradientBoostingRegressor()
clf.fit(X_train, y_train)
mse = mean_squared_error(y_test, clf.predict(X_test))
assert mse < 5.0, "Failed on Friedman1 with mse = %.4f" % mse
# Friedman2
X, y = datasets.make_friedman2(n_samples=1200, random_state=random_state)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
clf = GradientBoostingRegressor(**regression_params)
clf.fit(X_train, y_train)
mse = mean_squared_error(y_test, clf.predict(X_test))
assert mse < 1700.0, "Failed on Friedman2 with mse = %.4f" % mse
# Friedman3
X, y = datasets.make_friedman3(n_samples=1200, random_state=random_state)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
clf = GradientBoostingRegressor(**regression_params)
clf.fit(X_train, y_train)
mse = mean_squared_error(y_test, clf.predict(X_test))
assert mse < 0.015, "Failed on Friedman3 with mse = %.4f" % mse
开发者ID:ChuntheQhai,项目名称:Dota2-Heroes-Recommendation,代码行数:35,代码来源:test_gradient_boosting.py
示例5: test_make_friedman1
def test_make_friedman1():
X, y = make_friedman1(n_samples=5, n_features=10, noise=0.0, random_state=0)
assert_equal(X.shape, (5, 10), "X shape mismatch")
assert_equal(y.shape, (5,), "y shape mismatch")
assert_array_almost_equal(
y, 10 * np.sin(np.pi * X[:, 0] * X[:, 1]) + 20 * (X[:, 2] - 0.5) ** 2 + 10 * X[:, 3] + 5 * X[:, 4]
)
开发者ID:93sam,项目名称:scikit-learn,代码行数:9,代码来源:test_samples_generator.py
示例6: test
def test():
from sklearn.datasets import make_friedman1
from sklearn.svm import SVR
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = SVR(kernel="linear")
selector = RFECVp(estimator, step=1, cv=5)
selector = selector.fit(X, y)
print selector.support_ # doctest: +NORMALIZE_WHITESPACE
print selector.ranking_
开发者ID:orazaro,项目名称:stumbleupon_kaggle,代码行数:9,代码来源:rfecv.py
示例7: load_toy_dataset
def load_toy_dataset():
X, Y = make_friedman1(n_samples=200, n_features=15)
# X = [
# [1,1,1,1,1],
# [2,2,2,2,2],
# [3,3,3,3,3],
# ]
# Y = [1.1,2.2,3.3]
return np.asarray(X), np.asarray(Y)
开发者ID:AlonAzrael,项目名称:Golang-ExtraTrees,代码行数:10,代码来源:extra_tree.ultra.singletree.py
示例8: genFriedman
def genFriedman(self, i=1, N=240, D=10):
if i not in range(1,4):
raise Exception('not a correct dataset')
if i == 1:
X, Y = datasets.make_friedman1(N, D )
if i == 2:
X, Y = datasets.make_friedman2(N, D)
if i == 3:
X, Y = datasets.make_friedman3(N, D)
return X, Y
开发者ID:adhaka,项目名称:dd2434project,代码行数:13,代码来源:DataSets.py
示例9: generate_baseline_data
def generate_baseline_data(include_cat):
X, y = datasets.make_friedman1(NUM_SAMPLES, 5, 100, 1)
# convert to a binomial
prob = 1 / (1 + np.exp(-y))
y = np.random.binomial(1, prob)
print('Event rate = {0:4.4f}'.format(np.sum(y) / NUM_SAMPLES))
data = np.hstack((y.reshape(-1, 1), X))
data = pd.DataFrame(data, columns=['y', 'x0', 'x1', 'x2', 'x3', 'x4'])
if include_cat is True:
data['c'] = data.apply(lambda row: 'A' if row.y == 1 else 'B', axis=1)
return data
开发者ID:StevenLOL,项目名称:h2o-3,代码行数:16,代码来源:pyunit_pubdev_4697_early_stop_gbm.py
示例10: make_sample
def make_sample():
"""
Return (X_train, X_test, y_train, y_test)
"""
X, y = make_friedman1(n_samples=1200, random_state=0, noise=1.0)
X_train, X_test = X[:200], X[200:]
y_train, y_test = y[:200], y[200:]
result = (
X_train,
X_test,
y_train,
y_test
)
return result
开发者ID:Sandy4321,项目名称:test_gbm_rf,代码行数:16,代码来源:test_gbm_rf.py
示例11: rf_fear_test_home
def rf_fear_test_home(n=10,n_trees=10):
cblparallel.start_port_forwarding()
# Data
X, y = make_friedman1(n_samples=1200, random_state=0, noise=1.0)
X_train, X_test = X[:200], X[200:]
y_train, y_test = y[:200], y[200:]
# Params
#local_temp_path = os.path.abspath('../temp/')
#remote_temp_path = 'python/'
# Write data file locally
#data_file = mkstemp_safe(cblparallel.config.LOCAL_TEMP_PATH, '.p')
data_file = mkstemp_safe(cblparallel.config.HOME_TEMP_PATH, '.p')
with open(data_file, 'w') as f:
pickle.dump((X_train, y_train, X_test), f)
# Prepare code
scripts = [reduced_tree_code % {'data_file' : os.path.join(cblparallel.config.REMOTE_TEMP_PATH, os.path.split(data_file)[-1]),
'n_trees' : n_trees,
'random_state' : i * n_trees,
'output_file' : '%(output_file)s',
'flag_file' : '%(flag_file)s'} for i in range(n)]
# Submit to fear
with cblparallel.fear(via_gate=True) as fear:
fear.copy_to(data_file, os.path.join(cblparallel.config.REMOTE_TEMP_PATH, os.path.split(data_file)[-1]))
output_files = cblparallel.run_batch_on_fear(scripts, max_jobs=1000)
fear.rm(os.path.join(cblparallel.config.REMOTE_TEMP_PATH, os.path.split(data_file)[-1]))
# Kill local data file
os.remove(data_file)
# Now do something with the output
estimators = []
predictions = []
for output_file in output_files:
with open(output_file, 'r') as f:
#(estimator, prediction) = pickle.load(f)
prediction = np.genfromtxt(output_file, delimiter=',')
os.remove(output_file)
#estimators.append(estimator)
predictions.append(prediction)
#ens = EnsembleRegressor(estimators)
#return RMSE(X_test, y_test, ens)
ens_pred = np.mean(predictions, axis=0)
return RMSE_y(y_test, ens_pred)
开发者ID:jamesrobertlloyd,项目名称:fearsome_forest,代码行数:47,代码来源:sandpit.py
示例12: rf_fear_test
def rf_fear_test(n=10,n_trees=1000):
# Data
X, y = make_friedman1(n_samples=1200, random_state=0, noise=1.0)
X_train, X_test = X[:200], X[200:]
y_train, y_test = y[:200], y[200:]
# Params
local_temp_path = os.path.abspath('../temp/')
remote_temp_path = 'python/'
# Write data file locally
data_file = mkstemp_safe(local_temp_path, '.p')
with open(data_file, 'w') as f:
pickle.dump((X_train, y_train, X_test), f)
# Prepare code
scripts = [tree_code % {'data_file' : os.path.split(data_file)[-1],
'n_trees' : n_trees,
'random_state' : i * n_trees,
'output_file' : '%(output_file)s',
'flag_file' : '%(flag_file)s'} for i in range(n)]
# Submit to fear
with pyfear.fear() as fear:
fear.copy_to(data_file, os.path.join(remote_temp_path, os.path.split(data_file)[-1]))
output_files = pyfear.run_python_jobs(scripts, local_temp_path, remote_temp_path, fear)
fear.rm(os.path.join(remote_temp_path, os.path.split(data_file)[-1]))
# Kill local data file
os.remove(data_file)
# Now do something with the output
estimators = []
predictions = []
for output_file in output_files:
with open(output_file, 'r') as f:
#(estimator, prediction) = pickle.load(f)
prediction = np.genfromtxt(output_file, delimiter=',')
os.remove(output_file)
#estimators.append(estimator)
predictions.append(prediction)
#ens = EnsembleRegressor(estimators)
#return RMSE(X_test, y_test, ens)
ens_pred = np.mean(predictions, axis=0)
return RMSE_y(y_test, ens_pred)
开发者ID:jamesrobertlloyd,项目名称:fearsome_forest,代码行数:45,代码来源:sandpit.py
示例13: test_staged_predict
def test_staged_predict():
# Test whether staged decision function eventually gives
# the same prediction.
X, y = datasets.make_friedman1(n_samples=1200, random_state=1, noise=1.0)
X_train, y_train = X[:200], y[:200]
X_test = X[200:]
clf = GradientBoostingRegressor()
# test raise ValueError if not fitted
assert_raises(ValueError, lambda X: np.fromiter(clf.staged_predict(X), dtype=np.float64), X_test)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
# test if prediction for last stage equals ``predict``
for y in clf.staged_predict(X_test):
assert_equal(y.shape, y_pred.shape)
assert_array_equal(y_pred, y)
开发者ID:arvindchari88,项目名称:newGitTest,代码行数:18,代码来源:test_gradient_boosting.py
示例14: test_regression_synthetic
def test_regression_synthetic():
# Test on synthetic regression datasets used in Leo Breiman,
# `Bagging Predictors?. Machine Learning 24(2): 123-140 (1996).
random_state = check_random_state(1)
regression_params = {'n_estimators': 100, 'max_depth': 4,
'min_samples_split': 2, 'learning_rate': 0.1,
'loss': 'ls'}
# Friedman1
X, y = datasets.make_friedman1(n_samples=1200,
random_state=random_state,
noise=1.0)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
for presort in True, False:
clf = GradientBoostingRegressor(presort=presort)
clf.fit(X_train, y_train)
mse = mean_squared_error(y_test, clf.predict(X_test))
assert_less(mse, 5.0)
# Friedman2
X, y = datasets.make_friedman2(n_samples=1200, random_state=random_state)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
for presort in True, False:
regression_params['presort'] = presort
clf = GradientBoostingRegressor(**regression_params)
clf.fit(X_train, y_train)
mse = mean_squared_error(y_test, clf.predict(X_test))
assert_less(mse, 1700.0)
# Friedman3
X, y = datasets.make_friedman3(n_samples=1200, random_state=random_state)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
for presort in True, False:
regression_params['presort'] = presort
clf = GradientBoostingRegressor(**regression_params)
clf.fit(X_train, y_train)
mse = mean_squared_error(y_test, clf.predict(X_test))
assert_less(mse, 0.015)
开发者ID:amueller,项目名称:scikit-learn,代码行数:44,代码来源:test_gradient_boosting.py
示例15: test_regressor
def test_regressor(self):
X, y = datasets.make_friedman1(n_samples=1200,
random_state=1,
noise=1.0)
X_train, y_train = X[:200], y[:200]
index = [i for i in range(200)]
rf = RandomForestRegressor()
jrf = JoblibedRegressor(rf, "rfr", cache_dir='')
jrf.fit(X_train, y_train, index)
prediction = jrf.predict(X_train, index)
mse = mean_squared_error(y_train, prediction)
assert_less(mse, 6.0)
rf = RandomForestRegressor(n_estimators=20)
jrf = JoblibedRegressor(rf, "rfr", cache_dir='')
jrf.fit(X_train, y_train, index)
prediction2 = jrf.predict(X_train, index)
assert_allclose(prediction, prediction2)
开发者ID:fukatani,项目名称:stacked_generalization,代码行数:19,代码来源:test.py
示例16: local_forest_test
def local_forest_test(n=10,n_trees=10):
# Data
X, y = make_friedman1(n_samples=1200, random_state=0, noise=1.0)
X_train, X_test = X[:200], X[200:]
y_train, y_test = y[:200], y[200:]
# Params
# local_temp_path = os.path.abspath('../temp/')
# remote_temp_path = 'python/'
# Write data file locally
data_file = mkstemp_safe(cblparallel.config.HOME_TEMP_PATH, '.p')
with open(data_file, 'w') as f:
pickle.dump((X_train, y_train, X_test), f)
# Prepare code
scripts = [reduced_tree_code % {'data_file' : data_file,
'n_trees' : n_trees,
'random_state' : i * n_trees,
'output_file' : '%(output_file)s',
'flag_file' : '%(flag_file)s'} for i in range(n)]
# Run bacth in parallel)
output_files = cblparallel.run_batch_locally(scripts)
# Kill local data file
os.remove(data_file)
# Now do something with the output
estimators = []
predictions = []
for output_file in output_files:
with open(output_file, 'r') as f:
#(estimator, prediction) = pickle.load(f)
prediction = np.genfromtxt(output_file, delimiter=',')
os.remove(output_file)
#estimators.append(estimator)
predictions.append(prediction)
#ens = EnsembleRegressor(estimators)
#return RMSE(X_test, y_test, ens)
ens_pred = np.mean(predictions, axis=0)
return RMSE_y(y_test, ens_pred)
开发者ID:jamesrobertlloyd,项目名称:fearsome_forest,代码行数:42,代码来源:sandpit.py
示例17: test_rfe_min_step
def test_rfe_min_step():
n_features = 10
X, y = make_friedman1(n_samples=50, n_features=n_features, random_state=0)
n_samples, n_features = X.shape
estimator = SVR(kernel="linear")
# Test when floor(step * n_features) <= 0
selector = RFE(estimator, step=0.01)
sel = selector.fit(X, y)
assert_equal(sel.support_.sum(), n_features // 2)
# Test when step is between (0,1) and floor(step * n_features) > 0
selector = RFE(estimator, step=0.20)
sel = selector.fit(X, y)
assert_equal(sel.support_.sum(), n_features // 2)
# Test when step is an integer
selector = RFE(estimator, step=5)
sel = selector.fit(X, y)
assert_equal(sel.support_.sum(), n_features // 2)
开发者ID:amueller,项目名称:scikit-learn,代码行数:20,代码来源:test_rfe.py
示例18: test_stacked_regressor
def test_stacked_regressor(self):
bclf = LinearRegression()
clfs = [RandomForestRegressor(n_estimators=50, random_state=1),
GradientBoostingRegressor(n_estimators=25, random_state=1),
Ridge(random_state=1)]
# Friedman1
X, y = datasets.make_friedman1(n_samples=1200,
random_state=1,
noise=1.0)
X_train, y_train = X[:200], y[:200]
X_test, y_test = X[200:], y[200:]
sr = StackedRegressor(bclf,
clfs,
n_folds=3,
verbose=0,
oob_score_flag=True)
sr.fit(X_train, y_train)
mse = mean_squared_error(y_test, sr.predict(X_test))
assert_less(mse, 6.0)
开发者ID:idoamihai,项目名称:stacked_generalization-1,代码行数:21,代码来源:test.py
示例19: create_reg_syn_data
def create_reg_syn_data(self, reps=1, rows=None):
"""Create synthetic data using friedman1 sample generator.
Returns
-------
X : pd.DataFrame
The input as a pd.DataFrame.
Y : np.ndarray
The targets as a ndarray
Z : Partition
The partition object holding 5-folds.
"""
if rows is None:
rows = 1000
X, y = make_friedman1(n_samples=rows, random_state=13)
X = pd.DataFrame(data=X, columns=map(unicode, range(X.shape[1])))
Y = Response.from_array(y)
Z = Partition(size=X.shape[0], folds=5, reps=reps,total_size=X.shape[0])
Z.set(max_reps=reps,max_folds=0)
X = Container(dataframe=X)
return X, Y, Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:21,代码来源:base_task_test.py
示例20: error_curves
def error_curves(estimator, parameter, parameter_values, n_repeat=100):
all_train_errors = []
all_test_errors = []
for i in range(n_repeat):
X, y = make_friedman1(n_samples=200)
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.7)
train_errors = []
test_errors = []
for j, p in enumerate(parameter_values):
est = estimator(**{parameter: p})
est.fit(X_train, y_train)
train_errors.append(mean_squared_error(y_train, est.predict(X_train)))
test_errors.append(mean_squared_error(y_test, est.predict(X_test)))
all_train_errors.append(train_errors)
all_test_errors.append(test_errors)
return all_train_errors, all_test_errors
开发者ID:ASBoldt,项目名称:phd-thesis,代码行数:22,代码来源:ch2_train_test_error.py
注:本文中的sklearn.datasets.make_friedman1函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论