首页 > 解决方案 > teradataml:如何使用 teradataml 生成 xgboost 模型?

问题描述

我正在尝试使用 teradataml 生成 XGBoost 模型。此示例将展示如何在 teradataml 中使用 xgboost。假设训练和测试数据存在于 teradata 数据库中。

标签: pythonteradata

解决方案


  1. 导入库

    import teradataml
    from teradataml.context.context import *
    from teradataml.dataframe.dataframe import DataFrame
    from teradataml.analytics.mle.XGBoost import XGBoost
    from teradataml.analytics.mle.XGBoostPredict import XGBoostPredict
    
  2. 创建上下文

    housing_train_binary = DataFrame.from_table("housing_train_binary")
    housing_test_binary = DataFrame.from_table("housing_test_binary")
    
  3. 生成模型

    xgboostmodel = XGBoost(data=housing_train_binary,
                         id_column='sn',
                         formula=" homestyle ~ driveway +  recroom +  fullbase +  gashw +  airco +  prefarea ",
                         num_boosted_trees=2,
                         loss_function='SOFTMAX',
                         prediction_type='CLASSIFICATION',
                         reg_lambda=1.0,
                         shrinkage_factor=0.1,
                         column_subsampling=1.0,
                         iter_num=10,
                         min_node_size=1,
                         max_depth=12,
                         variance=0.0,
                         seed=1,
                         data_sequence_column=['sn', 'homestyle']
                         );
    
  4. 预测

    xgpredict = XGBoostPredict(newdata=housing_test_binary, object=result, object_order_column=['tree_id', 'iter','class_num']);
    

推荐阅读