hw3/hw3_submission.py
def gen_by_class(self):
        """
        With the given input dataset (self.x, self.y), generate 3 dictionaries to calculate class-wise mean and variance of the data.
        - self.x_by_class : A dictionary of numpy arraies with the keys as each class label and values as data with such label.
        - self.mean_by_class : A dictionary of numpy arraies with the keys as each class label and values as mean of the data with such label.
        - self.std_by_class : A dictionary of numpy arraies with the keys as each class label and values as standard deviation of the data with such label.
        - self.y_prior : A numpy array of shape (C,) containing prior probability of each class
        """
        self.x_by_class = dict()
        self.mean_by_class = dict()
        self.std_by_class = dict()
        self.y_prior = None

        ############################################################
        ############################################################
        # BEGIN_YOUR_CODE
        # Generate dictionaries.
        # hint : to see all unique y labels, you might use np.unique function, e.g., np.unique(self.y)
        classes = np.unique(self.y)
        counts = dict()
        for c in classes:
            self.x_by_class[c] = []
            self.mean_by_class[c] = []
            self.std_by_class[c] = []
            counts[c] = 0
        for i in range(0, self.x.shape[0]):
            c = self.y[i]
            self.x_by_class[c].append(self.x[i])
            counts[c] = counts[c] + 1
        for c in classes:
            self.mean_by_class[c] = self.mean(self.x_by_class[c])
            self.std_by_class[c] = self.std(self.x_by_class[c])
        self.y_prior = np.array([(counts[c] / len(self.y)) for c in classes])
        pass
        # END_YOUR_CODE
        ############################################################
        ############################################################        

        With the given input dataset (self.x, self.y), generate 3 dictionaries to calculate class-wise mean and variance of the data.
        - self.x_by_class : A dictionary of numpy arraies with the keys as each class label and values as data with such label.
        - self.mean_by_class : A dictionary of numpy arraies with the keys as each class label and values as mean of the data with such label.
        - self.std_by_class : A dictionary of numpy arraies with the keys as each class label and values as standard deviation of the data with such label.
        - self.y_prior : A numpy array of shape (C,) containing prior probability of each class
        
With the given input dataset (self.x, self.y), generate 3 dictionaries to calculate class-wise mean and variance of the data.
self.x_by_class : A dictionary of numpy arraies with the keys as each class label and values as data with such label.
self.mean_by_class : A dictionary of numpy arraies with the keys as each class label and values as mean of the data with such label.
self.std_by_class : A dictionary of numpy arraies with the keys as each class label and values as standard deviation of the data with such label.
self.y_prior : A numpy array of shape (C,) containing prior probability of each class
With the given input dataset ( self . x self . y ) generate 3 dictionaries to calculate class - wise mean and variance of the data . self . x_by_class : A dictionary of numpy arraies with the keys as each class label and values as data with such label . self . mean_by_class : A dictionary of numpy arraies with the keys as each class label and values as mean of the data with such label . self . std_by_class : A dictionary of numpy arraies with the keys as each class label and values as standard deviation of the data with such label . self . y_prior : A numpy array of shape ( C ) containing prior probability of each class
def gen_by_class(self):
        self.x_by_class = dict()
        self.mean_by_class = dict()
        self.std_by_class = dict()
        self.y_prior = None
        classes = np.unique(self.y)
        counts = dict()
        for c in classes:
            self.x_by_class[c] = []
            self.mean_by_class[c] = []
            self.std_by_class[c] = []
            counts[c] = 0
        for i in range(0, self.x.shape[0]):
            c = self.y[i]
            self.x_by_class[c].append(self.x[i])
            counts[c] = counts[c] + 1
        for c in classes:
            self.mean_by_class[c] = self.mean(self.x_by_class[c])
            self.std_by_class[c] = self.std(self.x_by_class[c])
        self.y_prior = np.array([(counts[c] / len(self.y)) for c in classes])
        pass
def gen_by_class ( self ) : self . x_by_class = dict ( ) self . mean_by_class = dict ( ) self . std_by_class = dict ( ) self . y_prior = None classes = np . unique ( self . y ) counts = dict ( ) for c in classes : self . x_by_class [ c ] = [ ] self . mean_by_class [ c ] = [ ] self . std_by_class [ c ] = [ ] counts [ c ] = 0 for i in range ( 0 , self . x . shape [ 0 ] ) : c = self . y [ i ] self . x_by_class [ c ] . append ( self . x [ i ] ) counts [ c ] = counts [ c ] + 1 for c in classes : self . mean_by_class [ c ] = self . mean ( self . x_by_class [ c ] ) self . std_by_class [ c ] = self . std ( self . x_by_class [ c ] ) self . y_prior = np . array ( [ ( counts [ c ] / len ( self . y ) ) for c in classes ] ) pass
With the given input dataset (self.x, self.y), generate 3 dictionaries to calculate class-wise mean and variance of the data.
With the given input dataset ( self . x self . y ) generate 3 dictionaries to calculate class - wise mean and variance of the data .
"""
        With the given input dataset (self.x, self.y), generate 3 dictionaries to calculate class-wise mean and variance of the data.
        - self.x_by_class : A dictionary of numpy arraies with the keys as each class label and values as data with such label.
        - self.mean_by_class : A dictionary of numpy arraies with the keys as each class label and values as mean of the data with such label.
        - self.std_by_class : A dictionary of numpy arraies with the keys as each class label and values as standard deviation of the data with such label.
        - self.y_prior : A numpy array of shape (C,) containing prior probability of each class
        """ ############################################################ ############################################################ # BEGIN_YOUR_CODE # Generate dictionaries. # hint : to see all unique y labels, you might use np.unique function, e.g., np.unique(self.y) # END_YOUR_CODE ############################################################ ############################################################        
self