Original link:http://tecdat.cn/?p=23104
Polynomial regression is a nonlinear relationship between independent X variables and causal Y variables. Fit this type of regression is essential when we analyze volatility data with some curvature. In this article, we’ll learn how to use polynomial regression data to fit a curve and plot it in Python. We use the NumPy and Matplotlib libraries throughout this tutorial.
We’ll start by loading the modules required for this tutorial.
import numpy as np
import matplotlib.pyplot as plt
We need test data, which we can generate as shown in the figure below. You can also use your own data set.
Train_x = np.array(x) train_y = np.array(y)
We will visually examine the X data by creating a scatter plot.
plt.scatter(train\_x, train\_y)
Next, we will use the PolymonialFeatures class to define the polynomial model to fit on the training data.
fit\_transform(train\_x.reshape(-1, 1))
We need a linear model, which we will define and fit on the training data. And then we use this model to predict the X data.
liniearModel.fit(xpol, train_y\[:,\])
Finally, we will plot the fitting curve.
plt.plot(train_x, polyfit, color = 'red')
In this article, we have briefly looked at how to fit polynomial regression data in Python.
The most popular insight
1. Application case of multiple Logistic Logistic regression in R language
2. Implementation of Panel Smooth Transfer Regression (PSTR) analysis case
3. Partial least squares regression (PLSR) and principal component regression (PCR) in MATLAB
4. Case study of R language Poisson regression model
5. Hosmer-Lemeshow goodness of fit test in R language regression
6. Realization of Lasso regression, Ridge Ridge regression and Elastic Net model in R language
7. Logistic Logistic regression was realized in R language
8. Python uses linear regression to predict stock prices
9. How does R language calculate IDI and NRI indexes in survival analysis and Cox regression