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


Python kernel_ridge.KernelRidge方法代码示例

本文整理汇总了Python中sklearn.kernel_ridge.KernelRidge方法的典型用法代码示例。如果您正苦于以下问题:Python kernel_ridge.KernelRidge方法的具体用法?Python kernel_ridge.KernelRidge怎么用?Python kernel_ridge.KernelRidge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.kernel_ridge的用法示例。


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

示例1: model_builder

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def model_builder(model_dir):
  sklearn_model = KernelRidge(kernel="rbf", alpha=1e-3, gamma=0.05)
  return dc.models.SklearnModel(sklearn_model, model_dir) 
开发者ID:deepchem,项目名称:deepchem,代码行数:5,代码来源:delaney_krr.py

示例2: model_builder

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def model_builder(model_dir):
  sklearn_model = KernelRidge(kernel="rbf", alpha=5e-4, gamma=0.008)
  return dc.models.SklearnModel(sklearn_model, model_dir) 
开发者ID:deepchem,项目名称:deepchem,代码行数:5,代码来源:qm7_sklearn.py

示例3: test_kernel_ridge

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge():
    pred = Ridge(alpha=1, fit_intercept=False).fit(X, y).predict(X)
    pred2 = KernelRidge(kernel="linear", alpha=1).fit(X, y).predict(X)
    assert_array_almost_equal(pred, pred2) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:6,代码来源:test_kernel_ridge.py

示例4: test_kernel_ridge_csr

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge_csr():
    pred = Ridge(alpha=1, fit_intercept=False,
                 solver="cholesky").fit(Xcsr, y).predict(Xcsr)
    pred2 = KernelRidge(kernel="linear", alpha=1).fit(Xcsr, y).predict(Xcsr)
    assert_array_almost_equal(pred, pred2) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:7,代码来源:test_kernel_ridge.py

示例5: test_kernel_ridge_csc

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge_csc():
    pred = Ridge(alpha=1, fit_intercept=False,
                 solver="cholesky").fit(Xcsc, y).predict(Xcsc)
    pred2 = KernelRidge(kernel="linear", alpha=1).fit(Xcsc, y).predict(Xcsc)
    assert_array_almost_equal(pred, pred2) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:7,代码来源:test_kernel_ridge.py

示例6: test_kernel_ridge_singular_kernel

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge_singular_kernel():
    # alpha=0 causes a LinAlgError in computing the dual coefficients,
    # which causes a fallback to a lstsq solver. This is tested here.
    pred = Ridge(alpha=0, fit_intercept=False).fit(X, y).predict(X)
    kr = KernelRidge(kernel="linear", alpha=0)
    ignore_warnings(kr.fit)(X, y)
    pred2 = kr.predict(X)
    assert_array_almost_equal(pred, pred2) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:10,代码来源:test_kernel_ridge.py

示例7: test_kernel_ridge_precomputed

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge_precomputed():
    for kernel in ["linear", "rbf", "poly", "cosine"]:
        K = pairwise_kernels(X, X, metric=kernel)
        pred = KernelRidge(kernel=kernel).fit(X, y).predict(X)
        pred2 = KernelRidge(kernel="precomputed").fit(K, y).predict(K)
        assert_array_almost_equal(pred, pred2) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:8,代码来源:test_kernel_ridge.py

示例8: test_kernel_ridge_sample_weights

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge_sample_weights():
    K = np.dot(X, X.T)  # precomputed kernel
    sw = np.random.RandomState(0).rand(X.shape[0])

    pred = Ridge(alpha=1,
                 fit_intercept=False).fit(X, y, sample_weight=sw).predict(X)
    pred2 = KernelRidge(kernel="linear",
                        alpha=1).fit(X, y, sample_weight=sw).predict(X)
    pred3 = KernelRidge(kernel="precomputed",
                        alpha=1).fit(K, y, sample_weight=sw).predict(K)
    assert_array_almost_equal(pred, pred2)
    assert_array_almost_equal(pred, pred3) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:14,代码来源:test_kernel_ridge.py

示例9: test_kernel_ridge_multi_output

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_kernel_ridge_multi_output():
    pred = Ridge(alpha=1, fit_intercept=False).fit(X, Y).predict(X)
    pred2 = KernelRidge(kernel="linear", alpha=1).fit(X, Y).predict(X)
    assert_array_almost_equal(pred, pred2)

    pred3 = KernelRidge(kernel="linear", alpha=1).fit(X, y).predict(X)
    pred3 = np.array([pred3, pred3]).T
    assert_array_almost_equal(pred2, pred3) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:10,代码来源:test_kernel_ridge.py

示例10: fit

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def fit(self):
        """Scale data and train the model with the indicated algorithm.

        Do not forget to tune the hyperparameters.

        Parameters
        ----------
        algorithm : String,
            "KernelRidge", "SVM", "LinearRegression", "Lasso", "ElasticNet", "NeuralNet", "BaggingNeuralNet", default = "SVM"

        """
        self.X_scaler.fit(self.X_train)
        self.Y_scaler.fit(self.y_train)

        # scaling the data in all cases, it may not be used during the fit later
        self.X_train_sc = self.X_scaler.transform(self.X_train)
        self.y_train_sc = self.Y_scaler.transform(self.y_train)

        self.X_test_sc = self.X_scaler.transform(self.X_test)
        self.y_test_sc = self.Y_scaler.transform(self.y_test)

        if self.algorithm == "KernelRidge":
            clf_kr = KernelRidge(kernel=self.user_kernel)
            self.model = sklearn.model_selection.GridSearchCV(clf_kr, cv=5, param_grid=self.param_kr)

        elif self.algorithm == "SVM":
            clf_svm = SVR(kernel=self.user_kernel)
            self.model = sklearn.model_selection.GridSearchCV(clf_svm, cv=5, param_grid=self.param_svm)

        elif self.algorithm == "Lasso":
            clf_lasso = sklearn.linear_model.Lasso(alpha=0.1,random_state=self.rand_state)
            self.model = sklearn.model_selection.GridSearchCV(clf_lasso, cv=5,
                                                              param_grid=dict(alpha=np.logspace(-5,5,30)))

        elif self.algorithm == "ElasticNet":
            clf_ElasticNet = sklearn.linear_model.ElasticNet(alpha=0.1, l1_ratio=0.5,random_state=self.rand_state)
            self.model = sklearn.model_selection.GridSearchCV(clf_ElasticNet,cv=5,
                                                              param_grid=dict(alpha=np.logspace(-5,5,30)))

        elif self.algorithm == "LinearRegression":
            self.model = sklearn.linear_model.LinearRegression()

        elif self.algorithm == "NeuralNet":
            self.model = MLPRegressor(**self.param_neurons)
        elif self.algorithm == "BaggingNeuralNet":
            nn_m = MLPRegressor(**self.param_neurons)

            self.model = BaggingRegressor(base_estimator = nn_m, **self.param_bag)

        if self.scaling == True:
            self.model.fit(self.X_train_sc, self.y_train_sc.reshape(-1,))
            predict_train_sc = self.model.predict(self.X_train_sc)
            self.prediction_train = self.Y_scaler.inverse_transform(predict_train_sc.reshape(-1,1))
            predict_test_sc = self.model.predict(self.X_test_sc)
            self.prediction_test = self.Y_scaler.inverse_transform(predict_test_sc.reshape(-1,1))
        else:
            self.model.fit(self.X_train, self.y_train.reshape(-1,))
            self.prediction_train = self.model.predict(self.X_train)
            self.prediction_test = self.model.predict(self.X_test) 
开发者ID:charlesll,项目名称:rampy,代码行数:61,代码来源:ml_regressor.py

示例11: __init__

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def __init__(self, alpha=1, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None):
        self._hyperparams = {
            'alpha': alpha,
            'kernel': kernel,
            'gamma': gamma,
            'degree': degree,
            'coef0': coef0,
            'kernel_params': kernel_params}
        self._wrapped_model = Op(**self._hyperparams) 
开发者ID:IBM,项目名称:lale,代码行数:11,代码来源:kernel_ridge.py

示例12: ridge_regression

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def ridge_regression(K1, K2, y1, y2, alpha, c):
    n_val, n_train = K2.shape
    clf = KernelRidge(kernel = "precomputed", alpha = alpha)
    one_hot_label = np.eye(c)[y1] - 1.0 / c
    clf.fit(K1, one_hot_label)
    z = clf.predict(K2).argmax(axis = 1)
    return 1.0 * np.sum(z == y2) / n_val 
开发者ID:LeoYu,项目名称:neural-tangent-kernel-UCI,代码行数:9,代码来源:tools.py

示例13: __init__

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def __init__(self, options):
        self.handle_options(options)

        out_params = convert_params(options.get('params', {}), floats=['gamma'])
        out_params['kernel'] = 'rbf'

        self.estimator = _KernelRidge(**out_params) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:9,代码来源:KernelRidge.py

示例14: test_KernelRidge

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_KernelRidge(self):
        KernelRidgeAlgo.register_codecs()
        self.regressor_util(KernelRidge) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:5,代码来源:test_codec.py

示例15: test_objectmapper

# 需要导入模块: from sklearn import kernel_ridge [as 别名]
# 或者: from sklearn.kernel_ridge import KernelRidge [as 别名]
def test_objectmapper(self):
        df = pdml.ModelFrame([])
        self.assertIs(df.kernel_ridge.KernelRidge, kr.KernelRidge) 
开发者ID:pandas-ml,项目名称:pandas-ml,代码行数:5,代码来源:test_kernel_ridge.py


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