def random_forest(self):
        """ Random Forest.

        This function runs random forest and stores the,
        1. Model
        2. Model name
        3. Max score
        4. Metrics

        """

        model = RandomForestRegressor(random_state=42)

        scores = []
        kfold = KFold(n_splits=self.cv, shuffle=True, random_state=42)
        for i, (train, test) in enumerate(kfold.split(self.baseline_in, self.baseline_out)):
            model.fit(self.baseline_in.iloc[train], self.baseline_out.iloc[train])
            scores.append(model.score(self.baseline_in.iloc[test], self.baseline_out.iloc[test]))
        mean_score = np.mean(scores)

        self.models.append(model)
        self.model_names.append('Random Forest Regressor')
        self.max_scores.append(mean_score)
        
        self.metrics['Random Forest Regressor'] = {}
        self.metrics['Random Forest Regressor']['R2'] = mean_score
        self.metrics['Random Forest Regressor']['Adj R2'] = self.adj_r2(mean_score, self.baseline_in.shape[0], self.baseline_in.shape[1])
def random_forest ( self ) : model = RandomForestRegressor ( random_state = 42 ) scores = [ ] kfold = KFold ( n_splits = self . cv , shuffle = True , random_state = 42 ) for i , ( train , test ) in enumerate ( kfold . split ( self . baseline_in , self . baseline_out ) ) : model . fit ( self . baseline_in . iloc [ train ] , self . baseline_out . iloc [ train ] ) scores . append ( model . score ( self . baseline_in . iloc [ test ] , self . baseline_out . iloc [ test ] ) ) mean_score = np . mean ( scores ) self . models . append ( model ) self . model_names . append ( 'Random Forest Regressor' ) self . max_scores . append ( mean_score ) self . metrics [ 'Random Forest Regressor' ] = { } self . metrics [ 'Random Forest Regressor' ] [ 'R2' ] = mean_score self . metrics [ 'Random Forest Regressor' ] [ 'Adj R2' ] = self . adj_r2 ( mean_score , self . baseline_in . shape [ 0 ] , self . baseline_in . shape [ 1 ] )
Random Forest.

        This function runs random forest and stores the,
        1. Model
        2. Model name
        3. Max score
        4. Metrics