用Spark-Scala训练LightGBM模型

Spark构建生产级用户流失预测Pipeline实战 用户流失预测是典型的业务驱动型机器学习任务,其核心不在算法本身,而在于特征工程的稳定性、标签定义的业务对齐性,以及端到端pipeline的可追溯与可重现能力。基于Spark DataFrame的全链路处理,能天然保障计算口径一致性、分区裁剪效率和Delta Lake版本管理能力;而pandas UDF结合LightGBM的推理架构,则在模型表达力与工程可控性之间取得关键平衡。该方案已广泛应用于电信、SaaS与金融行业,支撑千万级用户日更特征、百维以上业务可解释特征、Top-K Lift等可行动指标交付。本文 阅读详情

  今日表情 ???? 

Spark-scala 可以使用LightGBM模型,既可以进行分布式训练,也可以进行分布式预测,支持各种参数设置。

支持模型保存,并且保存后的模型和Python等语言是可以相互调用的。

需要注意的是,Spark-scala训练LightGBM模型时, 输入模型的训练数据集需要处理成一个DataFrame,用spark.ml.feature.VectorAssembler将多列特征转换成一个 features向量列,label作为另外一列。

一,环境配置

spark-scala要使用lightgbm模型,pom文件中要配置如下依赖。

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_${scala.version}</artifactId>
<version>${spark.version}</version>
<!--spark-ml要去掉pmml-model依赖-->
<exclusions>
    <exclusion>
        <groupId>org.jpmml</groupId>
        <artifactId>pmml-model</artifactId>
    </exclusion>
</exclusions>
</dependency>

<dependency>
    <groupId>org.jpmml</groupId>
    <artifactId>jpmml-sparkml</artifactId>
    <version>1.3.4</version>
</dependency>
<dependency>
    <groupId>org.jpmml</groupId>
    <artifactId>jpmml-lightgbm</artifactId>
    <version>1.3.4</version>
</dependency>

二,范例代码

下面我们以二分类问题为例,按照如下几个大家熟悉的步骤进行范例代码演示。

  • 1,准备数据

  • 2,定义模型

  • 3,训练模型

  • 4,评估模型

  • 5,使用模型

  • 6,保存模型

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.types.{DoubleType, StringType, StructField, StructType, IntegerType}
import org.apache.spark.ml.Pipeline
import org.apache.spark.ml.evaluation.BinaryClassificationEvaluator
import org.apache.spark.ml.evaluation.MulticlassClassificationEvaluator
import org.apache.spark.ml.linalg.Vector
import org.apache.spark.ml.feature.VectorAssembler
import org.apache.spark.ml.attribute.Attribute
import org.apache.spark.ml.feature.{IndexToString, StringIndexer}
import com.microsoft.ml.spark.{lightgbm=>lgb}
import com.google.gson.{JsonObject, JsonParser}
import scala.collection.JavaConverters._

object LgbDemo extends Serializable {
    
    def printlog(info:String): Unit ={
        val dt = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date)
        println("=========="*8+dt)
        println(info+"\n")
    }
    
    def main(args:Array[String]):Unit= {


    /*================================================================================*/
    //  一,加载数据
    /*================================================================================*/
    printlog("step1: preparing data ...")

    //加载数据
    val spark = SparkSession.builder().getOrCreate()
    val dfdata_raw = spark.read.option("header","true")
        .option("delimiter", "\t")
        .option("inferschema", "true")
        .option("nullValue","")
        .csv("data/breast_cancer.csv")

    dfdata_raw.sample(false,0.1,1).printSchema 

    //将特征组合成features向量
    val feature_cols = dfdata_raw.columns.filter(!Array("label").contains(_)) 
    val cate_cols = Array("mean_radius","mean_texture") 


    val vectorAssembler = new VectorAssembler().
      setInputCols(feature_cols).
      setOutputCol("features")

    val dfdata = vectorAssembler.transform(dfdata_raw).select("features", "label")
    val Array(dftrain,dfval)  = dfdata.randomSplit(Array(0.7, .3), 666)

    //各个特征的名字存储在了schema 的 metadata中了, 所以可以用特征名指定类别特征 
    println(dfdata.schema("features").metadata)
    dfdata.show(10) 

    /*================================================================================*/
    //  二,定义模型
    /*================================================================================*/
    printlog("step2: defining model ...")

    val lgbclassifier = new lgb.LightGBMClassifier()
      .setNumIterations(100)
      .setLearningRate(0.1)
      .setNumLeaves(31)
      .setMinSumHessianInLeaf(0.001)
      .setMaxDepth(-1)
      .setBoostFromAverage(false)
      .setFeatureFraction(1.0)
      .setMaxBin(255)
      .setLambdaL1(0.0)
      .setLambdaL2(0.0)
      .setBaggingFraction(1.0)
      .setBaggingFreq(0)
      .setBaggingSeed(1)
      .setBoostingType("gbdt") //rf、dart、goss
      .setCategoricalSlotNames(cate_cols)
      .setObjective("binary") //binary, multiclass
      .setFeaturesCol("features") 
      .setLabelCol("label")

    println(lgbclassifier.explainParams) 


    /*================================================================================*/
    //  三,训练模型
    /*================================================================================*/
    printlog("step3: training model ...")

    val lgbmodel = lgbclassifier.fit(dftrain)

    val feature_importances = lgbmodel.getFeatureImportances("gain")
    val arr = feature_cols.zip(feature_importances).sortBy[Double](t=> -t._2)
    val dfimportance = spark.createDataFrame(arr).toDF("feature_name","feature_importance(gain)")

    dfimportance.show(100)


    /*================================================================================*/
    //  四,评估模型
    /*================================================================================*/
    printlog("step4: evaluating model ...")

    val evaluator = new BinaryClassificationEvaluator()
      .setLabelCol("label")
      .setRawPredictionCol("rawPrediction")
      .setMetricName("areaUnderROC")

    val dftrain_result = lgbmodel.transform(dftrain)
    val dfval_result = lgbmodel.transform(dfval)

    val train_auc  = evaluator.evaluate(dftrain_result)
    val val_auc = evaluator.evaluate(dfval_result)
    println(s"train_auc = ${train_auc}")
    println(s"val_auc = ${val_auc}")


    /*================================================================================*/
    //  五,使用模型
    /*================================================================================*/
    printlog("step5: using model ...")

    //批量预测
    val dfpredict = lgbmodel.transform(dfval)
    dfpredict.sample(false,0.1,1).show(20)

    //对单个样本进行预测
    val features = dfval.head().getAs[Vector]("features")
    val single_result = lgbmodel.predict(features)

    println(single_result)


    /*================================================================================*/
    //  六,保存模型
    /*================================================================================*/
    printlog("step6: saving model ...")

    //保存到集群,多文件
    lgbmodel.write.overwrite().save("lgbmodel.model")
    //加载集群模型
    println("load model ...")
    val lgbmodel_loaded = lgb.LightGBMClassificationModel.load("lgbmodel.model")
    val dfresult = lgbmodel_loaded.transform(dfval)
    dfresult.show() 

    //保存到本地,单文件,和Python接口兼容
    //lgbmodel.saveNativeModel("lgb_model",true)
    //加载本地模型
    //val lgbmodel_loaded = LightGBMClassificationModel.loadNativeModelFromFile("lgb_model")
    
    }
    
}


三,输出参考

运行如上代码之后,可以得到如下输出。

注意 println(lgbclassifier.explainParams)可以获取LightGBM模型各个参数的含义以及默认值。

================================================================================2021-07-17 22:16:29
step1: preparing data ...

root
 |-- mean_radius: integer (nullable = true)
 |-- mean_texture: integer (nullable = true)
 |-- mean_perimeter: double (nullable = true)
 |-- mean_area: double (nullable = true)
 |-- mean_smoothness: double (nullable = true)
 |-- mean_compactness: double (nullable = true)
 |-- mean_concavity: double (nullable = true)
 |-- mean_concave_points: double (nullable = true)
 |-- mean_symmetry: double (nullable = true)
 |-- mean_fractal_dimension: double (nullable = true)
 |-- radius_error: double (nullable = true)
 |-- texture_error: double (nullable = true)
 |-- perimeter_error: double (nullable = true)
 |-- area_error: double (nullable = true)
 |-- smoothness_error: double (nullable = true)
 |-- compactness_error: double (nullable = true)
 |-- concavity_error: double (nullable = true)
 |-- concave_points_error: double (nullable = true)
 |-- symmetry_error: double (nullable = true)
 |-- fractal_dimension_error: double (nullable = true)
 |-- worst_radius: double (nullable = true)
 |-- worst_texture: double (nullable = true)
 |-- worst_perimeter: double (nullable = true)
 |-- worst_area: double (nullable = true)
 |-- worst_smoothness: double (nullable = true)
 |-- worst_compactness: double (nullable = true)
 |-- worst_concavity: double (nullable = true)
 |-- worst_concave_points: double (nullable = true)
 |-- worst_symmetry: double (nullable = true)
 |-- worst_fractal_dimension: double (nullable = true)
 |-- label: integer (nullable = true)

{"ml_attr":{"attrs":{"numeric":[{"idx":0,"name":"mean_radius"},{"idx":1,"name":"mean_texture"},{"idx":2,"name":"mean_perimeter"},{"idx":3,"name":"mean_area"},{"idx":4,"name":"mean_smoothness"},{"idx":5,"name":"mean_compactness"},{"idx":6,"name":"mean_concavity"},{"idx":7,"name":"mean_concave_points"},{"idx":8,"name":"mean_symmetry"},{"idx":9,"name":"mean_fractal_dimension"},{"idx":10,"name":"radius_error"},{"idx":11,"name":"texture_error"},{"idx":12,"name":"perimeter_error"},{"idx":13,"name":"area_error"},{"idx":14,"name":"smoothness_error"},{"idx":15,"name":"compactness_error"},{"idx":16,"name":"concavity_error"},{"idx":17,"name":"concave_points_error"},{"idx":18,"name":"symmetry_error"},{"idx":19,"name":"fractal_dimension_error"},{"idx":20,"name":"worst_radius"},{"idx":21,"name":"worst_texture"},{"idx":22,"name":"worst_perimeter"},{"idx":23,"name":"worst_area"},{"idx":24,"name":"worst_smoothness"},{"idx":25,"name":"worst_compactness"},{"idx":26,"name":"worst_concavity"},{"idx":27,"name":"worst_concave_points"},{"idx":28,"name":"worst_symmetry"},{"idx":29,"name":"worst_fractal_dimension"}]},"num_attrs":30}}
+--------------------+-----+
|            features|label|
+--------------------+-----+
|[17.0,10.0,122.8,...|    0|
|[20.0,17.0,132.9,...|    0|
|[19.0,21.0,130.0,...|    0|
|[11.0,20.0,77.58,...|    0|
|[20.0,14.0,135.1,...|    0|
|[12.0,15.0,82.57,...|    0|
|[18.0,19.0,119.6,...|    0|
|[13.0,20.0,90.2,5...|    0|
|[13.0,21.0,87.5,5...|    0|
|[12.0,24.0,83.97,...|    0|
+--------------------+-----+
only showing top 10 rows

================================================================================2021-07-17 22:16:29
step2: defining model ...

baggingFraction: Bagging fraction (default: 1.0, current: 1.0)
baggingFreq: Bagging frequency (default: 0, current: 0)
baggingSeed: Bagging seed (default: 3, current: 1)
boostFromAverage: Adjusts initial score to the mean of labels for faster convergence (default: true, current: false)
boostingType: Default gbdt = traditional Gradient Boosting Decision Tree. Options are: gbdt, gbrt, rf (Random Forest), random_forest, dart (Dropouts meet Multiple Additive Regression Trees), goss (Gradient-based One-Side Sampling).  (default: gbdt, current: gbdt)
categoricalSlotIndexes: List of categorical column indexes, the slot index in the features column (undefined)
categoricalSlotNames: List of categorical column slot names, the slot name in the features column (current: [Ljava.lang.String;@351fb3fc)
defaultListenPort: The default listen port on executors, used for testing (default: 12400)
earlyStoppingRound: Early stopping round (default: 0)
featureFraction: Feature fraction (default: 1.0, current: 1.0)
featuresCol: features column name (default: features, current: features)
initScoreCol: The name of the initial score column, used for continued training (undefined)
isProvideTrainingMetric: Whether output metric result over training dataset. (default: false)
isUnbalance: Set to true if training data is unbalanced in binary classification scenario (default: false)
labelCol: label column name (default: label, current: label)
lambdaL1: L1 regularization (default: 0.0, current: 0.0)
lambdaL2: L2 regularization (default: 0.0, current: 0.0)
learningRate: Learning rate or shrinkage rate (default: 0.1, current: 0.1)
maxBin: Max bin (default: 255, current: 255)
maxDepth: Max depth (default: -1, current: -1)
minSumHessianInLeaf: Minimal sum hessian in one leaf (default: 0.001, current: 0.001)
modelString: LightGBM model to retrain (default: )
numBatches: If greater than 0, splits data into separate batches during training (default: 0)
numIterations: Number of iterations, LightGBM constructs num_class * num_iterations trees (default: 100, current: 100)
numLeaves: Number of leaves (default: 31, current: 31)
objective: The Objective. For regression applications, this can be: regression_l2, regression_l1, huber, fair, poisson, quantile, mape, gamma or tweedie. For classification applications, this can be: binary, multiclass, or multiclassova.  (default: binary, current: binary)
parallelism: Tree learner parallelism, can be set to data_parallel or voting_parallel (default: data_parallel)
predictionCol: prediction column name (default: prediction)
probabilityCol: Column name for predicted class conditional probabilities. Note: Not all models output well-calibrated probability estimates! These probabilities should be treated as confidences, not precise probabilities (default: probability)
rawPredictionCol: raw prediction (a.k.a. confidence) column name (default: rawPrediction)
thresholds: Thresholds in multi-class classification to adjust the probability of predicting each class. Array must have length equal to the number of classes, with values > 0 excepting that at most one value may be 0. The class with largest value p/t is predicted, where p is the original probability of that class and t is the class's threshold (undefined)
timeout: Timeout in seconds (default: 1200.0)
useBarrierExecutionMode: Use new barrier execution mode in Beta testing, off by default. (default: false)
validationIndicatorCol: Indicates whether the row is for training or validation (undefined)
verbosity: Verbosity where lt 0 is Fatal, eq 0 is Error, eq 1 is Info, gt 1 is Debug (default: 1)
weightCol: The name of the weight column (undefined)
================================================================================2021-07-17 22:16:29
step3: training model ...

+--------------------+------------------------+
|        feature_name|feature_importance(gain)|
+--------------------+------------------------+
|          worst_area|       974.9349449056517|
|     worst_perimeter|       885.3691593843923|
|worst_concave_points|      255.67364284247745|
| mean_concave_points|      250.21955942230738|
|       worst_texture|      151.07745621304454|
|          area_error|       65.75557372416814|
|    worst_smoothness|       62.29973236144293|
|     mean_smoothness|      19.902610011957194|
|        worst_radius|        16.8275272153341|
|           mean_area|       12.41261211467938|
|      mean_perimeter|      12.127510878875537|
|     worst_concavity|      11.414242858900646|
|   compactness_error|      10.996194651604892|
|        mean_texture|       9.274276675339683|
|     concavity_error|       8.009578698471008|
|      symmetry_error|        7.93458393366217|
|        radius_error|       7.357747321194173|
|      worst_symmetry|       5.951699663755868|
|fractal_dimension...|       4.811246624133022|
|concave_points_error|        4.73140145466917|
|   worst_compactness|       4.469820723182832|
|       texture_error|       4.356178728700959|
|    mean_compactness|       3.123736411467967|
|       mean_symmetry|      1.9968633063354835|
|      mean_concavity|      1.9701941942285224|
|    smoothness_error|       1.673042485476758|
|worst_fractal_dim...|      1.3582115541525612|
|mean_fractal_dime...|      0.6050912755332459|
|     perimeter_error|      0.3889888676278275|
|         mean_radius|    5.684356116234315...|
+--------------------+------------------------+

================================================================================2021-07-17 22:16:30
step4: evaluating model ...

train_auc = 1.0
val_auc = 0.9890340267698758
================================================================================2021-07-17 22:16:31
step5: using model ...

+--------------------+-----+--------------------+--------------------+----------+
|            features|label|       rawPrediction|         probability|prediction|
+--------------------+-----+--------------------+--------------------+----------+
|[9.0,12.0,60.34,2...|    1|[-10.570726382467...|[-9.5707263824679...|       1.0|
|[10.0,16.0,65.85,...|    1|[-10.120435089856...|[-9.1204350898567...|       1.0|
|[10.0,21.0,68.51,...|    1|[-8.8020346337692...|[-7.8020346337692...|       1.0|
|[11.0,14.0,73.53,...|    1|[-10.315758226759...|[-9.3157582267596...|       1.0|
|[11.0,15.0,73.38,...|    1|[-10.086077130817...|[-9.0860771308174...|       1.0|
|[11.0,16.0,74.72,...|    1|[-6.9649803118554...|[-5.9649803118554...|       1.0|
|[11.0,17.0,71.25,...|    1|[-10.694667171248...|[-9.6946671712481...|       1.0|
|[11.0,17.0,75.27,...|    1|[-9.0156792680894...|[-8.0156792680894...|       1.0|
|[11.0,18.0,75.17,...|    1|[-5.7513546284621...|[-4.7513546284621...|       1.0|
|[11.0,18.0,76.38,...|    1|[-4.3134421808792...|[-3.3134421808792...|       1.0|
|[12.0,15.0,82.57,...|    0|[2.49310942805160...|[3.49310942805160...|       0.0|
|[12.0,17.0,78.27,...|    1|[-10.516042459712...|[-9.5160424597122...|       1.0|
|[12.0,18.0,83.19,...|    1|[-9.4899850168431...|[-8.4899850168431...|       1.0|
|[12.0,22.0,78.75,...|    1|[-8.9917629958319...|[-7.9917629958319...|       1.0|
|[14.0,15.0,92.68,...|    1|[-7.2724968676775...|[-6.2724968676775...|       1.0|
|[14.0,15.0,95.77,...|    1|[-5.0143190624015...|[-4.0143190624015...|       1.0|
|[14.0,16.0,96.22,...|    1|[-5.3849620427583...|[-4.3849620427583...|       1.0|
|[14.0,19.0,97.83,...|    1|[-3.3292007261919...|[-2.3292007261919...|       1.0|
|[16.0,14.0,104.3,...|    1|[4.66077729134426...|[5.66077729134426...|       0.0|
|[19.0,24.0,122.0,...|    0|[10.1503565558166...|[11.1503565558166...|       0.0|
+--------------------+-----+--------------------+--------------------+----------+

1.0
================================================================================2021-07-17 22:16:31
step6: saving model ...

load model ...


收工。????

本文Spark-scala 使用 LightGBM 模型训练 二分类模型 代码和数据集,以及训练 多分类模型 和 回归模型 的范例代码和数据集,可以在公众号算法美食屋后台回复关键词 spark+lightgbm 获取。

万水千山总是情,点个在看行不行?????

猜你喜欢❤️

30分钟学会LightGBM

银行客户分群实战:规则驱动+Spark Scala落地六类业务标签 客户分群是金融数据分析的核心基础能力,其本质是将海量客户按行为、价值与风险特征进行可解释、可执行的结构化划分。原理上需兼顾统计规律性与业务可追溯性,避免黑盒模型带来的监管与协作障碍;技术价值体现在支撑精准营销、流失预警与产品推荐等关键动作,显著提升ROI与合规性;典型应用场景包括信用卡分期名单筛选、理财客户触达及高风险客户干预。本文基于真实银行项目,详解如何用Spark SQL宽表构建、Scala规则引擎与RFLM生命周期模型,实现六类可运营客户分群——不依赖AI平台,直连BI与营销中台,强调可解释性、稳定 阅读详情

相关推荐

PySpark集成XGBoost实战:跨范式分布式训练全链路指南

XGBoost作为高性能梯度提升树模型,其单机设计与Spark分布式计算范式存在本质冲突——核心在于共享内存依赖、全局直方图构建与参数同步机制的不兼容。理解这一原理差异,是解决分布式训练OOM、特征维度错配、AllReduce超时等工程问题的前提。技术价值体现在真正支持千节点规模下的端到端可复现训练,完整保留XGBoost原生参数与正则能力;典型应用场景包括金融风控、电商推荐等需高精度AUC与可解释特征重要性的超大规模离线任务。本文聚焦xgboost4j-spark在PySpark生态中的落地实践,覆盖版本

xpmwgcwm的博客 380

[机器学习] LightGBM on Spark (MMLSpark) 使用完全手册

一 Spark上训练模型优势与劣势 (1)机器学习算法一般都有很多个步骤迭代计算的过程,机器学习的计算需要在多次迭代后获得足够小的误差或者足够收敛才会停止,迭代时如果使用一般的Hadoop分布式计算框架,每次计算都要读 / 写磁盘以及任务的启动等工作,这回导致非常大的 I/O 和 CPU 消耗。而 Spark 基于内存的计算模型天生就擅长迭代计算,多个步骤计算直接在内存中完成. (2)从通信的角度讲,如果使用 Hadoop分布式计算框架, 工作和任务之间由于是通过 heartbeat 的方式来进行的通信

摩登都市天空---专栏 1万+

PySpark机器学习实战:构建可部署的分布式训练Pipeline

分布式机器学习是处理海量数据的核心能力,其本质是将单机算法扩展至集群环境,通过数据并行与计算调度实现性能线性提升。技术价值在于保障模型训练的稳定性、可复现性与工程可控性,支撑实时风控、用户流失预测、推荐系统等高要求场景。关键挑战包括特征工程一致性、跨环境模型部署、资源瓶颈定位及生产级监控。本文聚焦PySpark ML(pyspark.ml)这一主流接口,深入解析Pipeline设计范式与DataFrame原生API协同机制,结合Parquet优化、CrossValidator调参、MLeap模型导出等实操要

cumian9828的博客 643

基于Spark框架实现LightGBM模型

原生的Spark MLlib并不支持LightGBM算法的实现,但SynapseML提供了一种解决方案,使得我们可以在Spark中调用LightGBM。LightGBM是一种基于梯度提升决策树的高效机器学习框架,它专门用于创建高质量的决策树算法,适用于分类、回归和排名等多种机器学习任务。通过SynapseML,LightGBM可以与Spark MLlib无缝集成,利用Spark的分布式计算能力,实现对大规模数据集的高效处理。高性能:LightGBM以其快速的训练速度和低内存消耗而闻名,这使得它在处理大规模数

LUyan10086的博客 1176

Synapse ML统一接口:构建可扩展的机器学习流水线

机器学习流水线(ML Pipeline)是实现模型工程化落地的核心范式,其本质是将数据预处理、特征工程、模型训练、评估与部署等环节封装为可复用、可版本化、可跨环境执行的声明式工作流。Synapse ML通过统一Python API抽象,屏蔽底层计算引擎(如Spark、LightGBM、ONNX Runtime)差异,实现单接口定义、多环境运行;其Massively Scalable特性依托Spark DataFrame惰性求值与分布式算法设计,支持从本地调试到EB级数据的平滑扩展。该方案显著降低ML工程师在

dengjuanshou7445的博客 385

spark 使用 LightGBM 原理解析

LightGBM于2016年10月17日发布,是微软分布式机器学习工具包(DMTK)项目的一部分。它快速且分布式的设计使得训练速度更快且内存使用率更低。它具有支持GPU、采用并行学习以及能够处理大型数据集等能力。LightGBM 在多个基准测试和公共数据集实验中甚至比 XGBoost 更快,更准确。

shiter编写程序的艺术 1228

Scala 版

启动spark shell 加载 jar 包 spark-shell --jars mmlspark-0.12.jar,lightgbmlib-2.0.120.jar traning model # 导入算法包 import com.microsoft.ml.spark.LightGBMClassifier val lgbm = new LightGBMClassifier().setLabe...

baidu_20457783的博客 487

第13课:Spark 分布式模型训练及调优(原理)

本节课程为大家介绍 Deeplearning4j 在 Apache Spark 上构建分布式深度学习模型的方式与底层机制。本节课的核心内容包括: Apache Spark 简介 深度学习的并行与分布式建模 Deeplearning4j 是原生支持在 Spark 上建模的开源库之一,同样原生支持的还有 Intel BigDL、SparkNet、H2O 等。像 Caffe 和 TensorFlow...

万宫玺的专栏 796

SparkML -- LightGBM On Spark 导出pmml示例

向导MAVEN测试数据代码示例,以二分类为例结果 MAVEN <dependency> <groupId>org.jpmml</groupId> <artifactId>jpmml-sparkml</artifactId> <version>1.5.0</version> <!-- ...

TheBigBlue的博客 1288

第14课:Spark 分布式模型训练及调优(实战)

上节课已经为大家介绍了 Apache Spark 项目的基本情况,以及分布式深度神经网络的解决方案。这节课我们将给出一个 Deeplearning4j+Spark 的建模实例,包括从配置 Maven 工程开始到本地的原型验证,以及集群上的模型训练。由于 ND4J 的张量运算是通过 JavaCPP 技术,诸如 OpenBLAS 开源库来调用实现的,因此我们也将就内存的调优进行介绍。下面我们首先介绍下...

万宫玺的专栏 1967

scala导出pmml模型报错:Caused by: java.lang.IllegalArgumentException: Expected org.apache.spark.ml.Transfor

🏆本文收录于专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家!持续更新中,up!up!up!!

**My Coding Family** 932

python训练模型_Java读取python训练的模型

Java读取python训练的模型package com.hikvision.tpse.mml.scalaimport com.microsoft.ml.spark.lightgbm.LightGBMClassificationModelimport org.apache.arrow.vector.types.pojo.ArrowType.Structimport org.apache.spark...

weixin_39955142的博客 366

Hadoop+Spark大数据金融信贷风控系统设计与实现

大数据技术正在重塑金融风控的业务流程,其中分布式存储与内存计算是支撑海量数据处理的基石。Hadoop提供了可靠的分布式存储能力,Spark则通过高效的迭代计算加速数据清洗、特征工程与模型训练。在信贷场景中,从原始数据到风险评分,再到审批决策,需要一条完整的技术链路来保证业务闭环。本文从技术概念与原理出发,深入探讨Hadoop与Spark在金融风控中的分工协作,涵盖数据仓库分层、特征处理、逻辑回归模型构建及可视化展示,并给出版本兼容、性能调优等工程实践要点,帮助读者构建一套可解释、可扩展的信贷风控系统。

weixin_30954265的博客 334

Synapse ML:用Spark DataFrame统一AI工程化流水线

Apache Spark 作为成熟的大数据处理引擎,其核心价值在于分布式计算与SQL/DataFrame抽象的统一性。当机器学习工程面临多框架胶水代码、跨系统数据搬运和模型服务割裂等典型痛点时,AI工程化亟需一种能深度融入现有数据栈的轻量级集成范式。Synapse ML 正是这一需求的实践答案——它不替代Scikit-learn或PyTorch,而是将各类AI能力(如ONNX模型、LightGBM、认知服务)封装为Spark原生Transformer算子,实现predict()调用与filter()/joi

cuili5839的博客 319

保姆级教程:在摩尔线程MTT S80上快速部署Ollama运行DeepSeek R1模型(附性能测试)

本文提供了一份详细的保姆级教程,指导用户在摩尔线程MTT S80显卡上部署Ollama并运行DeepSeek R1模型。内容涵盖从驱动安装、Docker环境配置到模型拉取、性能测试的全流程,并分享了实测数据与优化技巧,旨在帮助开发者快速在国产GPU平台上实现高效的大语言模型推理。

weixin_29091837的博客 529

模拟滤波器的基础知识和设计

使用Python实现多种模拟滤波器

faltas的博客 3531

微软为Apache Spark改造了机器学习工具

根据项目存储库上的注释,Microsoft对其MMLSpark开源项目进行了改进,可以更好地将“许多深度学习和数据科学工具集成到Spark生态系统中”。 MMLSpark最初发布于去年,它是一个项目集合,旨在使Spark在许多情况下(主要是机器学习以及某些通用方式)更加有用。 [InfoWorld的要点: 什么是Apache Spark? 大数据分析平台介绍了以下内容 • Sp...

cxw9087的博客 109

【AUTOSAR-COM】Transmission Mode 和 Transfer Property

1.COM模块的基本概念 首先在描述Transmission Mode 和 Transfer Property之前,有必要对COM模块的基本处理有一个直观的理解,我所描述的和对概念理解的也不一定完全正确。 Signal:指的是通信协议中的,一条报文中所保存的若干信号。 I-PDU:至少在COM模块中,可以理解为一条报文。 上图是在CANdb软件中编辑一个报文的Layout的界面,可以很形象的将I-PDU对等为这里的一条Message,而Signal就是需要在Message中需要摆放的Signal

tim_hoven的博客 4637

apache spark_微软为Apache Spark改造了机器学习工具

apache spark 根据项目存储库上的注释,Microsoft对其MMLSpark开源项目进行了改进,可以更好地将“许多深度学习和数据科学工具集成到Spark生态系统中”。 MMLSpark最初发布于去年,它是一个项目集合,旨在使Spark在许多情况下(主要是机器学习以及某些通用方式)更加有用。 [InfoWorld的要点: 什么是Apache Spark? 大数据分析平台...

cxw9087的博客 93

rv1126平台spi屏调试

st7789v2 i2c调试

zuoanyouzhuan_的博客 2039

携程机票数据爬取实战:使用 Python 获取携程网机票信息

通过本篇博客,我们详细介绍了如何使用 Python 爬取携程网的机票信息,涉及了静态网页爬取(使用 Requests 和 BeautifulSoup)和动态网页爬取(使用 Selenium)两种方法。通过获取的数据,我们不仅能够进行票价分析,还可以构建更为复杂的预测模型或趋势分析工具。爬虫技术不仅能够帮助我们收集有价值的数据,还能够为商业决策提供数据支持。在实际应用中,我们可以结合更多的分析方法,如自然语言处理、图像处理等,进一步提升数据的价值。

2201_76125261的博客 1658

java使用joblib模型_机器学习模型线上部署感受

目前存在的几种模型上线的方式1、R+pmml+spark+airflow调度其他团队用R语言训练模型并转为pmml文件,然后我们使用spark将这个pmml文件封装为jar,使用airflow提交到yarn。val is: InputStream = fs.open(path)val pmml: PMML = PMMLUtil.unmarshal(is)modelEvaluator = Mode...

weixin_39585617的博客 579

如何对TBSS的结果进行统计学的分析,已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析??

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值。

**My Coding Family** 1442
上一篇: 中国88个超500万人口的大中城市都在哪里?Python动态图告诉你!
下一篇: 魔都上海4日旅游攻略?Python动态图告诉你!
算法美食屋
博客等级 码龄9年 2万+粉丝 154原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值