py2/h2o_ray.py
def build_model(self, algo, training_frame, parameters, destination_frame=None, model_id=None,
    timeoutSecs=60, noPoll=False, **kwargs):

    if 'destination_key' in kwargs:
        raise Exception('Change destination_key in build_model() to model_id')

    '''
    Build a model on the h2o cluster using the given algorithm, training 
    Frame and model parameters.
    '''
    assert algo is not None, '"algo" parameter is null'
    assert training_frame is not None, '"training_frame" parameter is null'
    assert parameters is not None, '"parameters" parameter is null'

    # why always check that the algo is in here?
    model_builders = self.model_builders(timeoutSecs=timeoutSecs)
    assert model_builders is not None, "/ModelBuilders REST call failed"
    assert algo in model_builders['model_builders'], "%s %s" % (algo, [k for k in model_builders['model_builders']])
    builder = model_builders['model_builders'][algo]
    
    # TODO: test this assert, I don't think this is working. . .
    frames = self.frames(key=training_frame)
    assert frames is not None, "/Frames/{0} REST call failed".format(training_frame)

    key_name = frames['frames'][0]['frame_id']['name'] 
    assert key_name==training_frame, \
        "/Frames/{0} returned Frame {1} rather than Frame {2}".format(training_frame, key_name, training_frame)
    parameters['training_frame'] = training_frame

    if destination_frame is not None:
        print "destination_frame should be replaced by model_id now"
        parameters['model_id'] = destination_frame

    if model_id is not None:
        parameters['model_id'] = model_id

    print "build_model parameters", parameters
    start = time.time()
    result1 = self.do_json_request('/3/ModelBuilders.json/' + algo, cmd='post', 
        timeout=timeoutSecs, postData=parameters)
    # make get overwritten after polling
    elapsed = time.time() - start
    verboseprint("build_model result", dump_json(result1))
      
    if noPoll:
        result = result1
    elif ('validation_error_count' in result1) and (result1['validation_error_count']>0):
        h2p.yellow_print("parameter error in model_builders: %s" % result1)
        # parameters validation failure
        # TODO: add schema_type and schema_version into all the schemas to make this clean to check
        result = result1
        # don't bother printing a time message
    elif 'exception_msg' in result1:
        h2p.yellow_print("exception msg in model_builders: %s" % result1['exception_msg'])
        result = result1
    else:
        job_result = result1['job']
        job_key = job_result['key']['name']
        verboseprint("build_model job_key: " + repr(job_key))

        job_result = self.poll_job(job_key, timeoutSecs=timeoutSecs)
        verboseprint(job_result)

        elapsed = time.time() - start
        print "ModelBuilders", algo,  "end on", training_frame, 'took', time.time() - start, 'seconds'
        print "%d pct. of timeout" % ((elapsed/timeoutSecs) * 100)

        if job_result:
            jobs = job_result['jobs'][0]
            description = jobs['description']
            dest = jobs['dest']
            msec = jobs['msec']
            status = jobs['status']
            progress = jobs['progress']

            # can condition this with a parameter if some FAILED are expected by tests.
            if status=='FAILED':
                print dump_json(job_result)
                raise Exception("Taking exception on build_model job status: %s %s %s %s" % \
                    (status, progress, msec, description))

            result = job_result
        else:
            # ? we should always get a job_json result
            raise Exception("build_model didn't get a job_result when it expected one")
            # return None

    verboseprint("result:", result)
    h2o_sandbox.check_sandbox_for_errors()
    result['python_elapsed'] = elapsed
    return result
def build_model(self, algo, training_frame, parameters, destination_frame=None, model_id=None,
    timeoutSecs=60, noPoll=False, **kwargs):

    if 'destination_key' in kwargs:
        raise Exception('Change destination_key in build_model() to model_id')

    '''
    Build a model on the h2o cluster using the given algorithm, training 
    Frame and model parameters.
    '''
    assert algo is not None, '"algo" parameter is null'
    assert training_frame is not None, '"training_frame" parameter is null'
    assert parameters is not None, '"parameters" parameter is null'

    # why always check that the algo is in here?
    model_builders = self.model_builders(timeoutSecs=timeoutSecs)
    assert model_builders is not None, "/ModelBuilders REST call failed"
    assert algo in model_builders['model_builders'], "%s %s" % (algo, [k for k in model_builders['model_builders']])
    builder = model_builders['model_builders'][algo]
    
    # TODO: test this assert, I don't think this is working. . .
    frames = self.frames(key=training_frame)
    assert frames is not None, "/Frames/{0} REST call failed".format(training_frame)

    key_name = frames['frames'][0]['frame_id']['name'] 
    assert key_name==training_frame, \
        "/Frames/{0} returned Frame {1} rather than Frame {2}".format(training_frame, key_name, training_frame)
    parameters['training_frame'] = training_frame

    if destination_frame is not None:
        print "destination_frame should be replaced by model_id now"
        parameters['model_id'] = destination_frame

    if model_id is not None:
        parameters['model_id'] = model_id

    print "build_model parameters", parameters
    start = time.time()
    result1 = self.do_json_request('/3/ModelBuilders.json/' + algo, cmd='post', 
        timeout=timeoutSecs, postData=parameters)
    # make get overwritten after polling
    elapsed = time.time() - start
    verboseprint("build_model result", dump_json(result1))
      
    if noPoll:
        result = result1
    elif ('validation_error_count' in result1) and (result1['validation_error_count']>0):
        h2p.yellow_print("parameter error in model_builders: %s" % result1)
        # parameters validation failure
        # TODO: add schema_type and schema_version into all the schemas to make this clean to check
        result = result1
        # don't bother printing a time message
    elif 'exception_msg' in result1:
        h2p.yellow_print("exception msg in model_builders: %s" % result1['exception_msg'])
        result = result1
    else:
        job_result = result1['job']
        job_key = job_result['key']['name']
        verboseprint("build_model job_key: " + repr(job_key))

        job_result = self.poll_job(job_key, timeoutSecs=timeoutSecs)
        verboseprint(job_result)

        elapsed = time.time() - start
        print "ModelBuilders", algo,  "end on", training_frame, 'took', time.time() - start, 'seconds'
        print "%d pct. of timeout" % ((elapsed/timeoutSecs) * 100)

        if job_result:
            jobs = job_result['jobs'][0]
            description = jobs['description']
            dest = jobs['dest']
            msec = jobs['msec']
            status = jobs['status']
            progress = jobs['progress']

            # can condition this with a parameter if some FAILED are expected by tests.
            if status=='FAILED':
                print dump_json(job_result)
                raise Exception("Taking exception on build_model job status: %s %s %s %s" % \
                    (status, progress, msec, description))

            result = job_result
        else:
            # ? we should always get a job_json result
            raise Exception("build_model didn't get a job_result when it expected one")
            # return None

    verboseprint("result:", result)
    h2o_sandbox.check_sandbox_for_errors()
    result['python_elapsed'] = elapsed
    return result
def build_model ( self , algo , training_frame , parameters , destination_frame = None , model_id = None , timeoutSecs = 60 , noPoll = False , * * kwargs ) : if 'destination_key' in kwargs : raise Exception ( 'Change destination_key in build_model() to model_id' ) assert algo is not None , '"algo" parameter is null' assert training_frame is not None , '"training_frame" parameter is null' assert parameters is not None , '"parameters" parameter is null' # why always check that the algo is in here? model_builders = self . model_builders ( timeoutSecs = timeoutSecs ) assert model_builders is not None , "/ModelBuilders REST call failed" assert algo in model_builders [ 'model_builders' ] , "%s %s" % ( algo , [ k for k in model_builders [ 'model_builders' ] ] ) builder = model_builders [ 'model_builders' ] [ algo ] # TODO: test this assert, I don't think this is working. . . frames = self . frames ( key = training_frame ) assert frames is not None , "/Frames/{0} REST call failed" . format ( training_frame ) key_name = frames [ 'frames' ] [ 0 ] [ 'frame_id' ] [ 'name' ] assert key_name == training_frame , "/Frames/{0} returned Frame {1} rather than Frame {2}" . format ( training_frame , key_name , training_frame ) parameters [ 'training_frame' ] = training_frame if destination_frame is not None : print "destination_frame should be replaced by model_id now" parameters [ 'model_id' ] = destination_frame if model_id is not None : parameters [ 'model_id' ] = model_id print "build_model parameters" , parameters start = time . time ( ) result1 = self . do_json_request ( '/3/ModelBuilders.json/' + algo , cmd = 'post' , timeout = timeoutSecs , postData = parameters ) # make get overwritten after polling elapsed = time . time ( ) - start verboseprint ( "build_model result" , dump_json ( result1 ) ) if noPoll : result = result1 elif ( 'validation_error_count' in result1 ) and ( result1 [ 'validation_error_count' ] > 0 ) : h2p . yellow_print ( "parameter error in model_builders: %s" % result1 ) # parameters validation failure # TODO: add schema_type and schema_version into all the schemas to make this clean to check result = result1 # don't bother printing a time message elif 'exception_msg' in result1 : h2p . yellow_print ( "exception msg in model_builders: %s" % result1 [ 'exception_msg' ] ) result = result1 else : job_result = result1 [ 'job' ] job_key = job_result [ 'key' ] [ 'name' ] verboseprint ( "build_model job_key: " + repr ( job_key ) ) job_result = self . poll_job ( job_key , timeoutSecs = timeoutSecs ) verboseprint ( job_result ) elapsed = time . time ( ) - start print "ModelBuilders" , algo , "end on" , training_frame , 'took' , time . time ( ) - start , 'seconds' print "%d pct. of timeout" % ( ( elapsed / timeoutSecs ) * 100 ) if job_result : jobs = job_result [ 'jobs' ] [ 0 ] description = jobs [ 'description' ] dest = jobs [ 'dest' ] msec = jobs [ 'msec' ] status = jobs [ 'status' ] progress = jobs [ 'progress' ] # can condition this with a parameter if some FAILED are expected by tests. if status == 'FAILED' : print dump_json ( job_result ) raise Exception ( "Taking exception on build_model job status: %s %s %s %s" % ( status , progress , msec , description ) ) result = job_result else : # ? we should always get a job_json result raise Exception ( "build_model didn't get a job_result when it expected one" ) # return None verboseprint ( "result:" , result ) h2o_sandbox . check_sandbox_for_errors ( ) result [ 'python_elapsed' ] = elapsed return result
Build a model on the h2o cluster using the given algorithm, training 
    Frame and model parameters.
Build a model on the h2o cluster using the given algorithm training Frame and model parameters .