第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

多變量回歸 statsmodels.api

多變量回歸 statsmodels.api

桃花長相依 2023-06-20 17:18:00
我查看了文檔,但仍然無法弄清楚。我想運行具有多重回歸的 WLS。statsmodels.api 作為 sm 導(dǎo)入單變量示例。X = Height Y = Weight res = sm.OLS(Y,X,).fit()  res.summary()說我也有:X2 = 年齡如何將其添加到我的回歸中?
查看完整描述

2 回答

?
飲歌長嘯

TA貢獻1951條經(jīng)驗 獲得超3個贊

您可以將它們放入 data.frame 并調(diào)出列(這樣輸出看起來也更好):


import statsmodels.api as sm

import pandas as pd

import numpy as np


Height = np.random.uniform(0,1,100)

Weight = np.random.uniform(0,1,100)

Age = np.random.uniform(0,30,100)


df = pd.DataFrame({'Height':Height,'Weight':Weight,'Age':Age})


res = sm.OLS(df['Height'],df[['Weight','Age']]).fit()


In [10]: res.summary()

Out[10]: 

<class 'statsmodels.iolib.summary.Summary'>

"""

                                 OLS Regression Results                                

=======================================================================================

Dep. Variable:                 Height   R-squared (uncentered):                   0.700

Model:                            OLS   Adj. R-squared (uncentered):              0.694

Method:                 Least Squares   F-statistic:                              114.3

Date:                Mon, 24 Aug 2020   Prob (F-statistic):                    2.43e-26

Time:                        15:54:30   Log-Likelihood:                         -28.374

No. Observations:                 100   AIC:                                      60.75

Df Residuals:                      98   BIC:                                      65.96

Df Model:                           2                                                  

Covariance Type:            nonrobust                                                  

==============================================================================

                 coef    std err          t      P>|t|      [0.025      0.975]

------------------------------------------------------------------------------

Weight         0.1787      0.090      1.988      0.050       0.000       0.357

Age            0.0229      0.003      8.235      0.000       0.017       0.028

==============================================================================

Omnibus:                        2.938   Durbin-Watson:                   1.813

Prob(Omnibus):                  0.230   Jarque-Bera (JB):                2.223

Skew:                          -0.211   Prob(JB):                        0.329

Kurtosis:                       2.404   Cond. No.                         49.7

==============================================================================


查看完整回答
反對 回復(fù) 2023-06-20
?
POPMUISE

TA貢獻1765條經(jīng)驗 獲得超5個贊

我使用二階多項式來預(yù)測身高和年齡如何影響士兵的體重。您可以在我的 GitHub 上獲取 ansur_2_m.csv。


 df=pd.read_csv('ANSUR_2_M.csv', encoding = "ISO-8859-1",   usecols=['Weightlbs','Heightin','Age'],  dtype={'Weightlbs':np.integer,'Heightin':np.integer,'Age':np.integer})

 df=df.dropna()

 df.reset_index()

 df['Heightin2']=df['Heightin']**2

 df['Age2']=df['Age']**2


 formula="Weightlbs ~ Heightin+Heightin2+Age+Age2"

 model_ols = smf.ols(formula,data=df).fit()

 minHeight=df['Heightin'].min()

 maxHeight=df['Heightin'].max()

 avgAge = df['Age'].median()

 print(minHeight,maxHeight,avgAge)


 df2=pd.DataFrame()


 df2['Heightin']=np.linspace(60,100,50)

 df2['Heightin2']=df2['Heightin']**2

 df2['Age']=28

 df2['Age2']=df['Age']**2


 df3=pd.DataFrame()

 df3['Heightin']=np.linspace(60,100,50)

 df3['Heightin2']=df2['Heightin']**2

 df3['Age']=45

 df3['Age2']=df['Age']**2


 prediction28=model_ols.predict(df2)

 prediction45=model_ols.predict(df3)


 plt.clf()

 plt.plot(df2['Heightin'],prediction28,label="Age 28")

 plt.plot(df3['Heightin'],prediction45,label="Age 45")

 plt.ylabel="Weight lbs"

 plt.xlabel="Height in"

 plt.legend()

 plt.show()


 print('A 45 year old soldier is more probable to weight more than an 28 year old soldier')



查看完整回答
反對 回復(fù) 2023-06-20
  • 2 回答
  • 0 關(guān)注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號