楼主: ReneeBK
3318 26

【GitHub】Spark Scala Learning Note [推广有奖]

21
ReneeBK 发表于 2017-2-21 09:29:57
  1. Scaling

  2. Making features have approximately zero mean by replacing each field x with x-m, and values within an unit standard deviation by dividing the range of feature.+

  3. Import
  4. import org.apache.spark.mllib.feature.StandardScaler
  5. Code
  6. val scaler = new StandardScaler(withMean = true, withStd = true).fit(trainingSet.map(dp => dp.features))

  7. Scale the training and test set.
  8. val scaledTrainingSet = trainingSet.map(dp => new LabeledPoint(dp.label, scaler.transform(dp.features))).cache()
  9. val scaledTestSet = testSet.map(dp => new LabeledPoint(dp.label, scaler.transform(dp.features))).cache()
复制代码

22
ReneeBK 发表于 2017-2-21 09:30:58
  1. Training the Model

  2. Import
  3. import org.apache.spark.mllib.regression.LinearRegressionWithSGD
  4. Code

  5. val regression=new LinearRegressionWithSGD().setIntercept(true)
  6. regression.optimizer.setNumIterations(1000).setStepSize(0.1)

  7. //Let's create a model out of our training examples.
  8. val model=regression.run(scaledTrainingSet)
复制代码

23
franky_sas 发表于 2017-2-21 11:16:08
Thanks for sharing.

24
钱学森64 发表于 2017-2-21 12:38:04
谢谢分享

25
kkkm_db 发表于 2017-2-21 16:14:27
谢谢分享!

26
luangao 在职认证  发表于 2017-2-21 18:41:54 来自手机
ReneeBK 发表于 2017-2-21 07:35
**** 本内容被作者隐藏 ****
学习学习

27
钱学森64 发表于 2017-2-21 19:13:06
谢谢分享

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-5 19:16