why i shouldn't just increase my polyfit to a random number in matlab

Increasing the order of the polynomial in a polyfit function can lead to overfitting of the data, resulting in a model that fits the training data very well but generalizes poorly to new, unseen data. This is because as the degree of the polynomial increases, the model tries to fit every little wiggle in the data, which may not be significant or representative of the true underlying relationship between the independent and dependent variables.

Overfitting can also lead to numerical instability, making it difficult to evaluate the model's performance or make predictions. In addition, using a high degree polynomial requires more data to fit, and may result in a model that is computationally expensive to use.

It is generally recommended to use the smallest degree polynomial that adequately captures the main features of the data. Cross-validation, or splitting the dataset into training and validation sets, can help to identify the optimal degree of the polynomial. Other techniques, such as regularization, can also be used to prevent overfitting.

related categories

gistlibby LogSnag