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


Python datasets.make_regression函数代码示例

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


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

示例1: testParallelPen

 def testParallelPen(self): 
     #Check if penalisation == inf when treeSize < gamma 
     numExamples = 100
     X, y = data.make_regression(numExamples) 
     learner = DecisionTreeLearner(pruneType="CART", maxDepth=10, minSplit=2)
     
     paramDict = {} 
     paramDict["setGamma"] = numpy.array(numpy.round(2**numpy.arange(1, 10, 0.5)-1), dtype=numpy.int)
     
     folds = 3
     alpha = 1.0
     Cvs = numpy.array([(folds-1)*alpha])
     
     idx = Sampling.crossValidation(folds, X.shape[0])
     
     resultsList = learner.parallelPen(X, y, idx, paramDict, Cvs)
     
     learner, trainErrors, currentPenalties = resultsList[0]
     
     learner.setGamma(2**10)
     treeSize = 0
     #Let's work out the size of the unpruned tree 
     for trainInds, testInds in idx: 
         trainX = X[trainInds, :]
         trainY = y[trainInds]
         
         learner.learnModel(trainX, trainY)
         treeSize += learner.tree.size 
     
     treeSize /= float(folds)         
     
     self.assertTrue(numpy.isinf(currentPenalties[paramDict["setGamma"]>treeSize]).all())      
     self.assertTrue(not numpy.isinf(currentPenalties[paramDict["setGamma"]<treeSize]).all())
开发者ID:malcolmreynolds,项目名称:APGL,代码行数:33,代码来源:DecisionTreeLearnerTest.py

示例2: test_partial_dependence_helpers

def test_partial_dependence_helpers(est, method, target_feature):
    # Check that what is returned by _partial_dependence_brute or
    # _partial_dependence_recursion is equivalent to manually setting a target
    # feature to a given value, and computing the average prediction over all
    # samples.
    # This also checks that the brute and recursion methods give the same
    # output.

    X, y = make_regression(random_state=0)
    # The 'init' estimator for GBDT (here the average prediction) isn't taken
    # into account with the recursion method, for technical reasons. We set
    # the mean to 0 to that this 'bug' doesn't have any effect.
    y = y - y.mean()
    est.fit(X, y)

    # target feature will be set to .5 and then to 123
    features = np.array([target_feature], dtype=np.int32)
    grid = np.array([[.5],
                     [123]])

    if method == 'brute':
        pdp = _partial_dependence_brute(est, grid, features, X,
                                        response_method='auto')
    else:
        pdp = _partial_dependence_recursion(est, grid, features)

    mean_predictions = []
    for val in (.5, 123):
        X_ = X.copy()
        X_[:, target_feature] = val
        mean_predictions.append(est.predict(X_).mean())

    pdp = pdp[0]  # (shape is (1, 2) so make it (2,))
    assert_allclose(pdp, mean_predictions, atol=1e-3)
开发者ID:manhhomienbienthuy,项目名称:scikit-learn,代码行数:34,代码来源:test_partial_dependence.py

示例3: test_regression_custom_mse

def test_regression_custom_mse():

    X, y = make_regression(n_samples=1000,
                           n_features=5,
                           n_informative=2,
                           n_targets=1,
                           random_state=123,
                           shuffle=False)

    X_train, X_test, y_train, y_test = train_test_split(
        X, y, test_size=0.3, random_state=123)

    svm = SVR(kernel='rbf', gamma='auto')
    svm.fit(X_train, y_train)

    imp_vals, imp_all = feature_importance_permutation(
        predict_method=svm.predict,
        X=X_test,
        y=y_test,
        metric=mean_squared_error,
        num_rounds=1,
        seed=123)

    norm_imp_vals = imp_vals / np.abs(imp_vals).max()

    assert imp_vals.shape == (X_train.shape[1], )
    assert imp_all.shape == (X_train.shape[1], 1)
    assert norm_imp_vals[0] == -1.
开发者ID:rasbt,项目名称:mlxtend,代码行数:28,代码来源:test_feature_importance.py

示例4: __init__

 def __init__(self, n_samples, n_features, n_informative, normalize_y = False, normalize = True, centerdata = True,
              transformation=NullTransformation(), fit_intercept = True):
     self.n_samples = n_samples
     self.n_features = n_features
     X, Y = datasets.make_regression(n_samples=self.n_samples, n_features=self.n_features,
                                               n_informative=n_informative, shuffle=False, random_state=11)
     XTrain, XTest, YTrain, YTest = train_test_split(X, Y, test_size=0.33,random_state=0)
     self.XTrain_orig = XTrain
     self.XTest_orig = XTest
     self.YTrain_orig = YTrain
     self.YTest_orig = YTest
     if centerdata==True:
         self.XTrain, YTrain, X_mean, y_mean, X_std = center_data(XTrain, YTrain, fit_intercept=fit_intercept, normalize = normalize)
         self.XTest, YTest = self.center_test(XTest,YTest,X_mean,y_mean,X_std)
         if normalize_y:
             self.YTrain, self.YTest = self.normalize_labels(YTrain, YTest)
         else:
             self.YTrain = YTrain
             self.YTest = YTest
     else:
         self.XTrain = XTrain
         self.YTrain = YTrain
         self.XTest = XTest
         self.YTest = YTest
     self.transformation = transformation
开发者ID:marty10,项目名称:LASSO,代码行数:25,代码来源:ExtractDataset.py

示例5: test_make_regression

def test_make_regression():
    X, y, c = make_regression(n_samples=100, n_features=10, n_informative=3,
                              effective_rank=5, coef=True, bias=0.0,
                              noise=1.0, random_state=0)

    assert_equal(X.shape, (100, 10), "X shape mismatch")
    assert_equal(y.shape, (100,), "y shape mismatch")
    assert_equal(c.shape, (10,), "coef shape mismatch")
    assert_equal(sum(c != 0.0), 3, "Unexpected number of informative features")

    # Test that y ~= np.dot(X, c) + bias + N(0, 1.0).
    assert_almost_equal(np.std(y - np.dot(X, c)), 1.0, decimal=1)

    # Test with small number of features.
    X, y = make_regression(n_samples=100, n_features=1)  # n_informative=3
    assert_equal(X.shape, (100, 1))
开发者ID:Adrien-NK,项目名称:scikit-learn,代码行数:16,代码来源:test_samples_generator.py

示例6: test_multi_predict

    def test_multi_predict(self):
        from sklearn.datasets import make_regression
        from sklearn.model_selection import train_test_split

        n = 1000
        X, y = make_regression(n, random_state=rng)
        X_train, X_test, y_train, y_test = train_test_split(X, y,
                                                            random_state=123)
        dtrain = xgb.DMatrix(X_train, label=y_train)
        dtest = xgb.DMatrix(X_test)

        params = {}
        params["tree_method"] = "gpu_hist"

        params['predictor'] = "gpu_predictor"
        bst_gpu_predict = xgb.train(params, dtrain)

        params['predictor'] = "cpu_predictor"
        bst_cpu_predict = xgb.train(params, dtrain)

        predict0 = bst_gpu_predict.predict(dtest)
        predict1 = bst_gpu_predict.predict(dtest)
        cpu_predict = bst_cpu_predict.predict(dtest)

        assert np.allclose(predict0, predict1)
        assert np.allclose(predict0, cpu_predict)
开发者ID:rfru,项目名称:xgboost,代码行数:26,代码来源:test_gpu_prediction.py

示例7: regression_data

def regression_data():
    X, y = make_regression(
        1000, 20, n_informative=10, bias=0, random_state=0)
    X, y = X.astype(np.float32), y.astype(np.float32).reshape(-1, 1)
    Xt = StandardScaler().fit_transform(X)
    yt = StandardScaler().fit_transform(y)
    return Xt, yt
开发者ID:YangHaha11514,项目名称:skorch,代码行数:7,代码来源:conftest.py

示例8: testRecursiveSetPrune

 def testRecursiveSetPrune(self): 
     numExamples = 1000
     X, y = data.make_regression(numExamples)  
     
     y = Standardiser().normaliseArray(y)
     
     numTrain = numpy.round(numExamples * 0.66)     
     
     trainX = X[0:numTrain, :]
     trainY = y[0:numTrain]
     testX = X[numTrain:, :]
     testY = y[numTrain:]
     
     learner = DecisionTreeLearner()
     learner.learnModel(trainX, trainY)
     
     rootId = (0,)
     learner.tree.getVertex(rootId).setTestInds(numpy.arange(testX.shape[0]))
     learner.recursiveSetPrune(testX, testY, rootId)
     
     for vertexId in learner.tree.getAllVertexIds(): 
         tempY = testY[learner.tree.getVertex(vertexId).getTestInds()]
         predY = numpy.ones(tempY.shape[0])*learner.tree.getVertex(vertexId).getValue()
         error = numpy.sum((tempY-predY)**2)
         self.assertAlmostEquals(error, learner.tree.getVertex(vertexId).getTestError())
         
     #Check leaf indices form all indices 
     inds = numpy.array([])        
     
     for vertexId in learner.tree.leaves(): 
         inds = numpy.union1d(inds, learner.tree.getVertex(vertexId).getTestInds())
         
     nptst.assert_array_equal(inds, numpy.arange(testY.shape[0]))
开发者ID:malcolmreynolds,项目名称:APGL,代码行数:33,代码来源:DecisionTreeLearnerTest.py

示例9: test_multioutput_regression

def test_multioutput_regression():
    # Test that multi-output regression works as expected
    X, y = make_regression(n_samples=200, n_targets=5)
    mlp = MLPRegressor(solver='lbfgs', hidden_layer_sizes=50, max_iter=200,
                       random_state=1)
    mlp.fit(X, y)
    assert_greater(mlp.score(X, y), 0.9)
开发者ID:aniryou,项目名称:scikit-learn,代码行数:7,代码来源:test_mlp.py

示例10: test_check_gcv_mode_error

def test_check_gcv_mode_error(mode):
    X, y = make_regression(n_samples=5, n_features=2)
    gcv = RidgeCV(gcv_mode=mode)
    with pytest.raises(ValueError, match="Unknown value for 'gcv_mode'"):
        gcv.fit(X, y)
    with pytest.raises(ValueError, match="Unknown value for 'gcv_mode'"):
        _check_gcv_mode(X, mode)
开发者ID:manhhomienbienthuy,项目名称:scikit-learn,代码行数:7,代码来源:test_ridge.py

示例11: test_check_gcv_mode_choice

def test_check_gcv_mode_choice(sparse, mode, mode_n_greater_than_p,
                               mode_p_greater_than_n):
    X, _ = make_regression(n_samples=5, n_features=2)
    if sparse:
        X = sp.csr_matrix(X)
    assert _check_gcv_mode(X, mode) == mode_n_greater_than_p
    assert _check_gcv_mode(X.T, mode) == mode_p_greater_than_n
开发者ID:manhhomienbienthuy,项目名称:scikit-learn,代码行数:7,代码来源:test_ridge.py

示例12: test_shuffle

def test_shuffle():
    # Test that the shuffle parameter affects the training process (it should)
    X, y = make_regression(n_samples=50, n_features=5, n_targets=1,
                           random_state=0)

    # The coefficients will be identical if both do or do not shuffle
    for shuffle in [True, False]:
        mlp1 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
                            random_state=0, shuffle=shuffle)
        mlp2 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
                            random_state=0, shuffle=shuffle)
        mlp1.fit(X, y)
        mlp2.fit(X, y)

        assert np.array_equal(mlp1.coefs_[0], mlp2.coefs_[0])

    # The coefficients will be slightly different if shuffle=True
    mlp1 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
                        random_state=0, shuffle=True)
    mlp2 = MLPRegressor(hidden_layer_sizes=1, max_iter=1, batch_size=1,
                        random_state=0, shuffle=False)
    mlp1.fit(X, y)
    mlp2.fit(X, y)

    assert not np.array_equal(mlp1.coefs_[0], mlp2.coefs_[0])
开发者ID:chrisfilo,项目名称:scikit-learn,代码行数:25,代码来源:test_mlp.py

示例13: test_levenberg_marquardt

    def test_levenberg_marquardt(self):
        dataset = datasets.make_regression(n_samples=50, n_features=2)
        data, target = dataset

        data_scaler = preprocessing.MinMaxScaler()
        target_scaler = preprocessing.MinMaxScaler()

        x_train, x_test, y_train, y_test = train_test_split(
            data_scaler.fit_transform(data),
            target_scaler.fit_transform(target.reshape(-1, 1)),
            train_size=0.85
        )

        lmnet = algorithms.LevenbergMarquardt(
            connection=[
                layers.Input(2),
                layers.Sigmoid(6),
                layers.Sigmoid(1),
            ],
            mu_update_factor=2,
            mu=0.1,
            verbose=False,
            show_epoch=1,
        )
        lmnet.train(x_train, y_train, epochs=4)
        error = lmnet.prediction_error(x_test, y_test)

        self.assertAlmostEqual(0.006, error, places=3)
开发者ID:itdxer,项目名称:neupy,代码行数:28,代码来源:test_levenberg_marquardt.py

示例14: test_cross_val_score_with_score_func_regression

def test_cross_val_score_with_score_func_regression():
    X, y = make_regression(n_samples=30, n_features=20, n_informative=5,
                           random_state=0)
    reg = Ridge()

    # Default score of the Ridge regression estimator
    scores = cval.cross_val_score(reg, X, y, cv=5)
    assert_array_almost_equal(scores, [0.94, 0.97, 0.97, 0.99, 0.92], 2)

    # R2 score (aka. determination coefficient) - should be the
    # same as the default estimator score
    r2_scores = cval.cross_val_score(reg, X, y, scoring="r2", cv=5)
    assert_array_almost_equal(r2_scores, [0.94, 0.97, 0.97, 0.99, 0.92], 2)

    # Mean squared error; this is a loss function, so "scores" are negative
    mse_scores = cval.cross_val_score(reg, X, y, cv=5,
                                      scoring="mean_squared_error")
    expected_mse = np.array([-763.07, -553.16, -274.38, -273.26, -1681.99])
    assert_array_almost_equal(mse_scores, expected_mse, 2)

    # Explained variance
    with warnings.catch_warnings(record=True):
        ev_scores = cval.cross_val_score(reg, X, y, cv=5,
                                         score_func=explained_variance_score)
    assert_array_almost_equal(ev_scores, [0.94, 0.97, 0.97, 0.99, 0.92], 2)
开发者ID:GGXH,项目名称:scikit-learn,代码行数:25,代码来源:test_cross_validation.py

示例15: regr_data

def regr_data():
    return make_regression(
        n_samples=2000,
        n_targets=1,
        n_informative=10,
        random_state=0,
    )
开发者ID:BenjaminBossan,项目名称:mink,代码行数:7,代码来源:conftest.py


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