두 가지 특징이있는 선형 회귀는 다음 방정식으로 설명 할 수 있습니다.
y = a1x1 + a2x2 + 절편
다중 선형 회귀를 피팅하면 계수 a1
및 a2
. 다음 코드를 고려하십시오.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
file = 'https://aegis4048.github.io/downloads/notebooks/sample_data/unconv_MV_v5.csv'
df = pd.read_csv(file)[['Por', 'Perm', 'Prod']]
features = df[['Por', 'Perm']].values.reshape(-1,2)
target = df['Prod']
ols = linear_model.LinearRegression()
model = ols.fit(features, target)
predicted = model.predict(features)
coef = model.coef_
pd.DataFrame(coef, index=['Por', 'Perm'], columns=['Regression Coef']).round(2)
>>> Regression Coef
Por 244.47
Perm 97.75
두 기능은 Por
및 Perm
입니다. 회귀 계수의 Perm
값을 고정 값으로 고정하고 계수에 대해서만 해결 하고 싶습니다 Por
. 파이썬에서 어떻게 할 수 있습니까?
말 Por
은 a2
입니다. 의 값을 a2
고정 값 A2로 설정하면 선형 회귀가 y(a1) = a1x1 + (A2x2 + intercept)
. 따라서, 당신은 단순히 단순 선형 회귀 해결할 수있는 y(a1) = a1x1 + intercept_new
, intercept_new
이미 계정 설정에 걸릴 Por
일정한 값을.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다