| { |
| "cells": [ |
| { |
| "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" |
| ] |
| } |
| ], |
| "source": [ |
| "%AddJar https://sparktc.ibmcloud.com/repo/latest/SystemML.jar" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 5, |
| "metadata": { |
| "collapsed": false |
| }, |
| "outputs": [], |
| "source": [ |
| "import org.apache.sysml.api.MLContext" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 6, |
| "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", |
| "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\")" |
| ] |
| }, |
| { |
| "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" |
| ] |
| } |
| ], |
| "source": [ |
| "outMatrix.show" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [] |
| } |
| ], |
| "metadata": { |
| "kernelspec": { |
| "display_name": "Scala 2.10", |
| "language": "scala", |
| "name": "spark" |
| }, |
| "language_info": { |
| "name": "scala" |
| } |
| }, |
| "nbformat": 4, |
| "nbformat_minor": 0 |
| } |