gpt4 book ai didi

python - 序数逻辑回归 : Intercept_ returns [1] instead of [n]

转载 作者:太空狗 更新时间:2023-10-30 00:00:55 24 4
gpt4 key购买 nike

我正在使用 mord (scikitlearn) 库运行序数(即多项式)岭回归。

y 是包含从 1 到 19 的整数值的单个列。

X 由分装在 4 个桶中的 7 个数值变量组成,并伪装成最终的 28 个二进制变量。

import pandas as pd
import numpy as np
from sklearn import metrics
from sklearn.model_selection import train_test_split
import mord

in_X, out_X, in_y, out_y = train_test_split(X, y,
stratify=y,
test_size=0.3,
random_state=42)

mul_lr = mord.OrdinalRidge(alpha=1.0,
fit_intercept=True,
normalize=False,
copy_X=True,
max_iter=None,
tol=0.001,
solver='auto').fit(in_X, in_y)

mul_lr.coef_ 返回 [28 x 1] 数组,但 mul_lr.intercept_ 返回单个值(而不是 19)。

知道我错过了什么吗?

最佳答案

如果您希望您的模型预测所有 19 个类别,您需要先将标签 y 转换为一种热编码,然后再训练模型。

from sklearn.preprocessing import OneHotEncoder

y-=1 # range from 1 to 19 -> range from 0 to 18
enc = OneHotEncoder(n_values=19)
y = enc.fit_transform(y).toarray()
"""
train a model
"""

现在 mul_lr.intercept_.shape 应该是 (19,)

关于python - 序数逻辑回归 : Intercept_ returns [1] instead of [n],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54927571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com