"""
Classification in Spark
@author: Chris Mantas
@contact: the1pro@gmail.com
@since: Created on 2016-02-12
@todo: custom formats, break up big lines
@license: http://www.apache.org/licenses/LICENSE-2.0 Apache License
"""

from pyspark.mllib.classification import \
    LogisticRegressionWithLBFGS, LogisticRegressionModel
from imr_tools import *
from pyspark import SparkContext
from argparse import ArgumentParser
from os import system

# ==================== Global Vars ============================ #
_INTERCEPT = True
_REGULARIZATION = None


# ====================  Helper Functions ====================== #

def train_model(training_rdd, **kwargs):
    """
    Train a classifier model using  an rdd training dataset
    :param training_rdd: the rdd of the training dataset
    :param kwargs: additional key-value params for the training (if any)
    :return:
    """
    return LogisticRegressionWithLBFGS.train(training_rdd,
                                             regType=_REGULARIZATION,
                                             intercept=_INTERCEPT,
                                             **kwargs)


def get_cli_args():
    """
    Defines the command-line arguments, parses the input and returns a
    namespace object with the parameters given by the user
    :return:
    """