當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。