Repository: incubator-systemml Updated Branches: refs/heads/master 93ada6291 -> 16ccfa057
[SYSTEMML-1606] Update notebook samples with latest code Updated few sample notebooks to support both Python 2.x and Python 3.x Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/16ccfa05 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/16ccfa05 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/16ccfa05 Branch: refs/heads/master Commit: 16ccfa0571d5a69c2e22ea2c6c1463102849d59c Parents: 93ada62 Author: Arvind Surve <ac...@yahoo.com> Authored: Tue May 23 11:08:36 2017 -0700 Committer: Arvind Surve <ac...@yahoo.com> Committed: Tue May 23 11:08:36 2017 -0700 ---------------------------------------------------------------------- samples/jupyter-notebooks/Autoencoder.ipynb | 31 +++++++++++++++----- .../Deep_Learning_Image_Classification.ipynb | 29 +++++++++--------- .../Linear_Regression_Algorithms_Demo.ipynb | 14 ++++----- .../SystemML-PySpark-Recommendation-Demo.ipynb | 18 ++++++++---- 4 files changed, 58 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/16ccfa05/samples/jupyter-notebooks/Autoencoder.ipynb ---------------------------------------------------------------------- diff --git a/samples/jupyter-notebooks/Autoencoder.ipynb b/samples/jupyter-notebooks/Autoencoder.ipynb index e69ca9c..dd5d265 100644 --- a/samples/jupyter-notebooks/Autoencoder.ipynb +++ b/samples/jupyter-notebooks/Autoencoder.ipynb @@ -18,7 +18,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "!pip show systemml" @@ -27,7 +29,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import pandas as pd\n", @@ -67,10 +71,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ - "X_pd = pd.DataFrame(range(1, 2001,1),dtype=float).values.reshape(100,20)\n", + "import numpy as np\n", + "X_pd = pd.DataFrame(np.arange(1,2001, dtype=np.float)).values.reshape(100,20)\n", + "# X_pd = pd.DataFrame(range(1, 2001,1),dtype=float).values.reshape(100,20)\n", "script =\"\"\"\n", " write(X, $Xfile)\n", "\"\"\"\n", @@ -81,7 +89,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "!ls -l /tmp/data/Input" @@ -90,7 +100,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "autoencoderURL = \"https://raw.githubusercontent.com/apache/incubator-systemml/master/scripts/staging/autoencoder-2layer.dml\"\n", @@ -110,7 +122,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "!ls -l /tmp/data/Output" @@ -127,6 +141,7 @@ "cell_type": "code", "execution_count": null, "metadata": { + "collapsed": true, "scrolled": true }, "outputs": [], @@ -163,7 +178,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.13" } }, "nbformat": 4, http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/16ccfa05/samples/jupyter-notebooks/Deep_Learning_Image_Classification.ipynb ---------------------------------------------------------------------- diff --git a/samples/jupyter-notebooks/Deep_Learning_Image_Classification.ipynb b/samples/jupyter-notebooks/Deep_Learning_Image_Classification.ipynb index 996c5d0..3124028 100644 --- a/samples/jupyter-notebooks/Deep_Learning_Image_Classification.ipynb +++ b/samples/jupyter-notebooks/Deep_Learning_Image_Classification.ipynb @@ -55,9 +55,9 @@ "\n", "ml = MLContext(sc)\n", "\n", - "print \"Spark Version:\", sc.version\n", - "print \"SystemML Version:\", ml.version()\n", - "print \"SystemML Built-Time:\", ml.buildTime()" + "print (\"Spark Version:\" + sc.version)\n", + "print (\"SystemML Version:\" + ml.version())\n", + "print (\"SystemML Built-Time:\" + ml.buildTime())" ] }, { @@ -120,18 +120,18 @@ "source": [ "mnist = datasets.fetch_mldata(\"MNIST Original\")\n", "\n", - "print \"Mnist data features:\", mnist.data.shape\n", - "print \"Mnist data label:\", mnist.target.shape\n", + "print (\"Mnist data features:\" + str(mnist.data.shape))\n", + "print (\"Mnist data label:\" + str(mnist.target.shape))\n", "\n", "trainX, testX, trainY, testY = train_test_split(mnist.data, mnist.target.astype(\"int0\"), test_size = 0.142857)\n", "\n", "trainD = np.concatenate((trainY.reshape(trainY.size, 1), trainX),axis=1)\n", "testD = np.concatenate((testY.reshape (testY.size, 1), testX),axis=1)\n", "\n", - "print \"Images for training:\", trainD.shape\n", - "print \"Images used for testing:\", testD.shape\n", + "print (\"Images for training:\" + str(trainD.shape))\n", + "print (\"Images used for testing:\" + str(testD.shape))\n", "pix = int(np.sqrt(trainD.shape[1]))\n", - "print \"Each image is:\", pix, \"by\", pix, \"pixels\"\n", + "print (\"Each image is: \" + str(pix) + \" by \" + str(pix) + \" pixels\")\n", "\n", "np.savetxt('data/mnist/mnist_train.csv', trainD, fmt='%u', delimiter=\",\")\n", "np.savetxt('data/mnist/mnist_test.csv', testD, fmt='%u', delimiter=\",\")" @@ -175,8 +175,8 @@ "trainData = np.genfromtxt('data/mnist/mnist_train.csv', delimiter=\",\")\n", "testData = np.genfromtxt('data/mnist/mnist_test.csv', delimiter=\",\")\n", "\n", - "print \"Training data: \", trainData.shape\n", - "print \"Test data: \", testData.shape" + "print (\"Training data: \" + str(trainData.shape))\n", + "print (\"Test data: \" + str(testData.shape))" ] }, { @@ -308,7 +308,7 @@ "\n", "predictions = ml.execute(script).get(\"predictions\").toNumPy()\n", "\n", - "print classification_report(testData[:,0], predictions)" + "print (classification_report(testData[:,0], predictions))" ] }, { @@ -334,7 +334,7 @@ }, "outputs": [], "source": [ - "img_size = np.sqrt(testData.shape[1] - 1)\n", + "img_size = int(np.sqrt(testData.shape[1] - 1))\n", "\n", "def displayImage(i):\n", " image = (testData[i,1:]).reshape((img_size, img_size)).astype(\"uint8\")\n", @@ -369,8 +369,9 @@ "\n", "p = predictImage(i)\n", "\n", - "print \"Image\", i, \"\\nPredicted digit:\", p, \"\\nActual digit: \", testData[i,0], \"\\nResult: \", (p == testData[i,0])\n", + "print (\"Image \" + str(i) + \"\\nPredicted digit: \" + str(p) + \"\\nActual digit: \" + str(testData[i,0]) + \"\\nResult: \" + str(p == testData[i,0]))\n", "\n", + "p\n", "displayImage(i)" ] }, @@ -401,7 +402,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.13" } }, "nbformat": 4, http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/16ccfa05/samples/jupyter-notebooks/Linear_Regression_Algorithms_Demo.ipynb ---------------------------------------------------------------------- diff --git a/samples/jupyter-notebooks/Linear_Regression_Algorithms_Demo.ipynb b/samples/jupyter-notebooks/Linear_Regression_Algorithms_Demo.ipynb index 77843ad..3e22757 100644 --- a/samples/jupyter-notebooks/Linear_Regression_Algorithms_Demo.ipynb +++ b/samples/jupyter-notebooks/Linear_Regression_Algorithms_Demo.ipynb @@ -58,9 +58,9 @@ "\n", "ml = MLContext(sc)\n", "\n", - "print \"Spark Version:\", sc.version\n", - "print \"SystemML Version:\", ml.version()\n", - "print \"SystemML Built-Time:\", ml.buildTime()" + "print (\"Spark Version:\" + sc.version)\n", + "print (\"SystemML Version:\" + ml.version())\n", + "print (\"SystemML Built-Time:\"+ ml.buildTime())" ] }, { @@ -138,7 +138,7 @@ "source": [ "prog = dml(script).input('$nr', 1e5).output('s')\n", "s = ml.execute(prog).get('s')\n", - "print s" + "print (s)" ] }, { @@ -171,7 +171,7 @@ "source": [ "prog = dml(script).input('$nr', 1e6).output('s')\n", "out = ml.execute(prog).get('s')\n", - "print out" + "print (out)" ] }, { @@ -496,7 +496,7 @@ "w = ml.execute(prog).get('beta_out')\n", "w = w.toNumPy()\n", "bias=w[1]\n", - "print bias" + "print (bias)" ] }, { @@ -591,7 +591,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.13" } }, "nbformat": 4, http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/16ccfa05/samples/jupyter-notebooks/SystemML-PySpark-Recommendation-Demo.ipynb ---------------------------------------------------------------------- diff --git a/samples/jupyter-notebooks/SystemML-PySpark-Recommendation-Demo.ipynb b/samples/jupyter-notebooks/SystemML-PySpark-Recommendation-Demo.ipynb index f51ef6c..84e2e66 100644 --- a/samples/jupyter-notebooks/SystemML-PySpark-Recommendation-Demo.ipynb +++ b/samples/jupyter-notebooks/SystemML-PySpark-Recommendation-Demo.ipynb @@ -24,7 +24,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "!pip show systemml" @@ -58,7 +60,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%%sh\n", @@ -70,7 +74,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# Load data\n", @@ -165,7 +171,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# Plot training loss over time\n", @@ -194,7 +202,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.13" } }, "nbformat": 4,