#makes a matrix of the possible combinations OF ALL THE POTENTIAL REGRESSION VARIABLES, AND SAVES AS A DATAFRAME # BE CAREFUL, THIS GIVES a little (2^^n)-1 COMBINATIONS def create_dataframes_for_multi_linear_model ( inputlist , inputdata ): '''Takes an inputlist of column names which should be a subset of columns in inputdata, calculates every possible combination of the columns and returns a list of dataframes, each containing a different combination of the input data''' output_dataframes = [] #this makes the matrix of 1s and 0s and maps the column list to it, saving a dataframe of that particular column where a #1 would be in the matrix #ACTUALLY MAKES THE MATRIX template = [ list ( i ) for i in itertools . product ([ 0 , 1 ], repeat = len ( inputlist )) if sum ( i ) > 0 ] check_template = copy . deepcopy ( template ) #ASSIGNS THE DATAFRAME COLUMNS TO EACH '1' for j in range ( len ( template )): for k in range ( len ( template [ j ])): if template [ j ][ k ] == 1 : template [ j ][ k ] = DataFrame ( inputdata [ inputlist [ k ]]) # takes the matrix of dataframes and concats them together into a single dataframe (where there is more than 1) # I should now be able to perform a linear regression on every combination of dataframe for i in range ( len ( template )): j = 0 temp_df = DataFrame () while j < len ( template [ i ]): if isinstance ( template [ i ][ j ], pd . DataFrame ): if len ( temp_df ) == 0 : temp_df = DataFrame ( template [ i ][ j ]) else : temp_df = DataFrame ( pd . concat ([ temp_df , template [ i ][ j ]], axis = 1 )) j += 1 output_dataframes . append ( temp_df ) return output_dataframes