1-Questions raised
2-Logistic regression
3-Theoretical derivation
4-python/spark implementation
1 #-*-coding:utf-8-*-2 fromPysparkImportSparkcontext3 fromMathImport*4 5theta = [0, 0, 0]#Initial theta Value6Alpha = 0.001#Learning Rate7 8 definner (x, y):9 returnSUM ([i*j forI,jinchzip (x, y)])Ten One deffunc (LST): AH = (1 + exp (-inner (LST, theta))) * * (-1) - returnMapLambdax: (H-lst[-1]) * x, Lst[:-1]) - the -sc = Sparkcontext ('Local') - -Rdd = Sc.textfile ('/home/freyr/logisticregression.txt') +. Map (LambdaLine:map (float, Line.strip (). Split (','))) -. Map (LambdaLST: [1]+lst) + A at forIinchRange (400): -Partheta =Rdd.map (func) -. Reduce (LambdaX, y: [i+j forI,jinchzip (x, y)]) - - forJinchRange (3): -THETA[J] = theta[j]-Alpha *Partheta[j] in - Print 'theta =%s'% Theta
PS:logisticRegression.txt
Distributed implementation of logistic regression [logistic regression/machine Learning/spark]