V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
windflurry
V2EX  ›  问与答

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

  •  
  •   windflurry · Mar 14, 2019 · 4005 views
    This topic created in 2606 days ago, the information mentioned may be changed or developed.

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

    1 replies    2019-04-28 16:26:55 +08:00
    liangzulin
        1
    liangzulin  
       Apr 28, 2019
    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)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2505 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 02:38 · PVG 10:38 · LAX 19:38 · JFK 22:38
    ♥ Do have faith in what you're doing.