learning with uncertainty class_counts[cis the number of examples with class= self class_counts [ ]*self num_classes feature_sum[ ][cis the sum of the values of feature for class self feature_sum [[ ]*self num_classes for feat in self dataset input_featuresfor eg in self dataset traincl random randrange(self num_classesassign eg to random class self class_counts[cl+ for (ind,featin enumerate(self dataset input_features)self feature_sum[ind][cl+feat(egself num_iterations self display( ,"initial class counts",self class_countsthe distance from (the mean ofa class to an example is the sumover all fraturesof the sum-of-squares differences of the class mean and the example value learnkmeans py -(continued def distance(self,cl,eg)"""distance of the eg from the mean of the class""return sum(self class_prediction(ind,cl)-feat(eg))** for (ind,featin enumerate(self dataset input_features) def class_prediction(self,feat_ind,cl)"""prediction of the class cl on the feature with index feat_ind""if self class_counts[cl= return there are no examples so we can choose any value elsereturn self feature_sum[feat_ind][cl]/self class_counts[cl def class_of_eg(self,eg)"""class to which eg is assigned""return (min((self distance(cl,eg),clfor cl in range(self num_classes)))[ second element of tuplewhich is class with minimum distance one step of -means updates the class counts and feature sum it uses the old values to determine the classesand so the new values for class counts and feature sum at the end it determines whether the values of these have changesand then replaces the old ones with the new ones it returns an indicator of whether the values are stable (have not changedlearnkmeans py -(continued def k_means_step(self)"""updates the model with one step of -means returns whether the assignment is stable ""version june