首页 > 解决方案 > Statsmodel 奇怪的行为

问题描述

我在 python 中使用 statsmodels 来执行分位数回归。我正在运行分位数 99 和分位数 1 来查看我的分布的极端分位数。

from statsmodels.regression.quantile_regression import QuantReg
from sklearn.datasets import load_iris
import pandas as pd

iris = pd.DataFrame(load_iris()['data'])

y = iris[0]
x = iris.iloc[:, [1, 2, 3]]

qt = QuantReg(y, x)
res99 = qt.fit(q=.99)
res01 = qt.fit(q=.01)
print('Quantile 99 description')
print(res99.predict(x).describe())
print('--------------------')
print('Quantile 01 description')
print(res01.predict(x).describe())
print('--------------------')
print('Target description')
print(y.describe())

输出是

Quantile 99 description
count    150.000000
mean       6.713570
std        1.092909
min        3.972447
25%        5.798665
50%        6.745737
75%        7.447919
max        9.906085
dtype: float64
--------------------
Quantile 01 description
count    150.000000
mean       5.196659
std        0.811265
min        3.110156
25%        4.555466
50%        5.270011
75%        5.777980
max        7.588576
dtype: float64
--------------------
Target description
count    150.000000
mean       5.843333
std        0.828066
min        4.300000
25%        5.100000
50%        5.800000
75%        6.400000
max        7.900000
Name: 0, dtype: float64

也就是说,百分位数 1、目标和百分位数 99 的分布并没有太大的不同。这是预期的还是我错过了什么?

标签: pythonregressionstatsmodelsquantile-regression

解决方案


推荐阅读