V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
windflurry
V2EX  ›  问与答

[scala]xgboost4j 中的 train 方法要求接收 dmatrix 参数,怎么将 dataframe 格式转成 dmatrix 啊

  •  
  •   windflurry · 2019-03-14 11:08:47 +08:00 · 3710 次点击
    这是一个创建于 2018 天前的主题,其中的信息可能已经有所发展或是发生改变。

    xgboost4j 中的 train 方法要求接收 dmatrix 参数,怎么将 dataframe 格式转成 dmatrix 啊

    1 条回复    2019-04-28 16:26:55 +08:00
    liangzulin
        1
    liangzulin  
       2019-04-28 16:26:55 +08:00
    DataFrame ?你确定说的是 DataFrame 吗?这是 xgboost python 里边的 API 吧。
    spark 在 JAVA 里边是 Dataset<>

    如果是 pandas DataFrame 的话,转成 DMatrix 是这么转的:
    df = pd.read_csv('some_data.csv')
    X_train_df = df[['col_x1', 'col_x2', 'col_x3', 'col_x4']]
    y_train_df = df[['col_y']]
    dtrain = xgb.DMatrix(X_train_df, label=y_train_df)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2783 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:42 · PVG 14:42 · LAX 23:42 · JFK 02:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.