You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于step_lencode_mixed函数使用的三个技术疑问

关于step_lencode_mixed函数的三个技术疑问

根据官方vignette说明,step_lencode_mixed会为每个分类预测变量拟合广义线性模型,并返回系数作为编码结果。示例输出中的partial列是该函数的返回值,具体疑问如下:

  • 是否应将此partial列作为分类变量where_town的编码结果用于后续待拟合的新模型?
  • 后台是否拟合了包含所有变量的完整模型(Class ~ ., data = okc_train),并将where_town变量的贡献值以partial列返回?
  • 使用logit2prob函数转换partial值后,结果与rate几乎一致,是否说明该返回值并非系数?

附示例代码

# ------------------------------------------------------------------------------
# Feature Engineering and Selection: A Practical Approach for Predictive Models
# by Max Kuhn and Kjell Johnson
#
# ------------------------------------------------------------------------------
# 
# Code for Section 5.4 at
# https://bookdown.org/max/FES/categorical-supervised-encoding.html
#
# ------------------------------------------------------------------------------
# 
# Code requires these packages: 

library(tidymodels)
library(embed)

# Create example data ----------------------------------------------------------

load("../Data_Sets/OkCupid/okc.RData")
load("../Data_Sets/OkCupid/okc_binary.RData")

options(width = 120)

partial_rec <- 
  recipe(Class ~ ., data = okc_train) %>%
  step_lencode_mixed(
    where_town,
    outcome = vars(Class)
  ) %>%
  prep()

okc_train2 <- okc_train %>% select(where_town, Class)

partial_rec2 <- 
  recipe(Class ~ ., data = okc_train2) %>%
  step_lencode_mixed(
    where_town,
    outcome = vars(Class)
  ) %>%
  prep()

# Organize results -------------------------------------------------------------

partial_pooled <- 
  tidy(partial_rec, number = 1) %>%
  dplyr::select(-terms, -id) %>%
  setNames(c("where_town", "partial"))

partial_pooled <- left_join(partial_pooled, okc_props)

partial_pooled2 <- 
  tidy(partial_rec2, number = 1) %>%
  dplyr::select(-terms, -id) %>%
  setNames(c("where_town", "partial"))

all.equal(partial_pooled, partial_pooled2)
>
[1] TRUE

内容的提问来源于stack exchange,提问作者user2165379

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 15:15:28