Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 400K 观察值和 250 个特征的数据集。我想进行分层抽样。
我提到了很多链接,但它们都是在包括 Target 在内的 1 或 2 个变量示例之后。
任何人都可以帮助我如何使用 R / Python 执行分层抽样。
感谢提前!
如果您首先对 data.frame 进行分组,则可以使用 dplyr 的 sample_n() 对每个组进行采样
library(dplyr) sample.df <- df %>% group_by( ID ) %>% sample_n( 10 )