• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python samples_generator.make_regression函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了make_regression函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"
开发者ID:orazaro,项目名称:stumbleupon_kaggle,代码行数:10,代码来源:feature_selection.py


示例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')
开发者ID:Kappie,项目名称:support_vector_machine,代码行数:7,代码来源:test_base.py


示例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)
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:7,代码来源:test_feature_select.py


示例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
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:26,代码来源:test_feature_select.py


示例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)))
开发者ID:1oscar,项目名称:scikit-learn,代码行数:25,代码来源:test_feature_select.py


示例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
开发者ID:yunleiz,项目名称:pythonprc,代码行数:30,代码来源:grad_desent.py


示例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
开发者ID:Aseeker,项目名称:scikit-learn,代码行数:30,代码来源:plot_prediction_latency.py


示例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."
开发者ID:infinitedreams9586,项目名称:StatisticsAlgo,代码行数:28,代码来源:Gradient+Descent.py


示例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)
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:26,代码来源:test_feature_select.py


示例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)
开发者ID:pandasasa,项目名称:lightning,代码行数:7,代码来源:test_sgd.py


示例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)
开发者ID:pandasasa,项目名称:lightning,代码行数:9,代码来源:test_sgd.py


示例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   
开发者ID:cadrev,项目名称:learning-machine-learning,代码行数:11,代码来源:gradient-vector.py


示例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)
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:13,代码来源:test_feature_select.py


示例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()
开发者ID:nellaivijay,项目名称:scikit-learn,代码行数:13,代码来源:test_feature_select.py


示例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
开发者ID:dmoliveira,项目名称:malss,代码行数:14,代码来源:test.py


示例16: test_linear_regression_multiple_outcome

def test_linear_regression_multiple_outcome(random_state=0):
    "Test multiple-outcome linear regressions"
    X, y = make_regression(random_state=random_state)

    Y = np.vstack((y, y)).T
    n_features = X.shape[1]

    clf = LinearRegression(fit_intercept=True)
    clf.fit((X), Y)
    assert_equal(clf.coef_.shape, (2, n_features))
    Y_pred = clf.predict(X)
    clf.fit(X, y)
    y_pred = clf.predict(X)
    assert_array_almost_equal(np.vstack((y_pred, y_pred)).T, Y_pred, decimal=3)
开发者ID:Kappie,项目名称:support_vector_machine,代码行数:14,代码来源:test_base.py


示例17: test_select_kbest_regression

def test_select_kbest_regression():
    # Test whether the relative univariate feature selection
    # gets the correct items in a simple regression problem
    # with the k best heuristic
    X, y = make_regression(n_samples=200, n_features=20, n_informative=5, shuffle=False, random_state=0, noise=10)

    univariate_filter = SelectKBest(f_regression, k=5)
    X_r = univariate_filter.fit(X, y).transform(X)
    assert_best_scores_kept(univariate_filter)
    X_r2 = GenericUnivariateSelect(f_regression, mode="k_best", param=5).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)
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:15,代码来源:test_feature_select.py


示例18: 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) 
    
    # criteria for the gradient descent
    learning_rate        = 0.1
    convergence_criteria = 0.01 
    
    # get the slope
    slope, intercept, iterations = grad_desc(x, y, learning_rate, convergence_criteria, 1000)

    print 'slope: ' + str(slope)
    print 'intercept: ' + str(intercept)
    print 'number of iterations: ' + str(iterations)
开发者ID:cadrev,项目名称:learning-machine-learning,代码行数:15,代码来源:gradient-descent.py


示例19: make_test_regression

def make_test_regression(n_features=30, n_informative=5, n_samples=5000):
    import pandas as pd
    X, y = make_regression(n_samples=n_samples, n_features=n_features,
                           n_informative=n_informative, noise=0.5,
                           shuffle=False, random_state=None)

    if False:
        idx_sel = f_regression_select(X, y, verbose=0)
        print("f_regression_select:", len(idx_sel), idx_sel)

    predictors = ["p{}".format(i) for i in range(X.shape[1])]
    target = 'y'
    df = pd.DataFrame(np.c_[X, y], columns=predictors+[target])
    # print(df.head())
    return df, predictors, target
开发者ID:orazaro,项目名称:kgml,代码行数:15,代码来源:feature_selection.py


示例20: test_select_fwe_regression

def test_select_fwe_regression():
    # Test whether the relative univariate feature selection
    # gets the correct items in a simple regression problem
    # with the fwe heuristic
    X, y = make_regression(n_samples=200, n_features=20, n_informative=5, shuffle=False, random_state=0)

    univariate_filter = SelectFwe(f_regression, alpha=0.01)
    X_r = univariate_filter.fit(X, y).transform(X)
    X_r2 = GenericUnivariateSelect(f_regression, mode="fwe", param=0.01).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[:5], np.ones((5,), dtype=np.bool))
    assert_less(np.sum(support[5:] == 1), 2)
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:15,代码来源:test_feature_select.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap