Skip to content

Commit

Permalink
example changes so they convert to notebooks better
Browse files Browse the repository at this point in the history
  • Loading branch information
pberkland committed Apr 15, 2016
1 parent 1f285f2 commit a64ae21
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/


var run = function(sc){
function run(sc){

sc.parallelize([1, 2, 3, 4]).foreach(function(x, accum) {
accum.add(x);
Expand Down
14 changes: 2 additions & 12 deletions examples/mllib/fp_growth_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,10 @@ function run(sc, useTake) {
check if SparkContext is defined, if it is we are being run from Unit Test
*/
var inputFile = ((typeof args !== "undefined") && (args.length > 1)) ? args[1] : "examples/data/mllib/sample_fpgrowth.txt";
var minSupport = 0.3;
var numPartition = -1;
var minSupport = ((typeof args !== "undefined") && (args.length > 2)) ? parseFloat(args[2]) :0.3;
var numPartition = ((typeof args !== "undefined") && (args.length > 3)) ? parseInt(args[3]) : -1;

if (typeof sparkContext === 'undefined') {
if (args.length >= 2) {
inputFile = args[1];
}

if (args.length >= 3) {
minSupport = parseFloat(args[2]);
}
if (args.length >= 4) {
numPartition = parseInt(args[3]);
}

var sparkConf = new SparkConf().setAppName("FPGrowthExample");
var sc = new SparkContext(sparkConf);
Expand Down
4 changes: 2 additions & 2 deletions examples/mllib/power_iteration_clustering_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ if (typeof sparkContext === 'undefined') {

var sparkConf = new SparkConf().setAppName("PowerIterationClusteringExample");
var sc = new SparkContext(sparkConf);
var results = run(sc);
results.forEach(function(a){
var result = run(sc);
result.forEach(function(a){
print(a.id() + " -> " + a.cluster());
});

Expand Down
4 changes: 2 additions & 2 deletions examples/mllib/prefix_span_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ if (typeof sparkContext === 'undefined') {

var sparkConf = new SparkConf().setAppName("PrefixSpanExample");
var sc = new SparkContext(sparkConf);
var results = run(sc);
results.forEach(function (freqSeq) {
var result = run(sc);
result.forEach(function (freqSeq) {
print(JSON.stringify(freqSeq.sequence()) + ", " + freqSeq.freq());
});

Expand Down
6 changes: 3 additions & 3 deletions examples/mllib/recommendation_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ if (typeof sparkContext === 'undefined') {

var sparkConf = new SparkConf().setAppName("Collaborative Filtering Example");
var sc = new SparkContext(sparkConf);
var results = run(sc);
print("Mean Squared Error = " + results.MSE);
var result = run(sc);
print("Mean Squared Error = " + result.MSE);
// Save and load model
results.model.save(sc, "target/tmp/myCollaborativeFilter");
result.model.save(sc, "target/tmp/myCollaborativeFilter");
var sameModel = MatrixFactorizationModel.load(sc,
"target/tmp/myCollaborativeFilter");

Expand Down
8 changes: 4 additions & 4 deletions examples/mllib/svd_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ if (typeof sparkContext === 'undefined') {

var sparkConf = new SparkConf().setAppName("SVD Example");
var sc = new SparkContext(sparkConf);
var results = run(sc);
var result = run(sc);
print("U factor is:");
results.collectPartitions.forEach(function (vector) {
result.collectPartitions.forEach(function (vector) {
print("\t" + vector);
});
print("Singular values are: " + results.s);
print("V factor is:\n" + results.V);
print("Singular values are: " + result.s);
print("V factor is:\n" + result.V);

sc.stop();
}
Expand Down
6 changes: 3 additions & 3 deletions examples/mllib/svm_with_sgd_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ if (typeof sparkContext === 'undefined') {

var sparkConf = new SparkConf().setAppName("SVMWithSGDExample");
var sc = new SparkContext(sparkConf);
var results = run(sc);
print("Area under ROC = " + results.auROC);
var result = run(sc);
print("Area under ROC = " + result.auROC);

// Save and load model
results.model.save(sc, "target/tmp/SVMWithSGDModel");
result.model.save(sc, "target/tmp/SVMWithSGDModel");
var sameModel = SVMModel.load(sc, "target/tmp/SVMWithSGDModel");

sc.stop();
Expand Down
17 changes: 6 additions & 11 deletions examples/spark_lr.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,18 @@
bin/eclairjs.sh examples/spark_lr.js"
*/

function showWarning() {
var warning = "WARN: This is a naive implementation of Logistic Regression " +
"and is given as an example!\n" +
"Please use either org.apache.spark.mllib.classification.LogisticRegressionWithSGD " +
"or org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS " +
"for more conventional use.";
print(warning);
}
/* WARNING: This is a naive implementation of Logistic Regression
and is given as an example!
Please use either org.apache.spark.mllib.classification.LogisticRegressionWithSGD
or org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS
for more conventional use.
*/

function printWeights(a) {
print(a);
}


showWarning();


var D = 10; // Number of dimensions

var file = (args.length > 1) ? args[1] : "./examples/data/lr_data.txt";
Expand Down

0 comments on commit a64ae21

Please sign in to comment.