簡體   English   中英

什么是python中的coef()等價函數

[英]What is coef() equivalent function in python

R我們有coef() ,您可以將其應用於線性模型並獲得構建線性模型的所有不同coefficientIntercept值。

python它的等效代碼是什么?

我需要解釋我所做的elastic net regression modelinterceptcoefficients

這將幫助我形成模型的回歸方程。

這取決於你在做什么。 評論你在做什么,我會編輯我的答案來幫助你。

對於 scikit-learn,您應該使用以下內容:

import numpy as np
from sklearn.linear_model import LinearRegression

X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]]) #Your x values, for a 2 variable model.
#y = 1 * x_0 + 2 * x_1 + 3 #This is the "true" model
y = np.dot(X, np.array([1, 2])) + 3 #Generating the true y-values
reg = LinearRegression().fit(X, y) #Fitting the model given your X and y values.
reg.coef_ #Prints an array of all regressor values (b1 and b2)
reg.intercept_  #Prints value for intercept/b0 
reg.predict(np.array([[3, 5]])) #Predicts an array of y-values with the fitted model given the inputs

來自: Scikit-learn linear_model_regression

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM