r - how to predict the values in mllib -


hi new spark mllib.i have 1 r model.i trying same model spark mllib.here r model code.

r code.

delhi <- read.delim("uitrain.txt", na.strings = "")   delhi$lnprice <- log(delhi$price) heddel <- lm(lnprice ~ bedrooms+ bathrooms+ area) deltest <- read.delim("uitest.txt", na.strings = "")  predict (heddel, deltest) 

i trying same r code in spark mllib java.

sparkconf conf = new sparkconf().setappname("linear regression example"); javasparkcontext sc = new javasparkcontext(conf); string path = "uitrain.txt"; javardd<string> data = sc.textfile(path); javardd<labeledpoint> parseddata = data.map(   new function<string, labeledpoint>() {     public labeledpoint call(string line) {       string[] parts = line.split("\t");       string[] features = parts[1].split("\t");       double[] v = new double[features.length];       (int = 0; < features.length - 1; i++)         v[i] = double.parsedouble(features[i]);       return new labeledpoint(double.parsedouble(parts[0]), vectors.dense(v));     }   }   );  parseddata.cache();  // building model  string input = "uitrain.txt";  int data2 = "uitest.txt"; int numiterations = 100; final linearregressionmodel model =   linearregressionwithsgd.train(javardd.tordd(parseddata), data2);  // evaluate model on training examples , compute training error javardd<tuple2<double, double>> valuesandpreds = parseddata.map(   new function<labeledpoint, tuple2<double, double>>() {     public tuple2<double, double> call(labeledpoint point) {       double prediction = model.predict(point.features());       return new tuple2<double, double>(prediction, point.label());     }   } ); double mse = new javadoublerdd(valuesandpreds.map(   new function<tuple2<double, double>, object>() {     public object call(tuple2<double, double> pair) {       return math.pow(pair._1() - pair._2(), 2.0);     }   } ).rdd()).mean(); system.out.println("training mean squared error = " + mse); 

i getting error while building model.any appreciated.

i think error in data2 here:

final linearregressionmodelmodel=linearregressionwithsgd.train(javardd.tordd(parseddata), data2) 

the regression expecting number of iterations , instead receiving text,

 int data2 = "uitest.txt"; 

if not error edit , print error.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -