作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 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/
我正在使用 mord (scikitlearn) 库运行序数(即多项式)岭回归。 y 是包含从 1 到 19 的整数值的单个列。 X 由分装在 4 个桶中的 7 个数值变量组成,并伪装成最终的 28
我是一名优秀的程序员,十分优秀!