“ DataFrame”对象没有属性“ split_frame”

时间:2019-06-11 01:01:53

标签: h2o

无法使用split_frame()分割帧。数据框能够显示(),但我不能拆分它。请帮忙。

下面是我使用的代码示例。

from h2o.estimators.random_forest import H2ORandomForestEstimator
from h2o.estimators.gbm import H2OGradientBoostingEstimator
from h2o.estimators.deeplearning import H2ODeepLearningEstimator
from h2o.estimators.glm import H2OGeneralizedLinearEstimator
from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator
from __future__ import print_function

temp = spark.read.option("header","true").option("inferSchema","true").csv("hdfs://bda-ns/user/august_week2.csv")

train,test,valid = temp.split_frame(ratios=[.75, .15])

预期:没有错误。数据分为测试和训练数据帧。 实际:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/cloudera/parcels/SPARK2-2.3.0.cloudera2-1.cdh5.13.3.p0.316101/lib/spark2/python/pyspark/sql/dataframe.py", line 1182, in __getattr__
    "'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
AttributeError: 'DataFrame' object has no attribute 'split_frame'
>>> train,test,valid = temp.split_frame(ratios=[.75, .15])
Traceback (most recent call last):
  File "/opt/cloudera/parcels/SPARK2-2.3.0.cloudera2-1.cdh5.13.3.p0.316101/lib/spark2/python/pyspark/context.py", line 234, in signal_handler

1 个答案:

答案 0 :(得分:1)

您可以在Spark数据框上使用randomsplit

如果要使用H2O-3 split_frame方法,则首先必须将spark帧转换为h2o帧。在这种情况下,您可以使用hc.as_h2o_frame(spark_df),其中hc是您的h2o_context(注意:您还需要创建h2o_context才能起作用)。