classification/tree_manager.py
def prep_tree_data(self, number: int):
        """
        Retrieve the data and convert the one-hot encodings to single columns.
        Then split the data into train and test sets.
        """
        filename = "data-before-normalization-{}-out-of-7.csv".format(number)
        path = str(DATA_PATH.joinpath("data-splitted", filename))
        df = pandas.read_csv(path)

        df.drop(df.columns[0], axis=1, inplace=True)
        assessments = [x for x in df.columns.values if x.split("_")[0] == "assessment"]
        df['average_score'] = df[assessments].mean(skipna=True, axis=1)
        for assessment in assessments:  # somehow he doesn't want to fillna in a batch?
            df[assessment].fillna(df['average_score'], inplace=True)
        clicks = [x for x in df.columns.values if x.split("_")[0] == "vle"]
        df['vle_click_average'] = df[clicks].mean(skipna=True, axis=1)
        for click in clicks:  # somehow he doesn't want to fillna in a batch?
            df[click].fillna(df['vle_click_average'], inplace=True)
        df.dropna()

        self.change_oh_cat("gender", df)
        self.change_oh_cat("highest_education", df)
        self.change_oh_cat("imd_band", df)
        self.change_oh_cat("age_band", df)
        self.change_oh_cat("disability", df)
        result_order = {'final_result__Fail': 0,  'final_result__Withdrawn': 2,
                        'final_result__Pass': 1, 'final_result__Distinction': 3}
        self.change_oh_cat("final_result", df, result_order)
        df["final_result"].replace(2, 0, inplace=True)
        df["final_result"].replace(3, 1, inplace=True)

        target = df["final_result"]
        df.drop(["final_result"], axis=1, inplace=True)

        x_train, x_test, y_train, y_test = train_test_split(df, target, test_size=0.1,
                                                            random_state=32, shuffle=True,
                                                            stratify=target)

        return x_train, x_test, y_train, y_test

        Retrieve the data and convert the one-hot encodings to single columns.
        Then split the data into train and test sets.
        
Retrieve the data and convert the one-hot encodings to single columns.
Then split the data into train and test sets.
Retrieve the data and convert the one - hot encodings to single columns . Then split the data into train and test sets .
def prep_tree_data(self, number: int):
        filename = "data-before-normalization-{}-out-of-7.csv".format(number)
        path = str(DATA_PATH.joinpath("data-splitted", filename))
        df = pandas.read_csv(path)
        df.drop(df.columns[0], axis=1, inplace=True)
        assessments = [x for x in df.columns.values if x.split("_")[0] == "assessment"]
        df['average_score'] = df[assessments].mean(skipna=True, axis=1)
        for assessment in assessments:  
            df[assessment].fillna(df['average_score'], inplace=True)
        clicks = [x for x in df.columns.values if x.split("_")[0] == "vle"]
        df['vle_click_average'] = df[clicks].mean(skipna=True, axis=1)
        for click in clicks:  
            df[click].fillna(df['vle_click_average'], inplace=True)
        df.dropna()
        self.change_oh_cat("gender", df)
        self.change_oh_cat("highest_education", df)
        self.change_oh_cat("imd_band", df)
        self.change_oh_cat("age_band", df)
        self.change_oh_cat("disability", df)
        result_order = {'final_result__Fail': 0,  'final_result__Withdrawn': 2,
                        'final_result__Pass': 1, 'final_result__Distinction': 3}
        self.change_oh_cat("final_result", df, result_order)
        df["final_result"].replace(2, 0, inplace=True)
        df["final_result"].replace(3, 1, inplace=True)
        target = df["final_result"]
        df.drop(["final_result"], axis=1, inplace=True)
        x_train, x_test, y_train, y_test = train_test_split(df, target, test_size=0.1,
                                                            random_state=32, shuffle=True,
                                                            stratify=target)
        return x_train, x_test, y_train, y_test
def prep_tree_data ( self , number : int ) : filename = "data-before-normalization-{}-out-of-7.csv" . format ( number ) path = str ( DATA_PATH . joinpath ( "data-splitted" , filename ) ) df = pandas . read_csv ( path ) df . drop ( df . columns [ 0 ] , axis = 1 , inplace = True ) assessments = [ x for x in df . columns . values if x . split ( "_" ) [ 0 ] == "assessment" ] df [ 'average_score' ] = df [ assessments ] . mean ( skipna = True , axis = 1 ) for assessment in assessments : df [ assessment ] . fillna ( df [ 'average_score' ] , inplace = True ) clicks = [ x for x in df . columns . values if x . split ( "_" ) [ 0 ] == "vle" ] df [ 'vle_click_average' ] = df [ clicks ] . mean ( skipna = True , axis = 1 ) for click in clicks : df [ click ] . fillna ( df [ 'vle_click_average' ] , inplace = True ) df . dropna ( ) self . change_oh_cat ( "gender" , df ) self . change_oh_cat ( "highest_education" , df ) self . change_oh_cat ( "imd_band" , df ) self . change_oh_cat ( "age_band" , df ) self . change_oh_cat ( "disability" , df ) result_order = { 'final_result__Fail' : 0 , 'final_result__Withdrawn' : 2 , 'final_result__Pass' : 1 , 'final_result__Distinction' : 3 } self . change_oh_cat ( "final_result" , df , result_order ) df [ "final_result" ] . replace ( 2 , 0 , inplace = True ) df [ "final_result" ] . replace ( 3 , 1 , inplace = True ) target = df [ "final_result" ] df . drop ( [ "final_result" ] , axis = 1 , inplace = True ) x_train , x_test , y_train , y_test = train_test_split ( df , target , test_size = 0.1 , random_state = 32 , shuffle = True , stratify = target ) return x_train , x_test , y_train , y_test
Retrieve the data and convert the one-hot encodings to single columns.
Retrieve the data and convert the one - hot encodings to single columns .
"""
        Retrieve the data and convert the one-hot encodings to single columns.
        Then split the data into train and test sets.
        """ # somehow he doesn't want to fillna in a batch? # somehow he doesn't want to fillna in a batch?
self
number
int