I'm following along with a "learn R" course, and we ran the following multiple linear regression:
regressor = lm(formula = Profit ~ ., data = training_set)
Then a bit later, we added some columns to a different data set:
dataset$Level2 = dataset$Level^2
dataset$Level3 = dataset$Level^3
dataset$Level4 = dataset$Level^4
And ran identical line...
regressor = lm(formula = Profit ~ ., data = training_set)
And somehow now lm
knows not to fit a multiple regression linear line?
It's modifying the original data set before it's even passed into lm
, so unless lm
is somehow trying to interpret my data to figure out which actual model to use, I don't see how it's knowing to do this...?
lm
needs to make for this. $\endgroup$x*
term and not thex^2
). But in a simple or multiple linear regression its a best fitting "straight line", solved for either by gradient descent or analytically, right? So how does, in this case, it know to use some other method to make a model who's function generates a curved line instead of straight. I can only imagine it is using some strategy to fit the line that isn't used in a simple or multiple linear regression? $\endgroup$lm
formula "solving" for the slope and y intercept of the regression line using some method? In certain dataset inputs, the line is straight, as if it were solvingy = mx + b
and other times, the outputted line is not straight (includingx^2 + x^3
in the data etc), I'm wondering what mechanism is making this happen? Why are some model lines straight (even with multiple independent variables, like in a "multiple linear regression"), and then a curved line is output for other datasets? $\endgroup$