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

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Python 中使用 statsmodels.api.OLS

如何在 Python 中使用 statsmodels.api.OLS

手掌心 2022-10-11 16:01:48
我已經(jīng)開始學(xué)習(xí)機(jī)器學(xué)習(xí),并且正在嘗試實(shí)現(xiàn)線性回歸反向消除。這是代碼:import statsmodels.api as smx = sm.add_constant(x)x_opt = x[:,[0,1,2,3,4,5]]regressor_OLS = sm.OLS(endog=y,exog=x_opt)這是錯(cuò)誤:Traceback (most recent call last):  File "<input>", line 1, in <module>  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\regression\linear_model.py", line 859, in __init__    hasconst=hasconst, **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\regression\linear_model.py", line 702, in __init__    weights=weights, hasconst=hasconst, **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\regression\linear_model.py", line 190, in __init__    super(RegressionModel, self).__init__(endog, exog, **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\base\model.py", line 236, in __init__    super(LikelihoodModel, self).__init__(endog, exog, **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\base\model.py", line 77, in __init__    **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\base\model.py", line 100, in _handle_data    data = handle_data(endog, exog, missing, hasconst, **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\base\data.py", line 672, in handle_data    **kwargs)  File "C:\Users\ewasy\AppData\Local\Programs\Python\Python37\lib\site-packages\statsmodels\base\data.py", line 87, in __init__    self._handle_constant(hasconst)這是變量 x 的 2 行:array([[1.0, 0.0, 1.0, 2.016411493158463, 0.560752914530775,2.153943088571744],       [1.0, 0.0, 0.0, 1.9558603364325031, 1.0828065830760816,1.9236003956421444]], dtype=object)這是變量 y 的 2 行:array([[2.01120333],[1.99942997]])
查看完整描述

2 回答

?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊

問題是在您的代碼x中有dtype=object而不是dtype=float, 即x不是數(shù)字變量,因此它不能用作回歸量。一旦x轉(zhuǎn)換為float您的代碼就可以工作。



查看完整回答
反對 回復(fù) 2022-10-11
?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

import statsmodels.api as sm


def model(X,y):

    X=sm.add_constant(X)

    lm_model=sm.OLS(y,X).fit()

    print(lm_model.summary())

    return X


X_train1=model(X_train_rfe,y_train)

如果您想查看基本的詳細(xì) ML 問題:https ://github.com/ds-souvik/Machine-Learning-Basic-Intermediate-Expert./tree/master/10%20Linear%20Regression-%20BoomBikes%20Bike%20Sharing %20服務(wù)%20業(yè)務(wù)%20案例


查看完整回答
反對 回復(fù) 2022-10-11
  • 2 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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