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


Python datasets.make_spd_matrix方法代码示例

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


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

示例1: random_model

# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import make_spd_matrix [as 别名]
def random_model(n, seed=None):
    """Generate random model (mu, sigma) for portfolio optimization problem.

    Args:
        n (int): number of assets.
        seed (int or None): random seed - if None, will not initialize.

    Returns:
        numpy.narray: expected return vector
        numpy.ndarray: covariance matrix

    """
    if seed:
        aqua_globals.random_seed = seed

    # draw random return values between [0, 1]
    m_u = aqua_globals.random.uniform(size=n, low=0, high=1)

    # construct positive semi-definite covariance matrix
    sigma = make_spd_matrix(n)

    return m_u, sigma 
开发者ID:Qiskit,项目名称:qiskit-aqua,代码行数:24,代码来源:portfolio.py

示例2: make_covar_matrix

# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import make_spd_matrix [as 别名]
def make_covar_matrix(covariance_type, n_components, n_features,
                      random_state=None):
    mincv = 0.1
    prng = check_random_state(random_state)
    if covariance_type == 'spherical':
        return (mincv + mincv * prng.random_sample((n_components,))) ** 2
    elif covariance_type == 'tied':
        return (make_spd_matrix(n_features)
                + mincv * np.eye(n_features))
    elif covariance_type == 'diag':
        return (mincv + mincv *
                prng.random_sample((n_components, n_features))) ** 2
    elif covariance_type == 'full':
        return np.array([
            (make_spd_matrix(n_features, random_state=prng)
             + mincv * np.eye(n_features))
            for x in range(n_components)
        ]) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:20,代码来源:__init__.py

示例3: test_make_spd_matrix

# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import make_spd_matrix [as 别名]
def test_make_spd_matrix():
    X = make_spd_matrix(n_dim=5, random_state=0)

    assert_equal(X.shape, (5, 5), "X shape mismatch")
    assert_array_almost_equal(X, X.T)

    from numpy.linalg import eig
    eigenvalues, _ = eig(X)
    assert_array_equal(eigenvalues > 0, np.array([True] * 5),
                       "X is not positive-definite") 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:12,代码来源:test_samples_generator.py

示例4: test_Metric

# 需要导入模块: from sklearn import datasets [as 别名]
# 或者: from sklearn.datasets import make_spd_matrix [as 别名]
def test_Metric(self):
        np.random.seed(28)
        for d in [iris, wine, breast_cancer]:
            X, y = d()
            n, d = X.shape
            M = make_spd_matrix(d)

            metric = Metric(M)
            metric.fit(X, y)
            L = metric.transformer()
            assert_array_almost_equal(L.T.dot(L), M)

            LX1 = metric.transform()
            LX2 = metric.transform(X)

            dl1 = pdist(LX1)
            dl2 = pdist(LX2)
            dm = pdist(X, metric='mahalanobis', VI=M)  # CHecking that d_M = d_L

            assert_array_almost_equal(dm, dl1)
            assert_array_almost_equal(dm, dl2)

            d_, d = L.shape
            e_, e = M.shape

            assert_equal(d, e_)
            assert_equal(d, e)
            assert_equal(d, X.shape[1]) 
开发者ID:jlsuarezdiaz,项目名称:pyDML,代码行数:30,代码来源:test_work.py


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