我正在尝试将分位数回归模型与我的输入数据相匹配。我想使用sklearn,但当我试图适应这个模型时,我得到了一个内存分配错误。与statsmodels等效函数相同的数据运行良好。
我得到的错误如下:
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 55.9 GiB for an array with shape (86636, 86636) and data type float64
没有任何意义,我的X和y分别是形状(86636,4)和(86636,1)。
这是我的剧本:
import pandas as pd
import statsmodels.api as sm
from sklearn.linear_model import QuantileRegressor
training_df = pd.read_csv("/path/to/training_df.csv") # 86,000 rows
FEATURES = [
"feature_1",
"feature_2",
"feature_3",
"feature_4",
]
TARGET = "target"
# STATSMODELS WORKS FINE WITH 86,000, RUNS IN 2-3 SECONDS.
model_statsmodels = sm.QuantReg(training_df[TARGET], training_df[FEATURES]).fit(q=0.5)
# SKLEARN GIVES A MEMORY ALLOCATION ERROR, OR TAKES MINUTES TO RUN IF I SIGNIFICANTLY TRIM THE DATA TO < 1000 ROWS.
model_sklearn = QuantileRegressor(quantile=0.5, alpha=0)
model_sklearn.fit(training_df[FEATURES], training_df[TARGET])
我已经检查了sklearn文档,并且非常肯定我的输入和dataframes一样好,我在NDarrays中也遇到了同样的问题。所以不知道是什么问题。有可能有什么问题吗?
这是QunatileRegressor的scikit学习文档。
非常感谢你的帮助/想法。1:https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.QuantileRegressor.html
发布于 2022-08-10 01:01:14
sklearn类使用线性规划求解分位数回归问题,它比状态模型QuantReg类使用的迭代重加权最小二乘计算量大得多。
下面是同一个问题的github问题:https://github.com/scikit-learn/scikit-learn/issues/22922
https://stackoverflow.com/questions/73296984
复制