日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中fit什么意思_使用Logit()和fit()在python中进行逻辑回归

發布時間:2025/4/5 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中fit什么意思_使用Logit()和fit()在python中进行逻辑回归 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我嘗試使用以下代碼在python中執行logistic回歸-from patsy import dmatrices

import numpy as np

import pandas as pd

import statsmodels.api as sm

df=pd.read_csv('C:/Users/Documents/titanic.csv')

df=df.drop(['ticket','cabin','name','parch','sibsp','fare'],axis=1) #remove columns from table

df=df.dropna() #dropping null values

formula = 'survival ~ C(pclass) + C(sex) + age'

df_train = df.iloc[ 0: 6, : ]

df_test = df.iloc[ 6: , : ]

#spliting data into dependent and independent variables

y_train,x_train = dmatrices(formula, data=df_train,return_type='dataframe')

y_test,x_test = dmatrices(formula, data=df_test,return_type='dataframe')

#instantiate the model

model = sm.Logit(y_train,x_train)

res=model.fit()

res.summary()

我在這條線上出錯了-

^{pr2}$

數據集中沒有丟失的值。但是,我的數據集非常小,只有10個條目。我不知道這里出了什么問題,我該怎么解決它?我在Jupyter筆記本上運行這個程序。整個錯誤信息如下----------------------------------------------------------------------------

PerfectSeparationError Traceback (most recent call last)

in ()

19 y_test,x_test = dmatrices(formula, data=df_test,return_type='dataframe')

20 model = sm.Logit(y_train,x_train)

---> 21 res=model.fit()

22 res.summary()

C:\Program Files\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py in fit(self, start_params, method, maxiter, full_output, disp, callback, **kwargs)

1374 bnryfit = super(Logit, self).fit(start_params=start_params,

1375 method=method, maxiter=maxiter, full_output=full_output,

-> 1376 disp=disp, callback=callback, **kwargs)

1377

1378 discretefit = LogitResults(self, bnryfit)

C:\Program Files\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py in fit(self, start_params, method, maxiter, full_output, disp, callback, **kwargs)

201 mlefit = super(DiscreteModel, self).fit(start_params=start_params,

202 method=method, maxiter=maxiter, full_output=full_output,

--> 203 disp=disp, callback=callback, **kwargs)

204

205 return mlefit # up to subclasses to wrap results

C:\Program Files\Anaconda3\lib\site-packages\statsmodels\base\model.py in fit(self, start_params, method, maxiter, full_output, disp, fargs, callback, retall, skip_hessian, **kwargs)

423 callback=callback,

424 retall=retall,

--> 425 full_output=full_output)

426

427 #NOTE: this is for fit_regularized and should be generalized

C:\Program Files\Anaconda3\lib\site-packages\statsmodels\base\optimizer.py in _fit(self, objective, gradient, start_params, fargs, kwargs, hessian, method, maxiter, full_output, disp, callback, retall)

182 disp=disp, maxiter=maxiter, callback=callback,

183 retall=retall, full_output=full_output,

--> 184 hess=hessian)

185

186 # this is stupid TODO: just change this to something sane

C:\Program Files\Anaconda3\lib\site-packages\statsmodels\base\optimizer.py in _fit_newton(f, score, start_params, fargs, kwargs, disp, maxiter, callback, retall, full_output, hess, ridge_factor)

246 history.append(newparams)

247 if callback is not None:

--> 248 callback(newparams)

249 iterations += 1

250 fval = f(newparams, *fargs) # this is the negative likelihood

C:\Program Files\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py in _check_perfect_pred(self, params, *args)

184 np.allclose(fittedvalues - endog, 0)):

185 msg = "Perfect separation detected, results not available"

--> 186 raise PerfectSeparationError(msg)

187

188 def fit(self, start_params=None, method='newton', maxiter=35,

PerfectSeparationError: Perfect separation detected, results not available

總結

以上是生活随笔為你收集整理的python中fit什么意思_使用Logit()和fit()在python中进行逻辑回归的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。