def step_maximization(X,weights,means,variances,n_compenents,pi): """M Step Parameters ---------- X : array-like, shape (n_samples,) The data. weights : array-like, shape (n_components,n_samples) initilized weights array means : array-like, shape (n_components,) The means of each mixture component. variances : array-like, shape (n_components,) The variances of each mixture component. n_components : int The number of clusters pi: array-like (n_components,) mixture component weights Returns ------- means : array-like, shape (n_components,) The means of each mixture component. variances : array-like, shape (n_components,) The variances of each mixture component. """ r = [] for j in range(n_compenents): r.append((weights[j] * pi[j]) / (np.sum([weights[i] * pi[i] for i in range(n_compenents)], axis=0))) #5th equation above means[j] = np.sum(r[j] * X) / (np.sum(r[j])) #6th equation above variances[j] = np.sum(r[j] * np.square(X - means[j])) / (np.sum(r[j])) #4th equation above pi[j] = np.mean(r[j]) return variances,means,pi