我尝试使用以下代码在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中进行逻辑回归相关推荐

  1. python 去除panda安装包_沉淀,再出发:python中的pandas包

    沉淀,再出发:python中的pandas包 一.前言 python中有很多的包,正是因为这些包工具才使得python能够如此强大,无论是在数据处理还是在web开发,python都发挥着重要的作用,下 ...

  2. python中如何移动图形工作站_六招教你用Python分分钟构建好玩的深度学习应用

    原标题:六招教你用Python分分钟构建好玩的深度学习应用 导读]深度学习是近来数据科学中研究和讨论最多的话题.得益于深度学习的发展,数据科学在近期得到了重大突破,深度学习也因此得到了很多关注.据预测 ...

  3. python删除链表中重复的节点_剑指offer:删除链表中重复的节点

    题目描述 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4->5 处理后 ...

  4. python服务发现与注册_(转)微服务架构中服务注册与发现

    https://blog.csdn.net/u011537073/article/details/69663858 想象一下,如果你在写代码调用一个有REST API或Thrift API的服务,你的 ...

  5. python创建类统计属性_轻松创建统计数据的Python包

    python创建类统计属性 介绍 (Introduction) Sometimes you may need a distribution figure for your slide or class ...

  6. python怎么复数乘方开方_运维必须掌握的 Python 宝典:值得每天复习一遍

    前言 本文旨在更好地总结 Python 基础知识,力求简明扼要,以供实战演练时能够快速查询遗忘的知识点. 学一门语言贵在坚持用它,不用就淡忘了,而记录下一篇文章也有助于日后快速回忆.全文分为两大部分, ...

  7. java中git使用教程_【教程】Git在Eclipse中的安装和基本使用

    一.安装 点击 Help->Install New Software->add 安装地址为:http://download.eclipse.org/egit/updates/ 选择插件 点 ...

  8. python人生的不同阶段_从入门到入土的Python自学教程,用改变你的人生轨迹

    Python在近几年越来越受追捧,很多童鞋或者职场小伙伴想要提升技能-学习Python. 这是非常好的事情,但问题在于很多人不知道学Python做什么,所以什么零碎细末.艰难晦涩.长篇大论的都去看,很 ...

  9. python webdriver点击指令_测开系列Selenium Webdriver Python(20)--Webdriver运行原理

    Webdriver运行原理 转帖请注明出处!谢谢 在开发Webdriver的自动化脚本过程中,Webdriver后台在创建WebDriver实例的过程中,先确认浏览器的原生组件中是否存在可匹配的版本. ...

最新文章

  1. C#_细说Cookie_Json Helper_Cookies封装
  2. mysql常用的分组函数
  3. 网易2019实习生招聘题目 被3整除
  4. jsp里面编写java代码注意加双引号
  5. 让Vue也可以使用Redux
  6. Sphinx编译docs文档
  7. 为什么很多人C语言学不下去
  8. [MySQL FAQ]系列 -- 新年新思想:MySQL也能并发导入数据
  9. MyBatis3源码解析(8)MyBatis与Spring的结合
  10. 【Flutter】Dart的工厂构造方法单例对象初始化列表
  11. 基于UDP的网络群聊系统
  12. Android性能测试工具Emmagee
  13. Mac 输入法候选词框消失的解决方法
  14. UPC 6615 Snuke Festival
  15. 我们比任何时候都更接近梦想
  16. 全新娱乐性超高的喝酒神器微信小程序源码
  17. Bert中文文本多分类与传统BOW+tfidf+LR中文文本多分类对比
  18. There were errors checking the update sites: SSLHandshakeException: sun.secu解决方案
  19. 【云原生分布式存储】成书心路历程
  20. android布局优化!Android动态换肤实现原理解析,灵魂拷问

热门文章

  1. C#如何得到运行中和杀死运行中的进程?
  2. opencv连通域去除小块面积_晋中市建成区面积排名,榆次区最大,榆社县最小,来了解一下?...
  3. 在线地图插件forarcmap_QGIS基础篇插件安装(在线地图纠偏)
  4. 【控制】多智能体系统总结。1. 系统模型。2.控制目标。3.模型转换。
  5. 【STM32】位操作、按位与、按位或、按位异或、取反、左移、右移等基础 C 语言知识补充
  6. 一起学nRF51xx 12 -  flash
  7. 【arduino】亲测MAC上arduino安装ESP32 SPIFFS插件
  8. 【PC工具】大神开源项目-配色调色工具Colorpicker颜色选择器
  9. 【Android工具】wifi概观360中文专业版,wifi overview 360 pro,wifi信息查看工具
  10. c语言常用的异常处理,C语言中的异常处理