pyspark count vectorizer错误,错误版本?

时间:2019-04-08 07:52:00

标签: python pyspark

我有一个关于使用pyspark进行计数向量化的问题

这是我的数据框,没有空值

from pyspark.sql.functions import isnan, when, count, col, rand

datatrain.select([count(when(isnan(c), c)).alias(c) for c in datatrain.columns]).show()
+------+-------+--------------+---------------+
|labels|subject|cleanedSubject|subjectLanguage|
+------+-------+--------------+---------------+
|     0|      0|             0|              0|
+------+-------+--------------+---------------+


 = 
datatrain = datatrain.orderBy(rand(42))
datatrain.show(5)
+-------------------+--------------------+--------------------+---------------+
|             labels|             subject|      cleanedSubject|subjectLanguage|
+-------------------+--------------------+--------------------+---------------+
|CATEGORY_PROMOTIONS|sebuah survei yan...|    buah survei baru|             id|
|   CATEGORY_UPDATES|[reminder] pengum...|reminder pengumum...|             et|
|   CATEGORY_UPDATES|“what have we lea...|learn googl publi...|             en|
|    CATEGORY_SOCIAL|nova hairiyanov a...|nova hairiyanov a...|             cy|
|   CATEGORY_UPDATES|payout request re...|payout request re...|             fr|
+-------------------+--------------------+--------------------+---------------+

这是我的管道

tokenizer = RegexTokenizer(inputCol="cleanedSubject",outputCol="cleanedSubject_token")
countVectorizer = CountVectorizer(inputCol="cleanedSubject_token",outputCol="features")
stringIndexer = StringIndexer(inputCol="labels",outputCol="label",stringOrderType="alphabetAsc")
classifier = LogisticRegression(regParam=0.1)

pipeline = Pipeline(stages=[stringIndexer,tokenizer,countVectorizer,classifier])

但是,尽管管道合适,但给我一个错误:

> Py4JJavaError                             Traceback (most recent call
> last) <ipython-input-230-beaf2f2c4310> in <module>
> ----> 1 pipeline = pipeline.fit(datatrain)
> 
> /etc/spark/python/pyspark/ml/base.py in fit(self, dataset, params)
>     130                 return self.copy(params)._fit(dataset)
>     131             else:
> --> 132                 return self._fit(dataset)
>     133         else:
>     134             raise ValueError("Params must be either a param map or a list/tuple of param maps, "
> 
> /etc/spark/python/pyspark/ml/pipeline.py in _fit(self, dataset)
>     107                     dataset = stage.transform(dataset)
>     108                 else:  # must be an Estimator
> --> 109                     model = stage.fit(dataset)
>     110                     transformers.append(model)
>     111                     if i < indexOfLastEstimator:
> 
> /etc/spark/python/pyspark/ml/base.py in fit(self, dataset, params)
>     130                 return self.copy(params)._fit(dataset)
>     131             else:
> --> 132                 return self._fit(dataset)
>     133         else:
>     134             raise ValueError("Params must be either a param map or a list/tuple of param maps, "
> 
> /etc/spark/python/pyspark/ml/wrapper.py in _fit(self, dataset)
>     293 
>     294     def _fit(self, dataset):
> --> 295         java_model = self._fit_java(dataset)
>     296         model = self._create_model(java_model)
>     297         return self._copyValues(model)
> 
> /etc/spark/python/pyspark/ml/wrapper.py in _fit_java(self, dataset)
>     290         """
>     291         self._transfer_params_to_java()
> --> 292         return self._java_obj.fit(dataset._jdf)
>     293 
>     294     def _fit(self, dataset):
> 
> /usr/lib/python3.7/site-packages/py4j/java_gateway.py in
> __call__(self, *args)    1284         answer = self.gateway_client.send_command(command)    1285         return_value
> = get_return_value(
> -> 1286             answer, self.gateway_client, self.target_id, self.name)    1287     1288         for temp_arg in temp_args:
> 
> /etc/spark/python/pyspark/sql/utils.py in deco(*a, **kw)
>      61     def deco(*a, **kw):
>      62         try:
> ---> 63             return f(*a, **kw)
>      64         except py4j.protocol.Py4JJavaError as e:
>      65             s = e.java_exception.toString()
> 
> /usr/lib/python3.7/site-packages/py4j/protocol.py in
> get_return_value(answer, gateway_client, target_id, name)
>     326                 raise Py4JJavaError(
>     327                     "An error occurred while calling {0}{1}{2}.\n".
> --> 328                     format(target_id, ".", name), value)
>     329             else:
>     330                 raise Py4JError(
> 
> Py4JJavaError: An error occurred while calling o1503.fit. :
> org.apache.spark.SparkException: Job aborted due to stage failure:
> Task 13 in stage 190.0 failed 1 times, most recent failure: Lost task
> 13.0 in stage 190.0 (TID 5217, localhost, executor driver): org.apache.spark.SparkException: Failed to execute user defined
> function($anonfun$createTransformFunc$2: (string) => array<string>)
>   at
> org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage2.processNext(Unknown
> Source)   at
> org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
>   at
> org.apache.spark.sql.execution.WholeStageCodegenExec$$anonfun$13$$anon$1.hasNext(WholeStageCodegenExec.scala:636)
>   at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)   at
> scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)


  [1]: https://i.stack.imgur.com/4DjZD.png   [2]: https://i.stack.imgur.com/zKknc.png

我尝试用权标器手动转换数据集,并将其放入countvectorizer中,但给出相同的错误。谢谢你的帮助

火花2.4.1

python 3.7.2

0 个答案:

没有答案