当前位置: 首页>>代码示例>>Python>>正文


Python datasets.make_friedman1函数代码示例

本文整理汇总了Python中sklearn.datasets.make_friedman1函数的典型用法代码示例。如果您正苦于以下问题:Python make_friedman1函数的具体用法?Python make_friedman1怎么用?Python make_friedman1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了make_friedman1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的sklearn.datasets.make_friedman1函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。