def learn(self, )"""do steps of em""for in range( )self class_counts,self feature_counts self em_step(self class_counts self feature_countsthe following is for visualizing the classes it prints the dataset ordered by the probability of class learnem py -(continued def show_class(self, )"""sorts the data by the class and prints in order for visualizing small data sets ""sorted_data sorted((self prob(tpl,self class_counts,self feature_counts)[ ]indpreserve ordering for equal probabilities tplfor (ind,tplin enumerate(self dataset train)for cc, ,tpl in sorted_dataprint(cc,*tpl,sep='\ 'the following are for evaluating the classes the probability of tuple can be evaluated by marginalizing over the classesp(tplep(cp(xi =tple(icc fc[ ][feati (tple)][ccc[ccc[cc len(self dataseti where cc is the class count and fc is feature count len(self datasetcan be distributed out of the sumand cc[ccan be taken out of the product fc[ ][feati (tple)][ #feats - len(self datasetc cc[ci given the probability of each tuplewe can evaluate the loglossas the negative of the log probabilitylearnem py -(continued def logloss(self,tple)"""returns the logloss of the prediction on tplewhich is -log( (tple)based on the current class counts and feature counts ""feats self dataset input_features res cc self class_counts fc self feature_counts version june