1. Job Roadmap
  2. Home
  3. Problem Set
  4. codenotelist
  5. Forum
  6. course
  7. Shore Share Sessions
  8. Record
  1. Login
  2. Sign Up
  3. Language
    1. English
    2. 한국어
    3. 简体中文
    4. 正體中文
    ZhContent TextSol AI分析

思路

  1. 读取与解析输入

    • 使用 sys.stdin.read() 读取输入 JSON 字符串;
    • 使用 json.loads() 转换为 Python 数据结构。
  2. 数据分离与转换

P3609.第2题-随机森林二分类器

    1000ms Tried: 22 Accepted: 14 Difficulty: 5 所属公司 : 蚂蚁
    算法与标签>机器学习算法

题目内容

请在仅使用 numpy/pandas/scikit−learnnumpy / pandas / scikit-learnnumpy/pandas/scikit−learn 的前提下,实现一个随机森林二分类器并对测试样本输出类别预测。

  1. 读取数据
  • traintraintrain:二维列表;最后一列为标签 y∈0,1y ∈ {0, 1}y∈0,1,前 mmm 列为数值特征,m≥1m ≥ 1m≥1
  • testtesttest:二维列表;仅含特征,与训练集同维度
  1. 预处理
  • 使用 StandardScalerStandardScalerStandardScaler :在训练集 fitfitfit,将 traintraintrain 和 testtesttest 分别 transformtransformtransform
  1. 模型
  • 你可能会用到的随机森林固定参数值:
    • nnn_estimators=50estimators = 50estimators=50
    • minminmin_samplessamplessamples _split=2split = 2split=2
    • minminmin_samplessamplessamples _leaf=1leaf = 1leaf=1
    • randomrandomrandom_state=42state = 42state=42
  • 其余超参数保持默认;不得改动 nnn_estimatorsestimatorsestimators 或 randomrandomrandom _statestatestate
  1. 训练 & 预测
  • 在全部训练样本上 fitfitfit
  • 然后对 testtesttest 进行预测,输出预测类别

输入描述

标准输入仅一行 JSON,示例:

{
 "train":[[-2.0,0],
          [-1.8,0],
          [-2.2,0],
          [2.0,1],
          [2.1,1],
          [1.9,1]],
 "test":[[-1.0],
         [2.0]]
}
  • 训练数据量 ≥6≥ 6≥6 且两类样本数均 ≥3≥ 3≥3,维度 ≥1≥ 1≥1。

  • 所有值为整数/浮点数,无空行。

输出描述

仅输出一行,格式为 JSONJSONJSON 数组,如:

[0, 1]

长度等于测试样本数,

合法 JSONJSONJSON ,逗号后带空格。

补充说明

  1. 所有随机过程均需显式设置 randomrandomrandom_state=42state=42state=42
  2. 为确保通过测试用例,仅使用 numpy/pandas/scikit−learnnumpy / pandas / scikit-learnnumpy/pandas/scikit−learn 实现

样例1

输入

{"train":[[-2.0,0],[-1.8,0],[-2.2,0],[2.0,1],[2.1,1],[1.9,1]],"test":[[-1.0],[2.0]]}

输出

[0, 1]

登录后即可使用 AI 分析。

模式
倒计时时长
:

最长 10 小时 59 分;应用后按此时长重新开始。

提示:点击提交记录在左侧题面区域查看详情
题库
AI分析设置
留空使用官方API Key,每天有次数限制(自定义API Key仅限会员和管理员使用,不限次数)
会员和管理员可切换模型;切到 Kimi/智谱/通义/豆包时需填写对应供应商 API Key
升级会员,可将运行与提交冷却时间缩短至 1 秒起

Status

  • Judging Queue
  • Service Status

Development

  • Open Source

Support

  • Help
  • Contact Us

About

  • About
  • Privacy
  • Terms of Service
  • Copyright Complaint
  1. Language
    1. English
    2. 한국어
    3. 简体中文
    4. 正體中文
  2. Legacy mode
  3. Theme
    1. Light
    2. Dark
  1. 京ICP备2025123107号-1
  2. Worker 3, 39ms
  3. Powered by Hydro v5.0.0-beta.18 Community
CLOSE


ScanQRCodePrompt

请使用微信扫描下方二维码完成注册

Forgot password or username?