博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pasty公式
阅读量:6303 次
发布时间:2019-06-22

本文共 3330 字,大约阅读时间需要 11 分钟。

 (博主亲自录制视频)

 

http://patsy.readthedocs.io/en/latest/overview.html

 

pasty功能:线性分析里因素分析(方差分析)

and Patsy takes care of building appropriate matrices. Furthermore, it:

  • Allows data transformations to be specified using arbitrary Python code: instead of x, we could have written log(x), (x > 0), or even log(x) if x > 1e-5 else log(1e-5),
  • Provides a range of convenient options for coding variables, including automatic detection and removal of redundancies,
  • Knows how to apply ‘the same’ transformation used on original data to new data, even for tricky transformations like centering or standardization (critical if you want to use your model to make predictions),
  • Has an incremental mode to handle data sets which are too large to fit into memory at one time,
  • Provides a language for symbolic, human-readable specification of linear constraint matrices,
  • Has a thorough test suite (>97% statement coverage) and solid underlying theory, allowing it to correctly handle corner cases that even R gets wrong, and
  • Features a simple API for integration into statistical packages.

 

pasty不能做的模型分析,只是提供描述性统计的高级接口

What Patsy won’t do is, well, statistics — it just lets you describe models in general terms. It doesn’t know or care whether you ultimately want to do linear regression, time-series analysis, or fit a forest of , and it certainly won’t do any of those things for you — it just gives a high-level language for describing which factors you want your underlying model to take into account. It’s not suitable for implementing arbitrary non-linear models from scratch; for that, you’ll be better off with something like , , or just plain Python. But if you’re using a statistical package that requires you to provide a raw model matrix, then you can use Patsy to painlessly construct that model matrix; and if you’re the author of a statistics package, then I hope you’ll consider integrating Patsy as part of your front-end.

Patsy’s goal is to become the standard high-level interface to describing statistical models in Python, regardless of what particular model or library is being used underneath.

 

 

 

pasty函数可以自定义

 

I()让+表示算术模式加号

Arithmetic transformations are also possible, but you’ll need to “protect” them by wrapping them in , so that Patsy knows that you really do want + to mean addition:

In [23]: dmatrix("I(x1 + x2)", data) # compare to "x1 + x2" Out[23]: DesignMatrix with shape (8, 2) Intercept I(x1 + x2) 1 1.66083 1 0.81076 1 1.12278 1 3.69517 1 2.62860 1 -0.85560 1 1.39395 1 0.18232 Terms: 'Intercept' (column 0) 'I(x1 + x2)' (column 1)

 

In [24]: dmatrix("I(x1 + x2)", { "x1": np.array([1, 2, 3]), "x2": np.array([4, 5, 6])}) Out[24]: DesignMatrix with shape (3, 2) Intercept I(x1 + x2) 1 5 1 7 1 9 Terms: 'Intercept' (column 0) 'I(x1 + x2)' (column 1) In [25]: dmatrix("I(x1 + x2)", { "x1": [1, 2, 3], "x2": [4, 5, 6]}) Out[25]: DesignMatrix with shape (6, 2) Intercept I(x1 + x2) 1 1 1 2 1 3 1 4 1 5 1 6 Terms: 'Intercept' (column 0) 'I(x1 + x2)' (column 1)

 

 

 

# ---------------------------------------------------------------

def anova_statsmodels():
    ''' do the ANOVA with a function '''
    
    # Get the data
    data = pd.read_csv('galton.csv')
    #sex是性别,属于分类变量
    anova_results = anova_lm(ols('height~C(sex)', data).fit())
    print('\nANOVA with "statsmodels" ------------------------------')
    print(anova_results)
    
    return anova_results['F'][0]

 

转载地址:http://qufxa.baihongyu.com/

你可能感兴趣的文章
云原生的新思考,为什么容器已经无处不在了
查看>>
linux centos DNS服务器的安装与部署
查看>>
(LNMP)Linux + Nginx + Mysql +PHP WEB站点安装包
查看>>
配置hadoop+pyspark环境
查看>>
oracle子查询详解2
查看>>
酒旗风暖少年狂,为初级前端开发工程师做学习计划
查看>>
ASP.Net MVC3安全升级导致程序集从3.0.0.0变为3.0.0.1
查看>>
c primer plus(第五版)读书笔计 第六章(7)
查看>>
【1】puppet笔记 - file资源
查看>>
Visual Studio Xamarin提示Bonjour backend初始化失败
查看>>
我的友情链接
查看>>
windows 2003 安全 配置
查看>>
常用排序算法(五)——堆排序
查看>>
shell中使用>/dev/null 2>&1 丢弃信息
查看>>
Centos7.3系统安装教程
查看>>
Android监听器实现(一)Broadcast方式监听系统事件
查看>>
sitemesh 2.4的用法
查看>>
深入理解java虚拟机——HotSpot的算法实现
查看>>
从oracle dba的角度看HANA数据库
查看>>
Android Widget 开发实例:桌面便签程序的实现详解和源码
查看>>