Repository: incubator-systemml Updated Branches: refs/heads/master 98e0aa219 -> f29ea3090
[SYSTEMML-1606] Update notebook samples with latest code Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/f29ea309 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/f29ea309 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/f29ea309 Branch: refs/heads/master Commit: f29ea3090ea86a53eb75937f57ddbc53db629069 Parents: 98e0aa2 Author: Arvind Surve <[email protected]> Authored: Fri May 12 17:14:03 2017 -0700 Committer: Arvind Surve <[email protected]> Committed: Fri May 12 17:14:03 2017 -0700 ---------------------------------------------------------------------- samples/jupyter-notebooks/tutorial1.ipynb | 114 ++++++++++++------------- 1 file changed, 57 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f29ea309/samples/jupyter-notebooks/tutorial1.ipynb ---------------------------------------------------------------------- diff --git a/samples/jupyter-notebooks/tutorial1.ipynb b/samples/jupyter-notebooks/tutorial1.ipynb index 4cde8f8..6da2cee 100644 --- a/samples/jupyter-notebooks/tutorial1.ipynb +++ b/samples/jupyter-notebooks/tutorial1.ipynb @@ -1,103 +1,103 @@ { "cells": [ { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SystemML Scala tutorial \n", + "This tutorial includes simple example to run DML script and display output." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Install latest SystemML jar file." + ] + }, + { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Starting download from https://sparktc.ibmcloud.com/repo/latest/SystemML.jar\n", - "Finished download of SystemML.jar\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "%AddJar https://sparktc.ibmcloud.com/repo/latest/SystemML.jar" ] }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ - "import org.apache.sysml.api.MLContext" + "import org.apache.sysml.api.mlcontext.MLContext\n", + "import org.apache.sysml.api.mlcontext.ScriptFactory.dml\n", + "import org.apache.spark.sql.SparkSession\n", + "\n", + "val sparkSession = SparkSession.builder().master(\"local\").appName(\"Tutorial\").getOrCreate()\n", + "val ml = new MLContext(sparkSession)\n", + "\n", + "print (\"Spark Version: \" + sc.version)\n", + "print (\"\\nSystemML Version: \" + ml.version())\n", + "print (\"\\nBuild Time: \" + ml.buildTime())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Run the script" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ - "import org.apache.spark.sql.SQLContext\n", - "val sqlCtx = new SQLContext(sc)\n", - "val ml = new MLContext(sc)\n", - "val dml = \"\"\"\n", + "val sumScript = \"\"\"\n", "X = rand(rows=100, cols=10)\n", "sumX = sum(X)\n", "outMatrix = matrix(sumX, rows=1, cols=1)\n", "write(outMatrix, \" \", format=\"csv\")\n", "\"\"\"\n", - "ml.reset()\n", - "ml.registerOutput(\"outMatrix\")\n", - "val out = ml.executeScript(dml)\n", - "val outMatrix = out.getDF(sqlCtx, \"outMatrix\")" + "\n", + "val script = dml(sumScript).out(\"outMatrix\")\n", + "val out = ml.execute(script)\n", + "val outMatrix = out.getDataFrame(\"outMatrix\")" ] }, { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "+---+------------------+\n", - "| ID| C1|\n", - "+---+------------------+\n", - "|0.0|507.71224689601286|\n", - "+---+------------------+\n", - "\n" - ] - } - ], + "cell_type": "markdown", + "metadata": {}, "source": [ - "outMatrix.show" + "## Display the output" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "outMatrix.show" + ] } ], "metadata": { "kernelspec": { - "display_name": "Scala 2.10", + "display_name": "Apache Toree - Scala", "language": "scala", - "name": "spark" + "name": "apache_toree_scala" }, "language_info": { - "name": "scala" + "file_extension": ".scala", + "name": "scala", + "version": "2.11.8" } }, "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + "nbformat_minor": 1 +}
