예제 #1
0
    def predict(self, conf):
        """
        Run linear regression predict task
        :param conf: configuration of algorithm and resource
        :return:
        """
        conf.set_int("angel.worker.matrix.transfer.request.timeout.ms", 60000)
        conf.set(
            AngelConf.ANGEL_TASK_USER_TASKCLASS,
            'com.tencent.angel.ml.regression.linear.LinearRegPredictTask')

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create a model
        model = conf._jvm.com.tencent.angel.ml.regression.linear.LinearRegModel(
            conf._jconf)

        # Add the model meta to client
        client.loadModel(model)

        # Run user task
        client.runTask(
            'com.tencent.angel.ml.regression.linear.LinearRegPredictTask')

        # Wait for completion,
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Stop
        client.stop()
예제 #2
0
    def train(self, conf):
        """
        Training job to obtain a model
        :param conf: configuration for parameter settings
        """
        conf.set(AngelConf.ANGEL_TASK_USER_TASKCLASS,
                 'com.tencent.angel.ml.matrixfactorization.MFTrainTask')

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create a MFModel
        mfModel = conf._jvm.com.tencent.angel.ml.matrixfactorization.MFModel(
            conf._jconf, None)

        # Load model meta to client
        client.loadModel(mfModel)

        # Start
        client.runTask('com.tencent.angel.ml.matrixfactorization.MFTrainTask')

        # Run user task and wait for completion
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Save the trained model to HDFS
        client.saveModel(mfModel)

        # Stop
        client.stop()
예제 #3
0
    def fm_classification(self):
        input_path = "./src/test/data/fm/a9a.train"
        LOCAL_FS = LocalFileSystem.DEFAULT_FS
        TMP_PATH = tempfile.gettempdir()
        save_path = LOCAL_FS + TMP_PATH + "/model"
        log_path = LOCAL_FS + TMP_PATH + "/LRlog"

        # Set trainning data path
        self.conf.set(AngelConf.ANGEL_TRAIN_DATA_PATH, input_path)
        # Set save model path
        self.conf.set(AngelConf.ANGEL_SAVE_MODEL_PATH, save_path)
        # Set log path
        self.conf.set(AngelConf.ANGEL_LOG_PATH, log_path)
        # Set actionType train
        self.conf.set(AngelConf.ANGEL_ACTION_TYPE, MLConf.ANGEL_ML_TRAIN)
        # Set learnType
        self.conf.set(MLConf.ML_FM_LEARN_TYPE, "c")
        # Set feature number
        self.conf.set(MLConf.ML_FEATURE_NUM, str(124))

        runner = FMRunner()
        runner.train(self.conf)

        angel_client = AngelClientFactory.get(self.conf)
        angel_client.stop()
예제 #4
0
파일: k_means.py 프로젝트: youmingwei/angel
    def train(self, conf):
        conf.set(AngelConf.ANGEL_TASK_USER_TASKCLASS, 'com.tencent.angel.ml.clustering.kmeans.KMeansTrainTask')

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create a KMeans model
        kmeansModel = conf._jvm.com.tencent.angel.ml.clustering.kmeans.KMeansModel(conf._jconf, None)

        # Load model meta to client
        client.loadModel(kmeansModel)

        # Start
        client.runTask('com.tencent.angel.ml.clustering.kmeans.KMeansTrainTask')

        # Run user task and wait for completion,
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Save the trained model to HDFS
        client.saveModel(kmeansModel)

        # Stop
        client.stop()
예제 #5
0
파일: k_means.py 프로젝트: youmingwei/angel
    def predict(self, conf):
        """
        Using a model to predict with unobserved samples
        """
        conf.set_int("angel.worker.matrix.transfer.request.timeout.ms", 60000)
        conf.set(AngelConf.ANGEL_TASK_USER_TASKCLASS, 'com.tencent.angel.ml.clustering.kmeans.KMeansPredictTask')

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create KMeans model
        model = conf._jvm.com.tencent.angel.ml.clustering.kmeans.KMeansModel(conf._jconf, None)

        # Add the model meta to client
        client.loadModel(model)

        # Start
        client.runTask('com.tencent.angel.ml.clustering.kmeans.KMeansPredictTask')

        # Run user task and wait for completion,
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Stop
        client.stop()
예제 #6
0
파일: runner.py 프로젝트: zzanswer/angel
    def inc_train(self, conf):
        """
        Run incremental train task
        :param conf: configuration of aalgorithm and resource
        :return:
        """
        conf['angel.worker.matrix.transfer.request.timeout.ms'] = 60000
        conf[AngelConf.ANGEL_TASK_USER_TASKCLASS] = 'com.tencent.angel.ml.regression.linear.LinearRegTrainTask'

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create a model
        model = conf._jvm.com.tencent.angel.ml.regression.linear.LinearRegModel(conf._jconf)

        # Load model meta to client
        client.loadModel(model)

        # Run user task
        client.runTask('com.tencent.angel.ml.regression.linear.LinearRegTrainTask')

        # Wait for completion,
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Save the incremental trained model to HDFS
        client.saveModel(model)

        # Stop
        client.stop()
예제 #7
0
파일: k_means.py 프로젝트: x-hacker/angel
    def train(self, conf):
        conf.set(AngelConf.ANGEL_TASK_USER_TASKCLASS,
                 'com.tencent.angel.ml.clustering.kmeans.KMeansTrainTask')

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create a KMeans model
        kmeansModel = conf._jvm.com.tencent.angel.ml.clustering.kmeans.KMeansModel(
            conf._jconf, None)

        # Load model meta to client
        client.loadModel(kmeansModel)

        # Start
        client.runTask(
            'com.tencent.angel.ml.clustering.kmeans.KMeansTrainTask')

        # Run user task and wait for completion,
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Save the trained model to HDFS
        client.saveModel(kmeansModel)

        # Stop
        client.stop()
예제 #8
0
    def fm_classification(self):
        input_path = "./src/test/data/fm/a9a.train"
        LOCAL_FS = LocalFileSystem.DEFAULT_FS
        TMP_PATH = tempfile.gettempdir()
        save_path = LOCAL_FS + TMP_PATH + "/model"
        log_path = LOCAL_FS + TMP_PATH + "/LRlog"

        # Set trainning data path
        self.conf.set(AngelConf.ANGEL_TRAIN_DATA_PATH, input_path)
        # Set save model path
        self.conf.set(AngelConf.ANGEL_SAVE_MODEL_PATH, save_path)
        # Set log path
        self.conf.set(AngelConf.ANGEL_LOG_PATH, log_path)
        # Set actionType train
        self.conf.set(AngelConf.ANGEL_ACTION_TYPE, MLConf.ANGEL_ML_TRAIN)
        # Set learnType
        self.conf.set(MLConf.ML_FM_LEARN_TYPE, "c")
        # Set feature number
        self.conf.set(MLConf.ML_FEATURE_NUM, str(124))

        runner = FMRunner()
        runner.train(self.conf)

        angel_client = AngelClientFactory.get(self.conf)
        angel_client.stop()
예제 #9
0
파일: k_means.py 프로젝트: x-hacker/angel
    def predict(self, conf):
        """
        Using a model to predict with unobserved samples
        """
        conf.set_int("angel.worker.matrix.transfer.request.timeout.ms", 60000)
        conf.set(AngelConf.ANGEL_TASK_USER_TASKCLASS,
                 'com.tencent.angel.ml.clustering.kmeans.KMeansPredictTask')

        # Create an angel job client
        client = AngelClientFactory.get(conf)

        # Submit this application
        client.startPSServer()

        # Create KMeans model
        model = conf._jvm.com.tencent.angel.ml.clustering.kmeans.KMeansModel(
            conf._jconf, None)

        # Add the model meta to client
        client.loadModel(model)

        # Start
        client.runTask(
            'com.tencent.angel.ml.clustering.kmeans.KMeansPredictTask')

        # Run user task and wait for completion,
        # User task is set in AngelConf.ANGEL_TASK_USER_TASKCLASS
        client.waitForCompletion()

        # Stop
        client.stop()
예제 #10
0
    def train(self, conf):
        client = AngelClientFactory.get(conf)

        model = conf._jvm.com.tencent.angel.ml.factorizationmachines.FMModel(conf._jconf, None)

        client.startPSServer()
        client.loadModel(model)
        client.runTask('com.tencent.angel.ml.factorizationmachines.FMTrainTask')
        client.waitForCompletion()
        client.saveModel(model)

        client.stop()
예제 #11
0
    def predict(self, dconf, model, class_name):
        """
        Default predict method with standard predcit process. Don't try to override this Method
        :param conf:
        :return:
        """
        jmap = Configuration._dict_to_jmap(dconf)
        client = AngelClientFactory.get(jmap)
        client.startPSServer()
        client.loadModel(model)
        client.runTask(class_name)
        client.waitForCompletion()

        client.stop()
예제 #12
0
    def train(self, conf):
        client = AngelClientFactory.get(conf)

        model = conf._jvm.com.tencent.angel.ml.factorizationmachines.FMModel(
            conf._jconf, None)

        client.startPSServer()
        client.loadModel(model)
        client.runTask(
            'com.tencent.angel.ml.factorizationmachines.FMTrainTask')
        client.waitForCompletion()
        client.saveModel(model)

        client.stop()
예제 #13
0
    def predict(self, dconf, model, class_name):
        """
        Default predict method with standard predcit process. Don't try to override this Method
        :param conf:
        :return:
        """
        jmap = Configuration._dict_to_jmap(dconf)
        client = AngelClientFactory.get(jmap)
        client.startPSServer()
        client.loadModel(model)
        client.runTask(class_name)
        client.waitForCompletion()

        client.stop()
예제 #14
0
    def predict_on_local_cluster(self):
        self.set_conf()
        LOCAL_FS = LocalFileSystem.DEFAULT_FS
        TMP_PATH = tempfile.gettempdir()
        # Set trainning data path
        self.conf[AngelConf.ANGEL_PREDICT_DATA_PATH] = input_path
        # Set load model path
        self.conf[AngelConf.ANGEL_LOAD_MODEL_PATH] = LOCAL_FS + TMP_PATH + "/model"
        # Set predict result path
        self.conf[AngelConf.ANGEL_PREDICT_PATH] = LOCAL_FS + TMP_PATH + "/predict"
        # Set actionType prediction
        self.conf[AngelConf.ANGEL_ACTION_TYPE] = MLConf.ANGEL_ML_PREDICT

        runner = KMeansRunner()
        runner.predict(self.conf)

        angel_client = AngelClientFactory.get(self.conf)
        angel_client.stop()
예제 #15
0
    def train(self, conf, model, class_name):
        """
        Default train method with standard training process. Don't Override this method
        :param conf: Configuration for angel application
        :param model: Data training model
        :param train_class: train task class name
        :return:
        """
        # Get Java HashMap instance which converted from a python dict
        jmap = conf.dict_to_jmap()
        client = AngelClientFactory.get(jmap, conf)

        client.startPSServer()
        client.loadModel(model)
        client.runTask(class_name)
        client.waitForCompletion()
        client.saveModel(model)

        client.stop()
예제 #16
0
    def train(self, conf, model, class_name):
        """
        Default train method with standard training process. Don't Override this method
        :param conf: Configuration for angel application
        :param model: Data training model
        :param train_class: train task class name
        :return:
        """
        # Get Java HashMap instance which converted from a python dict
        jmap = conf.dict_to_jmap()
        client = AngelClientFactory.get(jmap, conf)

        client.startPSServer()
        client.loadModel(model)
        client.runTask(class_name)
        client.waitForCompletion()
        client.saveModel(model)

        client.stop()
예제 #17
0
    def train(self):
        self.set_conf()
        input_path = "data/exampledata/clusteringLocalExampleData/iris"
        LOCAL_FS = LocalFileSystem.DEFAULT_FS
        TMP_PATH = tempfile.gettempdir()
        # Set trainning data path
        self.conf.set(AngelConf.ANGEL_TRAIN_DATA_PATH, input_path)
        # Set save model path
        self.conf.set(AngelConf.ANGEL_SAVE_MODEL_PATH,
                      LOCAL_FS + TMP_PATH + "/model")
        # Set log sava path
        self.conf.set(AngelConf.ANGEL_LOG_PATH,
                      LOCAL_FS + TMP_PATH + "/kmeansLog/log")
        # Set actionType train
        self.conf.set(AngelConf.ANGEL_ACTION_TYPE, MLConf.ANGEL_ML_TRAIN)

        runner = KMeansRunner()
        runner.train(self.conf)

        angel_client = AngelClientFactory.get(self.conf)
        angel_client.stop()
예제 #18
0
    def train_on_local_cluster(self):
        self.set_conf()
        input_path = "./src/test/data/fm/food_fm_libsvm"
        LOCAL_FS = LocalFileSystem.DEFAULT_FS
        TMP_PATH = tempfile.gettempdir()
        save_path = LOCAL_FS + TMP_PATH + "/model"
        log_path = LOCAL_FS + TMP_PATH + "/LRlog"

        # Set trainning data path
        self.conf.set(AngelConf.ANGEL_TRAIN_DATA_PATH, input_path)
        # Set save model path
        self.conf.set(AngelConf.ANGEL_SAVE_MODEL_PATH, save_path)
        # Set log path
        self.conf.set(AngelConf.ANGEL_LOG_PATH, log_path)
        # Set actionType train
        self.conf.set(AngelConf.ANGEL_ACTION_TYPE, MLConf.ANGEL_ML_TRAIN())

        runner = FMRunner()
        runner.train(self.conf)

        angel_client = AngelClientFactory.get(self.conf)
        angel_client.stop()
예제 #19
0
    def train_on_local_cluster(self):
        self.set_conf()
        input_path = "./src/test/data/fm/food_fm_libsvm"
        LOCAL_FS = LocalFileSystem.DEFAULT_FS
        TMP_PATH = tempfile.gettempdir()
        save_path = LOCAL_FS + TMP_PATH + "/model"
        log_path = LOCAL_FS + TMP_PATH + "/LRlog"

        # Set trainning data path
        self.conf.set(AngelConf.ANGEL_TRAIN_DATA_PATH, input_path)
        # Set save model path
        self.conf.set(AngelConf.ANGEL_SAVE_MODEL_PATH, save_path)
        # Set log path
        self.conf.set(AngelConf.ANGEL_LOG_PATH, log_path)
        # Set actionType train
        self.conf.set(AngelConf.ANGEL_ACTION_TYPE, MLConf.ANGEL_ML_TRAIN())

        runner = FMRunner()
        runner.train(self.conf)

        angel_client = AngelClientFactory.get(self.conf)
        angel_client.stop()