楼主: Lisrelchen
1167 0

[Case Study]Logistic Regression using Python, Scala and Java [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2015-11-16 00:12:46 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Python
  1. points = spark.textFile(...).map(parsePoint).cache()
  2. w = numpy.random.ranf(size = D) # current separating plane
  3. for i in range(ITERATIONS):
  4.     gradient = points.map(
  5.         lambda p: (1 / (1 + exp(-p.y*(w.dot(p.x)))) - 1) * p.y * p.x
  6.     ).reduce(lambda a, b: a + b)
  7.     w -= gradient
  8. print "Final separating plane: %s" % w
复制代码
Scala
  1. val points = spark.textFile(...).map(parsePoint).cache()
  2. var w = Vector.random(D) // current separating plane
  3. for (i <- 1 to ITERATIONS) {
  4.   val gradient = points.map(p =>
  5.     (1 / (1 + exp(-p.y*(w dot p.x))) - 1) * p.y * p.x
  6.   ).reduce(_ + _)
  7.   w -= gradient
  8. }
  9. println("Final separating plane: " + w)
复制代码
Java
  1. class ComputeGradient extends Function<DataPoint, Vector> {
  2.   private Vector w;
  3.   ComputeGradient(Vector w) { this.w = w; }
  4.   public Vector call(DataPoint p) {
  5.     return p.x.times(p.y * (1 / (1 + Math.exp(w.dot(p.x))) - 1));
  6.   }
  7. }

  8. JavaRDD<DataPoint> points = spark.textFile(...).map(new ParsePoint()).cache();
  9. Vector w = Vector.random(D); // current separating plane
  10. for (int i = 0; i < ITERATIONS; i++) {
  11.   Vector gradient = points.map(new ComputeGradient(w)).reduce(new AddVectors());
  12.   w = w.subtract(gradient);
  13. }
  14. System.out.println("Final separating plane: " + w);
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:regression Case study regressio logistic regress Java

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

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2026-1-8 05:38