當前位置: 首頁>>代碼示例>>Python>>正文


Python h2o.init方法代碼示例

本文整理匯總了Python中h2o.init方法的典型用法代碼示例。如果您正苦於以下問題:Python h2o.init方法的具體用法?Python h2o.init怎麽用?Python h2o.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在h2o的用法示例。


在下文中一共展示了h2o.init方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fit_transform

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def fit_transform(self, X: dt.Frame, y: np.array = None):
        h2o.init(port=config.h2o_recipes_port)
        model = H2OAutoEncoderEstimator(activation='tanh', epochs=1, hidden=[50, 50], reproducible=True, seed=1234)
        frame = h2o.H2OFrame(X.to_pandas())
        model_path = None
        try:
            model.train(x=list(range(X.ncols)), training_frame=frame)
            self.id = model.model_id
            model_path = os.path.join(user_dir(), "h2o_model." + str(uuid.uuid4()))
            model_path = h2o.save_model(model=model, path=model_path)
            with open(model_path, "rb") as f:
                self.raw_model_bytes = f.read()
            return model.anomaly(frame).as_data_frame(header=False)
        finally:
            if model_path is not None:
                remove(model_path)
            h2o.remove(model) 
開發者ID:h2oai,項目名稱:driverlessai-recipes,代碼行數:19,代碼來源:h2o3-dl-anomaly.py

示例2: transform

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def transform(self, X: dt.Frame):
        h2o.init(port=config.h2o_recipes_port)
        model_path = os.path.join(user_dir(), self.id)
        model_file = os.path.join(model_path, "h2o_model." + str(uuid.uuid4()) + ".bin")
        os.makedirs(model_path, exist_ok=True)
        with open(model_file, "wb") as f:
            f.write(self.raw_model_bytes)
        model = h2o.load_model(os.path.abspath(model_file))
        frame = h2o.H2OFrame(X.to_pandas())
        anomaly_frame = None

        try:
            anomaly_frame = model.anomaly(frame)
            anomaly_frame_df = anomaly_frame.as_data_frame(header=False)
            return anomaly_frame_df
        finally:
            remove(model_file)
            h2o.remove(self.id)
            h2o.remove(anomaly_frame) 
開發者ID:h2oai,項目名稱:driverlessai-recipes,代碼行數:21,代碼來源:h2o3-dl-anomaly.py

示例3: predict

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def predict(self, X, **kwargs):
        model, _, _, _ = self.get_model_properties()
        X = dt.Frame(X)
        h2o.init(port=config.h2o_recipes_port, log_dir=self.my_log_dir)
        model_path = os.path.join(user_dir(), self.id)
        model_file = os.path.join(model_path, "h2o_model." + str(uuid.uuid4()) + ".bin")
        os.makedirs(model_path, exist_ok=True)
        with open(model_file, "wb") as f:
            f.write(model)
        model = h2o.load_model(os.path.abspath(model_file))
        test_frame = h2o.H2OFrame(X.to_pandas(), column_types=self.col_types)
        preds_frame = None

        try:
            preds_frame = model.predict(test_frame)
            preds = preds_frame.as_data_frame(header=False)

            return preds.values.ravel()

        finally:
            remove(model_file)
            # h2o.remove(self.id) # Cannot remove id, do multiple predictions on same model
            h2o.remove(test_frame)
            if preds_frame is not None:
                h2o.remove(preds_frame) 
開發者ID:h2oai,項目名稱:driverlessai-recipes,代碼行數:27,代碼來源:h2o-glm-poisson.py

示例4: _pre_transform

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def _pre_transform(self, frame=None):
        frame_t = frame

        # we have to set the feature names at each stage to be
        # the remaining feature names (not the target though)
        next_feature_names = self.feature_names
        for name, transform in self.steps[:-1]:
            # for each transformer in the steps sequence, we need
            # to ensure the ``target_feature`` has been set... we do
            # this in the fit method and not the init because we've
            # now validated the ``target_feature``. Also this way if
            # ``target_feature`` is ever changed, this will be updated...
            transform.target_feature = self.target_feature

            # if the feature names are explicitly set in this estimator,
            # we won't set them to the ``next_feature_names``, however,
            # if the names are *not* explicitly set, we will set the 
            # estimator's ``feature_names`` to the ``next_feature_names``
            # variable set...
            if transform.feature_names is None:
                transform.feature_names = next_feature_names

            # now set the exclude_features if they exist
            transform.exclude_features = _union_exclusions(self.exclude_from_ppc,
                                                           transform.exclude_features)

            if hasattr(transform, "fit_transform"):
                frame_t = transform.fit_transform(frame_t)
            else:
                frame_t = transform.fit(frame_t).transform(frame_t)

            # now reset the next_feature_names to be the remaining names...
            next_feature_names = [str(nm) for nm in frame_t.columns if not (nm == self.target_feature)]
            if not next_feature_names or len(next_feature_names) < 1:
                raise ValueError('no columns retained after fit!')

        # this will have y re-combined in the matrix
        return frame_t, next_feature_names 
開發者ID:tgsmith61591,項目名稱:skutil,代碼行數:40,代碼來源:pipeline.py

示例5: h2o_compute

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def h2o_compute(X_train, y_train, X_test):
    import h2o
    from h2o.automl import H2OAutoML
    h2o.init(ip='localhost', port='55555', min_mem_size='14g', max_mem_size='15g')
    aml = H2OAutoML(max_runtime_secs = 3600)
    dd = h2o.H2OFrame(pd.concat([X_train, y_train], axis=1))
    dd['target'] = dd['target'].asfactor()
    aml.train(y = 'target', training_frame = dd)
    response = aml.predict(h2o.H2OFrame(X_test))
    return np.array(response[:,2].as_data_frame()) 
開發者ID:mljar,項目名稱:automl_comparison,代碼行數:12,代碼來源:compute.py

示例6: test_init_read

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def test_init_read(self):
        h2o.init()
        train = h2o.import_file("/input/tests/data/train.csv", destination_frame="train")
        self.assertEqual(100, train.nrow) 
開發者ID:Kaggle,項目名稱:docker-python,代碼行數:6,代碼來源:test_h2o.py

示例7: transform

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def transform(self, X: dt.Frame):

        stop_column_name = self.__class__._stop_column_name
        if stop_column_name in X.names:
            del X[:, stop_column_name]
        else:
            return X

        if self.id is None:
            return X

        #self._output_feature_names = list(X.names)
        #self._feature_desc = list(X.names)

        h2o.init(port=config.h2o_recipes_port, log_dir=self.my_log_dir)
        model_path = os.path.join(temporary_files_path, self.id)
        with open(model_path, "wb") as f:
            f.write(self.raw_model_bytes)
        model = h2o.load_model(os.path.abspath(model_path))
        remove(model_path)

        frame = h2o.H2OFrame(X.to_pandas())
        try:
            risk_frame = model.predict(frame)
            X[:, "risk_score_coxph_{}_{}".format(self.ties, self.max_iterations)] = risk_frame.as_data_frame(header=False)
            return X
        finally:
            h2o.remove(self.id)
            h2o.remove(frame)
            if risk_frame is not None:
                h2o.remove(risk_frame) 
開發者ID:h2oai,項目名稱:driverlessai-recipes,代碼行數:33,代碼來源:h2o-3-coxph-pretransformer.py

示例8: predict

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def predict(self, X, **kwargs):
        model, _, _, _ = self.get_model_properties()
        X = dt.Frame(X)
        h2o.init(port=config.h2o_recipes_port, log_dir=self.my_log_dir)
        model_path = os.path.join(user_dir(), self.id)
        model_file = os.path.join(model_path, "h2o_model." + str(uuid.uuid4()) + ".bin")
        os.makedirs(model_path, exist_ok=True)
        with open(model_file, "wb") as f:
            f.write(model)
        model = h2o.load_model(os.path.abspath(model_file))
        test_frame = h2o.H2OFrame(X.to_pandas(), column_types=self.col_types)
        preds_frame = None

        try:
            if kwargs.get("pred_contribs"):
                return model.predict_contributions(test_frame).as_data_frame(header=False).values
            preds_frame = model.predict(test_frame)
            preds = preds_frame.as_data_frame(header=False)
            if self.num_classes == 1:
                return preds.values.ravel()
            elif self.num_classes == 2:
                return preds.iloc[:, -1].values.ravel()
            else:
                return preds.iloc[:, 1:].values
        finally:
            # h2o.remove(self.id) # Cannot remove id, do multiple predictions on same model
            h2o.remove(test_frame)
            remove(model_file)
            if preds_frame is not None:
                h2o.remove(preds_frame) 
開發者ID:h2oai,項目名稱:driverlessai-recipes,代碼行數:32,代碼來源:h2o-3-models.py

示例9: load

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def load(self, path):
        try:
            import h2o
        except ImportError:
            raise MissingDependencyException(
                "h2o package is required to use H2oModelArtifact"
            )

        h2o.init()
        model = h2o.load_model(self._model_file_path(path))
        return self.pack(model) 
開發者ID:bentoml,項目名稱:BentoML,代碼行數:13,代碼來源:h2o_model_artifact.py

示例10: _load_model

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def _load_model(path, init=False):
    import h2o

    path = os.path.abspath(path)
    with open(os.path.join(path, "h2o.yaml")) as f:
        params = yaml.safe_load(f.read())
    if init:
        h2o.init(**(params["init"] if "init" in params else {}))
        h2o.no_progress()
    return h2o.load_model(os.path.join(path, params['model_file'])) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:12,代碼來源:h2o.py

示例11: _load_pyfunc

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def _load_pyfunc(path):
    """
    Load PyFunc implementation. Called by ``pyfunc.load_pyfunc``.

    :param path: Local filesystem path to the MLflow Model with the ``h2o`` flavor.
    """
    return _H2OModelWrapper(_load_model(path, init=True)) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:9,代碼來源:h2o.py

示例12: load_model

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def load_model(model_uri):
    """
    Load an H2O model from a local file (if ``run_id`` is ``None``) or a run.
    This function expects there is an H2O instance initialised with ``h2o.init``.

    :param model_uri: The location, in URI format, of the MLflow model. For example:

                      - ``/Users/me/path/to/local/model``
                      - ``relative/path/to/local/model``
                      - ``s3://my_bucket/path/to/model``
                      - ``runs:/<mlflow_run_id>/run-relative/path/to/model``
                      - ``models:/<model_name>/<model_version>``
                      - ``models:/<model_name>/<stage>``

                      For more information about supported URI schemes, see
                      `Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
                      artifact-locations>`_.

    :return: An `H2OEstimator model object
             <http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/intro.html#models>`_.
    """
    local_model_path = _download_artifact_from_uri(artifact_uri=model_uri)
    flavor_conf = _get_flavor_configuration(model_path=local_model_path, flavor_name=FLAVOR_NAME)
    # Flavor configurations for models saved in MLflow version <= 0.8.0 may not contain a
    # `data` key; in this case, we assume the model artifact path to be `model.h2o`
    h2o_model_file_path = os.path.join(local_model_path, flavor_conf.get("data", "model.h2o"))
    return _load_model(path=h2o_model_file_path) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:29,代碼來源:h2o.py

示例13: h2o_iris_model

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def h2o_iris_model():
    h2o.init()
    iris = datasets.load_iris()
    data = h2o.H2OFrame({
        'feature1': list(iris.data[:, 0]),
        'feature2': list(iris.data[:, 1]),
        'target': list(map(lambda i: "Flower %d" % i, iris.target))
    })
    train, test = data.split_frame(ratios=[.7])

    h2o_gbm = H2OGradientBoostingEstimator(ntrees=10, max_depth=6)
    h2o_gbm.train(['feature1', 'feature2'], 'target', training_frame=train)
    return ModelWithData(model=h2o_gbm, inference_data=test) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:15,代碼來源:test_h2o_model_export.py

示例14: process_h2o

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def process_h2o(X_train, X_test, y_train, df_types, m_type, seed,*args):
    """Function that trains and tests data using h2o's AutoML"""

    import h2o
    from h2o.automl import H2OAutoML

    ip = args[0] if len(args) > 0 else '127.0.0.1'
    port = np.random.randint(5555,8888)

    h2o.init(ip=ip, port=port, nthreads=N_CORES, min_mem_size=MIN_MEM, max_mem_size=MAX_MEM, ice_root='/tmp/')

    aml = None

    if(m_type == 'classification'):
        aml = H2OAutoML(max_runtime_secs=TIME_PER_TASK, seed=seed, sort_metric='AUTO')
    else:
        aml = H2OAutoML(max_runtime_secs=TIME_PER_TASK, seed=seed, sort_metric='MSE')

    dd = h2o.H2OFrame(pd.concat([X_train, y_train], axis=1))
    td = h2o.H2OFrame(X_test)

    # set categorical columns as 'factors'
    categ_cols = df_types[df_types['TYPE'] == 'categorical']['NAME'].values.tolist()
    if len(categ_cols) > 0:
        dd[categ_cols] = dd[categ_cols].asfactor()
        td[categ_cols] = td[categ_cols].asfactor()
    if m_type == 'classification':
        dd['target'] = dd['target'].asfactor()

    aml.train(y = 'target', training_frame = dd)
    response = aml.predict(td)
    pred =  (response[1:].as_data_frame().values if m_type == 'classification' else 
            response.as_data_frame().values.ravel())

    h2o.cluster().shutdown()

    return pred 
開發者ID:georgianpartners,項目名稱:automl_benchmark,代碼行數:39,代碼來源:benchmark.py

示例15: setUpClass

# 需要導入模塊: import h2o [as 別名]
# 或者: from h2o import init [as 別名]
def setUpClass(cls):
        h2o.init(port=54440) 
開發者ID:onnx,項目名稱:onnxmltools,代碼行數:4,代碼來源:test_h2o_converters.py


注:本文中的h2o.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。