def get_model(model_id): """ Return the specified model :param model_id: The model identification in h2o """ model_json = H2OConnection.get_json("Models/" + model_id)["models"][0] model_type = model_json["output"]["model_category"] if model_type == "Binomial": from model.binomial import H2OBinomialModel model = H2OBinomialModel(model_id, model_json) elif model_type == "Clustering": from model.clustering import H2OClusteringModel model = H2OClusteringModel(model_id, model_json) elif model_type == "Regression": from model.regression import H2ORegressionModel model = H2ORegressionModel(model_id, model_json) elif model_type == "Multinomial": from model.multinomial import H2OMultinomialModel model = H2OMultinomialModel(model_id, model_json) elif model_type == "AutoEncoder": from model.autoencoder import H2OAutoEncoderModel model = H2OAutoEncoderModel(model_id, model_json) else: print model_type raise NotImplementedError return model
def _resolve_model(future_model, **kwargs): future_model.poll() if '_rest_version' in kwargs.keys(): model_json = H2OConnection.get_json( "Models/" + future_model.job.dest_key, _rest_version=kwargs['_rest_version'])["models"][0] else: model_json = H2OConnection.get_json( "Models/" + future_model.job.dest_key)["models"][0] model_type = model_json["output"]["model_category"] if model_type == "Binomial": model = H2OBinomialModel(future_model.job.dest_key, model_json) elif model_type == "Clustering": model = H2OClusteringModel(future_model.job.dest_key, model_json) elif model_type == "Regression": model = H2ORegressionModel(future_model.job.dest_key, model_json) elif model_type == "Multinomial": model = H2OMultinomialModel(future_model.job.dest_key, model_json) elif model_type == "AutoEncoder": model = H2OAutoEncoderModel(future_model.job.dest_key, model_json) elif model_type == "DimReduction": model = H2ODimReductionModel(future_model.job.dest_key, model_json) else: raise NotImplementedError(model_type) return model
def _model_build(x,y,validation_x,validation_y,algo_url,kwargs): # Basic sanity checking if algo_url == "autoencoder": if "autoencoder" in kwargs.keys(): if kwargs["autoencoder"]: if y: raise ValueError("`y` should not be specified for autoencoder, remove `y` input.") algo_url="deeplearning" if not x: raise ValueError("Missing features") x = _check_frame(x,y,y) if validation_x: validation_x = _check_frame(validation_x,validation_y,y) # Send frame descriptions to H2O cluster train_key = x.send_frame() kwargs['training_frame']=train_key if validation_x is not None: valid_key = validation_x.send_frame() kwargs['validation_frame']=valid_key if y: kwargs['response_column']=y._name kwargs = dict([(k, kwargs[k]) for k in kwargs if kwargs[k] is not None]) # launch the job and poll job = H2OJob(H2OConnection.post_json("ModelBuilders/"+algo_url, **kwargs), job_type=(algo_url+" Model Build")).poll() model_json = H2OConnection.get_json("Models/"+job.dest_key)["models"][0] model_type = model_json["output"]["model_category"] if model_type=="Binomial": from model.binomial import H2OBinomialModel model = H2OBinomialModel(job.dest_key,model_json) elif model_type=="Clustering": from model.clustering import H2OClusteringModel model = H2OClusteringModel(job.dest_key,model_json) elif model_type=="Regression": from model.regression import H2ORegressionModel model = H2ORegressionModel(job.dest_key,model_json) elif model_type=="Multinomial": from model.multinomial import H2OMultinomialModel model = H2OMultinomialModel(job.dest_key,model_json) elif model_type=="AutoEncoder": from model.autoencoder import H2OAutoEncoderModel model = H2OAutoEncoderModel(job.dest_key,model_json) else: print model_type raise NotImplementedError # Cleanup h2o.remove(train_key) if validation_x: h2o.remove(valid_key) return model
def _resolve_model(future_model, **kwargs): future_model.poll() # Wait for model-building to be complete if '_rest_version' in kwargs.keys(): model_json = H2OConnection.get_json( "Models/" + future_model.job.dest_key, _rest_version=kwargs['_rest_version'])["models"][0] else: model_json = H2OConnection.get_json( "Models/" + future_model.job.dest_key)["models"][0] model_type = model_json["output"]["model_category"] if model_type == "Binomial": from model.binomial import H2OBinomialModel model = H2OBinomialModel(future_model.job.dest_key, model_json) elif model_type == "Clustering": from model.clustering import H2OClusteringModel model = H2OClusteringModel(future_model.job.dest_key, model_json) elif model_type == "Regression": from model.regression import H2ORegressionModel model = H2ORegressionModel(future_model.job.dest_key, model_json) elif model_type == "Multinomial": from model.multinomial import H2OMultinomialModel model = H2OMultinomialModel(future_model.job.dest_key, model_json) elif model_type == "AutoEncoder": from model.autoencoder import H2OAutoEncoderModel model = H2OAutoEncoderModel(future_model.job.dest_key, model_json) elif model_type == "DimReduction": from model.dim_reduction import H2ODimReductionModel model = H2ODimReductionModel(future_model.job.dest_key, model_json) else: print model_type raise NotImplementedError return model