{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nRunning machine learning pipelines\n==================================\nLet's run a machine learning pipeline to the Iris dataset.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Importing the required packages\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nfrom pjml.data.communication.report import Report\nfrom pjml.data.evaluation.metric import Metric\nfrom pjml.data.flow.file import File\nfrom pjml.operator.pipeline import Pipeline\nfrom pjml.stream.expand.partition import Partition\nfrom pjml.stream.reduce.reduce import Reduce\nfrom pjml.stream.reduce.summ import Summ\nfrom pjml.stream.transform.map import Map\nfrom pjpy.modeling.supervised.classifier.svmc import SVMC\nfrom pjpy.processing.feature.reductor.pca import PCA\nfrom pjpy.processing.feature.scaler.minmax import MinMax\n\nnp.random.seed(0)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, we must create a pipeline.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pipe = Pipeline(\n    File(\"../data/iris.arff\"),\n    Partition(),\n    Map(MinMax(), PCA(), SVMC(), Metric()),\n    Summ(),\n    Reduce(),\n    Report(\"Mean S: $S\"),\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we will train our pipeline\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "res_train, res_test = pipe.dual_transform()\nprint(\"Train result: \", res_train)\nprint(\"test result: \", res_test)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}