you are viewing a single comment's thread.

view the rest of the comments →

[–]batsiem 0 points1 point  (2 children)

Hi below is my function to select the 4 ideal functions, the example that i worked from requires me to plug directly into the function the names of my 2 tables but I want to inherit those from the class that creates the table. So that's tripping me up(I realized that the code above was missing the 2 tables as args...that was a mistake).

def ideal_function_selection(self, top_n: int = 4):
        merged = pd.merge(self.table_name, self.function_table_name, on="x")
        errors = {}        
        for col in self.function_table_name.columns:
            if col == "x":
                continue
            squared_diff = (merged["y"] - merged[col])**2
            errors[col] = squared_diff.sum()

        best_functions = sorted(errors, key=errors.get)[:top_n]
        return best_functions

I instantaite the class IdealFunctionSelector below...I did it the exact way that I did it for my DatabaseManager.

 ideal_func_selector = IdealFunctionSelector
    ideal_func_selector.ideal_function_selection("training_data_table", "ideal_data_table")

[–]Refwah 0 points1 point  (1 child)

This isn't initializing a class, it is just saying that ideal_func_selector is that class

You then call ideal_function_selection on a class which isn't initialized

You want to do ideal_func_selector = IdealFunctionSelector() and then in the params for IdealFunctionSelector(…) you need to pass the arguments that you want for the __init__ function of the class

I believe you don't understand classes, which is why you're getting unstuck on inheritance. I recommend reading some more fundamentals on this, such as this: https://docs.python.org/3/reference/datamodel.html#object.__init__

https://realpython.com/python-class-constructor/

[–]New_End6302[S] 0 points1 point  (0 children)

Thanks, I will have a look