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


Python kernels.Kernel方法代码示例

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


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

示例1: pairwise_kernels

# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import Kernel [as 别名]
def pairwise_kernels(
    X: ArrayLike,
    Y: Optional[ArrayLike] = None,
    metric: Union[str, Callable[[ArrayLike, ArrayLike], float]] = "linear",
    filter_params: bool = False,
    n_jobs: Optional[int] = 1,
    **kwds
):
    from sklearn.gaussian_process.kernels import Kernel as GPKernel

    if metric == "precomputed":
        X, _ = check_pairwise_arrays(X, Y, precomputed=True)
        return X
    elif isinstance(metric, GPKernel):
        raise NotImplementedError()
    elif metric in PAIRWISE_KERNEL_FUNCTIONS:
        if filter_params:
            kwds = dict((k, kwds[k]) for k in kwds if k in KERNEL_PARAMS[metric])
        assert isinstance(metric, str)
        func = PAIRWISE_KERNEL_FUNCTIONS[metric]
    elif callable(metric):
        raise NotImplementedError()
    else:
        raise ValueError("Unknown kernel %r" % metric)

    return func(X, Y, **kwds) 
开发者ID:dask,项目名称:dask-ml,代码行数:28,代码来源:pairwise.py

示例2: _safe_split

# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import Kernel [as 别名]
def _safe_split(estimator, X, y, indices, train_indices=None):
    """Create subset of dataset and properly handle kernels"""
    from sklearn.gaussian_process.kernels import Kernel as GPKernel

    if (hasattr(estimator, 'kernel') and callable(estimator.kernel) and
            not isinstance(estimator.kernel, GPKernel)):
        # cannot compute the kernel values with custom function
        raise ValueError("Cannot use a custom kernel function. "
                         "Precompute the kernel matrix instead.")

    if not hasattr(X, "shape"):
        if getattr(estimator, "_pairwise", False):
            raise ValueError("Precomputed kernels or affinity matrices have "
                             "to be passed as arrays or sparse matrices.")
        X_subset = [X[index] for index in indices]
    else:
        if getattr(estimator, "_pairwise", False):
            # X is a precomputed square kernel matrix
            if X.shape[0] != X.shape[1]:
                raise ValueError("X should be a square kernel matrix")
            if train_indices is None:
                X_subset = X[np.ix_(indices, indices)]
            else:
                X_subset = X[np.ix_(indices, train_indices)]
        else:
            X_subset = _safe_indexing(X, indices)

    if y is not None:
        y_subset = _safe_indexing(y, indices)
    else:
        y_subset = None
    return X_subset, y_subset 
开发者ID:Ibotta,项目名称:sk-dist,代码行数:34,代码来源:utils.py


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