Unbalanced Class Classification/Script.py
def cross_validate(self,clf):
        '''
        Use cross-validation to train models and return their scores.
        input:
            clf : classifier
        output:
            scores : weighted F1 scores of 5 cv. 
        '''
        cv = StratifiedKFold(n_splits=5)
        scores = []
        
        for train, test in cv.split(self.X,self.y):
            X_train = self.X[train]
            y_train = self.y[train]
            
            X_test = self.X[test]
            y_test = self.y[test]
            #Train the classifier            
            clf.fit(X_train,y_train)
            
            #predict
            y_pred = clf.predict(X_test)
            
            #evaluate
            scores.append(f1_score(y_test,y_pred,average='weighted'))
        print(scores)
            
        return scores

        Use cross-validation to train models and return their scores.
        input:
            clf : classifier
        output:
            scores : weighted F1 scores of 5 cv. 
        
Use cross-validation to train models and return their scores.
input:
clf : classifier
output:
scores : weighted F1 scores of 5 cv.
Use cross - validation to train models and return their scores . input : clf : classifier output : scores : weighted F1 scores of 5 cv .
def cross_validate(self,clf):
        cv = StratifiedKFold(n_splits=5)
        scores = []
        for train, test in cv.split(self.X,self.y):
            X_train = self.X[train]
            y_train = self.y[train]
            X_test = self.X[test]
            y_test = self.y[test]
            clf.fit(X_train,y_train)
            y_pred = clf.predict(X_test)
            scores.append(f1_score(y_test,y_pred,average='weighted'))
        print(scores)
        return scores
def cross_validate ( self , clf ) : cv = StratifiedKFold ( n_splits = 5 ) scores = [ ] for train , test in cv . split ( self . X , self . y ) : X_train = self . X [ train ] y_train = self . y [ train ] X_test = self . X [ test ] y_test = self . y [ test ] clf . fit ( X_train , y_train ) y_pred = clf . predict ( X_test ) scores . append ( f1_score ( y_test , y_pred , average = 'weighted' ) ) print ( scores ) return scores
Use cross-validation to train models and return their scores.
Use cross - validation to train models and return their scores .
'''
        Use cross-validation to train models and return their scores.
        input:
            clf : classifier
        output:
            scores : weighted F1 scores of 5 cv. 
        ''' #Train the classifier             #predict #evaluate
self
clf