想知道是否有内置的Spark功能将1,2,n-gram功能组合到一个词汇表中.设置n=2在NGram随后的调用CountVectorizer仅含有2克导致字典.我真正想要的是将所有频繁的1克,2克等组合成一个字典用于我的语料库.
我想跟踪一些任意命名的字符串的计数,然后将计数重置为零.我的想法是做以下事情:
reset_hash={"string1"=>0,"string2"=>0,"string3"=>0}
=> {"string1"=>0, "string2"=>0, "string3"=>0}
new_hash = reset_hash
=> {"string1"=>0, "string2"=>0, "string3"=>0}
new_hash["string1"]=1
new_hash["string3"]=1
new_hash
=> {"string1"=>1, "string2"=>0, "string3"=>1}
Run Code Online (Sandbox Code Playgroud)
...
现在我想将new_hash重置为reset_hash:
new_hash = reset_hash
=> {"string1"=>1, "string2"=>0, "string3"=>1}
reset_hash
=> {"string1"=>1, "string2"=>0, "string3"=>1}
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?似乎reset_hash实际上已设置为new_hash,这与我想要的相反.如何实现所需的行为?
假设我们有以下文件集:
{ "_id" : ObjectId("50a69fa904c8310609600be3"), "id" : 100, "city" : "San Francisco", "friends" : [ { "id" : 1, "name" : "John" }, { "id" : 2, "name" : "Betty" }, { "id" : 3, "name" : "Harry" } ] }
{ "_id" : ObjectId("50a69fc104c8310609600be4"), "id" : 200, "city" : "Palo Alto", "friends" : [ { "id" : 1, "name" : "Carol" }, { "id" : 2, "name" : "Frank" }, { "id" : 3, "name" : "Norman" } ] …Run Code Online (Sandbox Code Playgroud) 以下是相关示例.我正在考虑将球员效率作为NBA球员距离的函数.我想通过在每个距离拍摄的照片量(即气泡的大小)来对平滑进行加权.有没有办法做到这一点?生成此图的命令是:
ggplot(top10,aes(x=FT,y=PPS,size=FGA,color=PPS))
+scale_x_continuous(limits = c(0, 30))
+scale_y_continuous(limits = c(0, 2.2))+geom_point()
+facet_grid(NAME~.,space="free")
+stat_smooth(color="darkblue",size=2)
Run Code Online (Sandbox Code Playgroud)

我想制作一个2x4的图表阵列,显示随时间变化的分布.默认ggplot安排facet_wrap是顶行有系列1和2,第二行有系列3和4等.我想改变它,以便第一列按顺序排列(1-> 2-> 3-> 4)和然后第二列有下一个4系列.通过这种方式,您的眼睛可以在垂直方向上立即比较相邻的分布(我认为它们应该是这样).
我正在尝试在我的Mac上本地设置hadoop,但在尝试brew install hadoop时遇到以下错误:
$ brew install hadoop
==> Downloading http://www.apache.org/dyn/closer.cgi?path=hadoop/core/hadoop-1.1.2/hadoop-1.1.2.tar.gz
==> Best Mirror http://apache.mirrors.pair.com/hadoop/core/hadoop-1.1.2/hadoop-1.1.2.tar.gz
curl: (22) The requested URL returned error: 404
Error: Download failed: http://www.apache.org/dyn/closer.cgi?path=hadoop/core/hadoop-1.1.2/hadoop-1.1.2.tar.gz
Run Code Online (Sandbox Code Playgroud)
任何想法我应该做什么?
试图弄清楚如何在PySpark中使用窗口函数.这是我希望能够做的一个例子,只计算用户有"事件"的次数(在这种情况下,"dt"是模拟时间戳).
from pyspark.sql.window import Window
from pyspark.sql.functions import count
df = sqlContext.createDataFrame([{"id": 123, "dt": 0}, {"id": 123, "dt": 1}, {"id": 234, "dt":0}, {"id": 456, "dt":0}, {"id": 456, "dt":1}, {"id":456, "dt":2}])
df.select(["id","dt"], count("dt").over(Window.partitionBy("id").orderBy("dt")).alias("count")).show()
Run Code Online (Sandbox Code Playgroud)
这会产生错误.使用窗口函数的正确方法是什么?我读到1.4.1(我们需要使用的版本,因为它是AWS上的标准版本)应该能够使用DataFrame API来实现它们.
FWIW,关于这个主题的文档很少.我无法让任何实例运行.
当我在Docker容器中运行它时会失败,但是当我在OS X的virtualenv中运行它时效果很好。Docker + boto是否存在任何已知问题?
>>> import boto3
>>> s3 = boto3.client('s3')
>>> s3.download_file("mybucket", "myfile.txt", "myfile2.txt")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/lib/python2.7/site-packages/boto3/s3/inject.py", line 104, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/opt/conda/lib/python2.7/site-packages/boto3/s3/transfer.py", line 666, in download_file
object_size = self._object_size(bucket, key, extra_args)
File "/opt/conda/lib/python2.7/site-packages/boto3/s3/transfer.py", line 729, in _object_size
Bucket=bucket, Key=key, **extra_args)['ContentLength']
File "/opt/conda/lib/python2.7/site-packages/botocore/client.py", line 258, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/conda/lib/python2.7/site-packages/botocore/client.py", line 548, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (403) when calling the …Run Code Online (Sandbox Code Playgroud) 这个问题实际上适用于任何 Python 包。我有一个在 Spark 作业之前运行的引导脚本,我假设我需要在该脚本中安装 Pandas。我尝试了很多不同的东西,但似乎没有任何效果(pip install、easy_install、yum install 等)。当在 Spark pandas 中导入失败时,作业都失败了。我正在运行 EMR v5.12.1 和 Python 3.4。
假设我有以下内容DataFrame:
[Row(user='bob', values=[0.5, 0.3, 0.2]),
Row(user='bob', values=[0.1, 0.3, 0.6]),
Row(user='bob', values=[0.8, 0.1, 0.1])]
Run Code Online (Sandbox Code Playgroud)
我想groupBy user并做一些事情,比如avg(values)平均值取决于数组的每个索引,values如下所示:
[Row(user='bob', avgerages=[0.466667, 0.233333, 0.3])]
Run Code Online (Sandbox Code Playgroud)
我怎么能在PySpark中做到这一点?