Skip to main content

pyXgboost,github:https://github.com/303844828/PyXGBoost.git

Project description

Introduction

xgboost for pyspark

python install

pip install PyXGBoost

code examples:

from pyspark.sql import SparkSession
from PyXGBoost import PyXGBoostClassifier, PyXGBoostClassificationModel
spark = SparkSession \
    .builder \
    .appName("pyspark xgboost") \
    .getOrCreate()

df=spark.read.csv("src/main/resources/iris.csv",schema="sepal_length double, sepal_width double, petal_length double,petal_width double,label int")
df=df.fillna(0)
#same as xgboost param map
params0 = {
    "objective" :"binary:logistic"
    , "eta" : 0.01
    , "max_depth" : 6
    , "min_child_weight" : 50
    , "colsample_bytree" : 0.5
    , "silent" : 0
    , "seed" : 12345
}

xgb=PyXGBoostClassifier(params0)

xgb.set_num_round(11) \
    .set_num_workers(11)

feature_names=["sepal_length","sepal_width","petal_length","petal_width"]
xgbModel=xgb.train(df,feature_names, "label")
xgbModel.saveOverwrite("hdfs://xxxx")
#xgbModel.write().overwrite().save("hdfs://xxxx")
xgbModel=PyXGBoostClassificationModel.load("hdfs://xxxx")
result_df=xgbModel.transform(df,feature_names)

submit

spark-submit --master yarn-cluster --num-executors 100 \
--jars pyspark-xgboost-1.0-SNAPSHOT.jar  \
--py-files pyspark-xgboost-1.0-SNAPSHOT.jar \
--files test.py

简介

pyspark版本的xgboost

首先执行:

pip install PyXGBoost 安装python版本xgboost

代码示例:

from pyspark.sql import SparkSession
from PyXGBoost import PyXGBoostClassifier, PyXGBoostClassificationModel
spark = SparkSession \
    .builder \
    .appName("pyspark xgboost") \
    .getOrCreate()

df=spark.read.csv("src/main/resources/iris.csv",schema="sepal_length double, sepal_width double, petal_length double,petal_width double,label int")
df=df.fillna(0)
#same as xgboost param map
params0 = {
    "objective" :"binary:logistic"
    , "eta" : 0.01
    , "max_depth" : 6
    , "min_child_weight" : 50
    , "colsample_bytree" : 0.5
    , "silent" : 0
    , "seed" : 12345
}

xgb=PyXGBoostClassifier(params0)

xgb.set_num_round(11) \
    .set_num_workers(11)

feature_names=["sepal_length","sepal_width","petal_length","petal_width"]
xgbModel=xgb.train(df,feature_names, "label")
xgbModel.saveOverwrite("hdfs://xxxx")
#xgbModel.write().overwrite().save("hdfs://xxxx")
xgbModel=PyXGBoostClassificationModel.load("hdfs://xxxx")
result_df=xgbModel.transform(df,feature_names)

提交

命令需要在两个地方带上jar包,示例:

spark-submit --master yarn-cluster --num-executors 100 \
--jars pyspark-xgboost-1.0-SNAPSHOT.jar  \
--py-files pyspark-xgboost-1.0-SNAPSHOT.jar \
--files test.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyXGBoost-1.0.5.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file PyXGBoost-1.0.5.tar.gz.

File metadata

  • Download URL: PyXGBoost-1.0.5.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.4.2 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

File hashes

Hashes for PyXGBoost-1.0.5.tar.gz
Algorithm Hash digest
SHA256 dfc35bf64c70ca543bdad37a0c3aa4d3109bf50ade494e7166e12ed0a4a25afc
MD5 eeb7fd56c546f718eaf70ecee63d2a6e
BLAKE2b-256 0a4b448b2315586cd47c372d46bf04e56929a9a4c936fc4979fad448360b454a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page