Polynomial Linear Regression with NumPy
Polynomial linear regression using Sklearn is tedious as one has to explicitly code its features. This can get challenging when one has to iteratively build higher-degree polynomial models.
NumPy's 𝐩𝐨𝐥𝐲𝐟𝐢𝐭() method is an excellent alternative to this. Here, you can specify the degree of the polynomial as a parameter. As a result, it automatically creates the corresponding polynomial features.
The downside is that you cannot add custom features such as trigonometric/logarithmic. In other words, you are restricted to only polynomial features. But if that is not your requirement, NumPy's 𝐩𝐨𝐥𝐲𝐟𝐢𝐭() method can be a better approach.
Read more here: https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html
Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.
P.S. I post these daily tips on LinkedIn as well. You can read them here: https://www.linkedin.com/in/avi-chawla/recent-activity/shares