6

【statsmodels】Quantile regression

 3 years ago
source link: https://www.guofei.site/2019/04/07/quantile_regression.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【statsmodels】Quantile regression

2019年04月07日

Author: Guofei

文章归类: 4-1-统计模型 ,文章编号: 409


版权声明:本文作者是郭飞。转载随意,但需要标明原文链接,并通知本人
原文链接:https://www.guofei.site/2019/04/07/quantile_regression.html

Edit

官网代码

简介

还没来得及去看论文原文,这个模型用语言描述就是对数据的q分位数进行回归

实现

step1. 载入包和数据

import numpy as np
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
from statsmodels.regression.quantile_regression import QuantReg

data = sm.datasets.engel.load_pandas().data

step2. 拟合

mod = smf.quantreg('foodexp ~ income', data)
res = mod.fit(q=0.5)  # q是分位点

step3.结果分析

res.summary()
res.params  # 一个series,存放的是每个系数的值
res.conf_int()  # 一个DataFrame,存放的是每个系数上界和下界

其它:原文使q取 0.05~0.95 范围内10个数字,拟合10次,画出各分位点拟合图


您的支持将鼓励我继续创作!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK