如何解决读取apache mllib演示文件的问题 [英] How to solve the problem with read apache mllib demo file
问题描述
我是 spark 新手,我正在尝试在 Mac 上本地运行来自 Apache Spark MLlib 指南的以下代码.我已经安装了 Java 8、Scala、spark 和 pyspark.Scala 和 pyspark 在终端上工作.
I am new to spark and I am trying to run the following code that comes from the Apache Spark MLlib guide locally on a Mac. I have installed Java 8, Scala, spark and pyspark. Scala and pyspark work on the terminal.
from pyspark.context import SparkContext
from pyspark.sql.session import SparkSession
sc = SparkContext('local')
spark = SparkSession(sc)
from pyspark.ml.classification import LogisticRegression
# Load training data
training = spark.read.format("libsvm").load("sample_libsvm_data.txt")
该文件在项目文件夹中,但出现以下错误:
The file is in the project folder but I get the following error:
training = spark.read.format("libsvm").load("sample_libsvm_data.txt")
Traceback (most recent call last):
File "<ipython-input-23-16efb76d78dc>", line 1, in <module>
training = spark.read.format("libsvm").load("sample_libsvm_data.txt")
File "/Users/georgioskourogiorgas/anaconda3/lib/python3.6/site-packages/pyspark/sql/readwriter.py", line 166, in load
return self._df(self._jreader.load(path))
File "/Users/georgioskourogiorgas/anaconda3/lib/python3.6/site-packages/py4j/java_gateway.py", line 1257, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/Users/georgioskourogiorgas/anaconda3/lib/python3.6/site-packages/pyspark/sql/utils.py", line 63, in deco
return f(*a, **kw)
File "/Users/georgioskourogiorgas/anaconda3/lib/python3.6/site-packages/py4j/protocol.py", line 328, in get_return_value
format(target_id, ".", name), value)
Py4JJavaError: An error occurred while calling o521.load.
: java.lang.UnsupportedOperationException: empty collection
文件没有损坏或为空.
推荐答案
我想通了.首先,出于某种原因,它需要一条路径.虽然,我在 Spyder 中创建了一个项目,但它无法识别工作目录.然后我的路径有一个带空格的文件夹.它也不喜欢那样.
I figured it out. First it needs a path for some reason. Although, I had created a project in Spyder it didn't recognise the working directory. Then my path had a folder with a space. It didn't like that either.
这篇关于如何解决读取apache mllib演示文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!