def initialize(self, data): """ :param data: data, numpy 2-D array """ clf = KMeans(self.K) clf.fit(data, 10) self.centers = clf.get_centers() self.weights = np.ones(self.K) / self.K self.covariances = np.array( [1e10 * np.eye(data.shape[1]) for _ in range(self.K)])
def initialize(self, data: np.ndarray): """ Initializes cluster centers, weights, and covariances :param data: data, numpy 2-D array """ km = KMeans(self.K) km.fit(data) _ = km.predict(data) self.centers = km.get_centers() self.weights = np.random.uniform(0, 1, (self.K, )) self.weights = self.weights / np.sum(self.weights) self.covariances = np.array([np.eye(data.shape[-1])] * self.K) * 10e8
def initialize(self, data): """ :param data: data, numpy 2-D array """ # TODO: Initialize cluster centers, weights, and covariances # Hint: Use K-means km = KMeans(self.K) rr = km.fit(data) self.weights = np.sum(rr, axis=0) / np.sum(rr) self.centers = km.get_centers() dat_cov = [] self.covariances = np.zeros([self.K, 2, 2]) for j in range(rr.shape[1]): dat_cov = data[rr[:, j] == 1] self.covariances[j] = np.cov(dat_cov, rowvar=False) self.r = np.zeros([len(data), self.K])