Unbalanced Class Classification/Script.py
def preprocess(self):
        '''
        Pre-processings:
            - remove unary features
            - normalize continous features
            - remove negative values for using Naive Bayes
            - Convert y into integers from alphabets
        '''
        
        X = self.raw_data
        y = self.raw_data[self.raw_data.shape[1]-1]
        
#        find indices of variables
        uni_idx = []#Unary
        bin_idx = []#Binary
        ter_idx = []#Ternary
        cont_idx = []#Continous
        for i in range(X.shape[1]-1):
            uniq_ = np.unique(X.values[:,i])
            if np.shape(uniq_)[0]==1:
                uni_idx.append(i)
            elif np.shape(uniq_)[0]==2:
                bin_idx.append(i)
            elif np.shape(uniq_)[0]>2 and np.shape(uniq_)[0]<1000:
                ter_idx.append(i)
            else:
                cont_idx.append(i)
        
#        remove unary features and class
        X = X.drop(labels=uni_idx,axis=1)
        X = X.drop(labels=295,axis=1)#remove the class 
        
        uniq_class = np.unique(y)
        
        j=0
        for i in uniq_class:
            y[y==i] = j
            j+=1
                
        #Sklearn libraries don't accept object type as y. So, convert it into int32 array
        y = np.array(y.values, dtype='int32')
        X = X.values
        
        X[X[:,23]<0,23] = 0#Naive Bayesian classifier doesnt take negetive values
        X[X[:,36]<0,36] = 0
        
        self.X = X
        self.y = y
        print('Data Pre-processed')

        Pre-processings:
            - remove unary features
            - normalize continous features
            - remove negative values for using Naive Bayes
            - Convert y into integers from alphabets
        
Pre-processings:
remove unary features
normalize continous features
remove negative values for using Naive Bayes
Convert y into integers from alphabets
Pre - processings : remove unary features normalize continous features remove negative values for using Naive Bayes Convert y into integers from alphabets
def preprocess(self):
        X = self.raw_data
        y = self.raw_data[self.raw_data.shape[1]-1]
        uni_idx = []
        bin_idx = []
        ter_idx = []
        cont_idx = []
        for i in range(X.shape[1]-1):
            uniq_ = np.unique(X.values[:,i])
            if np.shape(uniq_)[0]==1:
                uni_idx.append(i)
            elif np.shape(uniq_)[0]==2:
                bin_idx.append(i)
            elif np.shape(uniq_)[0]>2 and np.shape(uniq_)[0]<1000:
                ter_idx.append(i)
            else:
                cont_idx.append(i)
        X = X.drop(labels=uni_idx,axis=1)
        X = X.drop(labels=295,axis=1)
        uniq_class = np.unique(y)
        j=0
        for i in uniq_class:
            y[y==i] = j
            j+=1
        y = np.array(y.values, dtype='int32')
        X = X.values
        X[X[:,23]<0,23] = 0
        X[X[:,36]<0,36] = 0
        self.X = X
        self.y = y
        print('Data Pre-processed')
def preprocess ( self ) : X = self . raw_data y = self . raw_data [ self . raw_data . shape [ 1 ] - 1 ] uni_idx = [ ] bin_idx = [ ] ter_idx = [ ] cont_idx = [ ] for i in range ( X . shape [ 1 ] - 1 ) : uniq_ = np . unique ( X . values [ : , i ] ) if np . shape ( uniq_ ) [ 0 ] == 1 : uni_idx . append ( i ) elif np . shape ( uniq_ ) [ 0 ] == 2 : bin_idx . append ( i ) elif np . shape ( uniq_ ) [ 0 ] > 2 and np . shape ( uniq_ ) [ 0 ] < 1000 : ter_idx . append ( i ) else : cont_idx . append ( i ) X = X . drop ( labels = uni_idx , axis = 1 ) X = X . drop ( labels = 295 , axis = 1 ) uniq_class = np . unique ( y ) j = 0 for i in uniq_class : y [ y == i ] = j j += 1 y = np . array ( y . values , dtype = 'int32' ) X = X . values X [ X [ : , 23 ] < 0 , 23 ] = 0 X [ X [ : , 36 ] < 0 , 36 ] = 0 self . X = X self . y = y print ( 'Data Pre-processed' )
Pre-processings:
 remove unary features
 normalize continous features
 remove negative values for using Naive Bayes
 Convert y into integers from alphabets
Pre - processings : remove unary features normalize continous features remove negative values for using Naive Bayes Convert y into integers from alphabets
'''
        Pre-processings:
            - remove unary features
            - normalize continous features
            - remove negative values for using Naive Bayes
            - Convert y into integers from alphabets
        ''' #        find indices of variables #Unary #Binary #Ternary #Continous #        remove unary features and class #remove the class  #Sklearn libraries don't accept object type as y. So, convert it into int32 array #Naive Bayesian classifier doesnt take negetive values
self