Example #1
0
 def to_pojo(self, pojo_name="", path="", get_jar=True):
     if pojo_name == "":
         pojo_name = unicode("AssemblyPOJO_" + str(uuid.uuid4()))
     java = H2OConnection.get("Assembly.java/" + self.id + "/" + pojo_name, _rest_version=99)
     file_path = path + "/" + pojo_name + ".java"
     if path == "":
         print java.text
     else:
         with open(file_path, "wb") as f:
             f.write(java.text)
     if get_jar and path != "":
         url = H2OConnection.make_url("h2o-genmodel.jar")
         filename = path + "/" + "h2o-genmodel.jar"
         response = urllib2.urlopen(url)
         with open(filename, "wb") as f:
             f.write(response.read())
Example #2
0
 def fit(self, fr, **fit_params):
     res = []
     for step in self.steps:
         res.append(step[1].to_rest(step[0]))
     res = "[" + ",".join([_quoted(r.replace('"', "'")) for r in res]) + "]"
     j = H2OConnection.post_json(url_suffix="Assembly", steps=res, frame=fr.frame_id, _rest_version=99)
     self.id = j["assembly"]["name"]
     return get_frame(j["result"]["name"])
Example #3
0
 def to_pojo(self, pojo_name="", path="", get_jar=True):
     if pojo_name == "":
         pojo_name = unicode("AssemblyPOJO_" + str(uuid.uuid4()))
     java = H2OConnection.get("Assembly.java/" + self.id + "/" + pojo_name,
                              _rest_version=99)
     file_path = path + "/" + pojo_name + ".java"
     if path == "": print java.text
     else:
Example #4
0
 def fit(self, fr, **fit_params):
     res = []
     for step in self.steps:
         res.append(step[1].to_rest(step[0]))
     res = "[" + ",".join([_quoted(r.replace('"', "'")) for r in res]) + "]"
     j = H2OConnection.post_json(url_suffix="Assembly",
                                 steps=res,
                                 frame=fr.frame_id,
                                 _rest_version=99)
     self.id = j["assembly"]["name"]
     return get_frame(j["result"]["name"])
Example #5
0
    def model_performance(self, test_data=None):
        """
        Compute the binary classifier model metrics on `test_data`
        :param test_data: An H2OFrame
        :return: A H2OBinomialMetrics object; prints model metrics summary
        """

        if not test_data:
            raise ValueError("Missing`test_data`.")

        if not isinstance(test_data, H2OFrame):
            raise ValueError("`test_data` must be of type H2OFrame. Got: " +
                             type(test_data))

        fr_key = H2OFrame.send_frame(test_data)

        url_suffix = "ModelMetrics/models/" + self._key + "/frames/" + fr_key
        res = H2OConnection.post_json(url_suffix=url_suffix)
        raw_metrics = res["model_metrics"][0]
        return H2OBinomialModelMetrics(raw_metrics)
Example #6
0
 def to_pojo(self, pojo_name="", path=""):
   if pojo_name=="": pojo_name = unicode("AssemblyPOJO_" + str(uuid.uuid4()))
   java = H2OConnection.get("Assembly.java/" + self.id + "/" + pojo_name, _rest_version=99)
   file_path = path + "/" + pojo_name + ".java"
   if path == "": print java.text
   else:
Example #7
0
    @property
    def names(self):
        return zip(*self.steps)[0][:-1]

    def to_pojo(self, pojo_name="", path="", get_jar=True):
        if pojo_name == "":
            pojo_name = unicode("AssemblyPOJO_" + str(uuid.uuid4()))
        java = H2OConnection.get("Assembly.java/" + self.id + "/" + pojo_name,
                                 _rest_version=99)
        file_path = path + "/" + pojo_name + ".java"
        if path == "": print java.text
        else:
            with open(file_path, 'wb') as f:
                f.write(java.text)
        if get_jar and path != "":
            url = H2OConnection.make_url("h2o-genmodel.jar")
            filename = path + "/" + "h2o-genmodel.jar"
            response = urllib2.urlopen(url)
            with open(filename, "wb") as f:
                f.write(response.read())

    # def union(self, assemblies):
    #   # fuse the assemblies onto this one, each is added to the end going left -> right
    #   # assemblies must be a list of namedtuples.
    #   #   [(H2OAssembly, X, y, {params}), ..., (H2OAssembly, X, y, {params})]
    #   for i in assemblies:
    #     if not isinstance(i, namedtuple):
    #       raise ValueError("Not a namedtuple. Assembly must be of type collections.namedtuple with fields [assembly, x, params].")
    #     if i._fields != ('assembly','x','params'):
    #       raise ValueError("Assembly must be a namedtuple with fields ('assembly', 'x', 'params').")
    #     self.fuzed.append(i)
Example #8
0
    self.out_colnames = None

  @property
  def names(self):
    return zip(*self.steps)[0][:-1]

  def to_pojo(self, pojo_name="", path="", get_jar=True):
    if pojo_name=="": pojo_name = unicode("AssemblyPOJO_" + str(uuid.uuid4()))
    java = H2OConnection.get("Assembly.java/" + self.id + "/" + pojo_name, _rest_version=99)
    file_path = path + "/" + pojo_name + ".java"
    if path == "": print java.text
    else:
      with open(file_path, 'wb') as f:
        f.write(java.text)
    if get_jar and path!="":
      url = H2OConnection.make_url("h2o-genmodel.jar")
      filename = path + "/" + "h2o-genmodel.jar"
      response = urllib2.urlopen(url)
      with open(filename, "wb") as f:
        f.write(response.read())

  def union(self, assemblies):
    # fuse the assemblies onto this one, each is added to the end going left -> right
    # assemblies must be a list of namedtuples.
    #   [(H2OAssembly, X, y, {params}), ..., (H2OAssembly, X, y, {params})]
    for i in assemblies:
      if not isinstance(i, namedtuple):
        raise ValueError("Not a namedtuple. Assembly must be of type collections.namedtuple with fields [assembly, x, params].")
      if i._fields != ('assembly','x','params'):
        raise ValueError("Assembly must be a namedtuple with fields ('assembly', 'x', 'params').")
      self.fuzed.append(i)