| { |
| "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 SystemML jar file and configure kernel\n", |
| " \n", |
| "Please visit http://systemml.apache.org/install-systemml.html site to know \"How to configure Toree(Scala) Kernel\".\n", |
| " \n", |
| "### This notebook is supported with SystemML 0.14.0 and above." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "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": null, |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "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", |
| "\n", |
| "val script = dml(sumScript).out(\"outMatrix\")\n", |
| "val out = ml.execute(script)\n", |
| "val outMatrix = out.getDataFrame(\"outMatrix\")" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Display the output" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "outMatrix.show" |
| ] |
| } |
| ], |
| "metadata": { |
| "kernelspec": { |
| "display_name": "Apache Toree - Scala", |
| "language": "scala", |
| "name": "apache_toree_scala" |
| }, |
| "language_info": { |
| "file_extension": ".scala", |
| "name": "scala", |
| "version": "2.11.8" |
| } |
| }, |
| "nbformat": 4, |
| "nbformat_minor": 1 |
| } |