So far, we have written sequential code in Python. Writing simple object-oriented code instead is always a time saver in the end. The code is more organized, maintainable, and less prone to becoming unusable after a while. Taking the time to write simple classes with clear initialization, instances and class methods will make your code much simpler and robust in the end. With that in mind, we will now write a NonLinear class for our experiment.
Let's first write down the different functions of that class that generate some of the fields that depend on the power of the polynomial regression:
- This function takes in a power p and returns the SQL query:
def generate_sql(self, p): powers = [ 'power(x,{0}) as x{0}'.format(i) ...