Как уменьшить размерность гауссовой смеси? - PullRequest
0 голосов
/ 17 апреля 2020

Что я хочу сделать, так это установить модель гауссовой смеси на некоторые данные, используя sklearn. С помощью этой модели гауссовой смеси я хочу предсказать вероятности для каждого кластера для неполных точек данных (которые имеют только подмножество доступных функций).

Поскольку я знаю, что подмножество функций всегда одинаково, Я хочу уменьшить размеры модели гауссовой смеси для предсказаний вероятности кластера.

Это то, что у меня есть сейчас, я думаю, что это работает правильно, но это неправильно:

from sklearn.mixture import GaussianMixture

gmm = GaussianMixture(n_components=self.n_clusters).fit(self.dataset.complete)
gmm_flattened = self.get_flattened_gmm(gmm)

def get_flattened_gmm(self, gmm):
    """Given a Gaussian Mixture Model, returns the flattened model which only
    includes the selection features and the label, removing the classification
    features.

    Args:
        gmm (GaussianMixture): The Gaussian Mixture Model representing the entire
            data.

    Returns:
        GaussianMixture: The flattened Gaussian Mixture Model.
    """
    gmm_new = GaussianMixture(n_components=gmm.n_components)

    n_features_new = # obtained from object constant
    indices = list(range(n_features_new)) + [-1]

    gmm_new.weights_ = gmm.weights_
    gmm_new.means_ = gmm.means_[:, indices]
    gmm_new.covariances_ = gmm.covariances_[:, indices, :][:, :, indices]
    gmm_new.precisions_ = gmm.precisions_[:, indices, :][:, :, indices]
    gmm_new.precisions_cholesky_ = gmm.precisions_cholesky_[:, indices, :][
        :, :, indices
    ]
    return gmm_new
...