在 Python 中获取 sklearn 多项式回归模型的系数

Sim*_*ith 5 python scikit-learn

我想用Python获取sklearn多项式回归模型的系数,这样我就可以在其他地方编写方程..即ax1^2 + ax + bx2^2 + bx2 + c

我已经在其他地方查看了答案,但似乎无法找到解决方案,除非我只是不知道我在看什么。

from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree = 2)
X_poly = poly_reg.fit_transform(X_train)
lin_reg_2 = LinearRegression()
lin_reg_2.fit(X_poly,y_train)

lin_reg_2.coef_
Run Code Online (Sandbox Code Playgroud)

小智 -1

支持向量回归:

\n\n
from sklearn.svm import SVR\nimport numpy as np\nn_samples, n_features = 10, 5\nnp.random.seed(0)\ny = np.random.randn(n_samples)\nX = np.random.randn(n_samples, n_features)\nclf = SVR(kernel="poly",degree=3,gamma="scale",C=0.8)\nclf.fit(X, y) \nclf.predict(X)\n
Run Code Online (Sandbox Code Playgroud)\n\n

sklearn.svm.SVR\xef\xbc\x9a 类的定义

\n\n
class sklearn.svm.SVR(kernel=\xe2\x80\x99rbf\xe2\x80\x99, degree=3, gamma=\xe2\x80\x99auto_deprecated\xe2\x80\x99, coef0=0.0, tol=0.001, C=1.0, epsilon=0.1, shrinking=True, cache_size=200, verbose=False, max_iter=-1)\n
Run Code Online (Sandbox Code Playgroud)\n