我正在尝试使用MlLib进行我的colloborative过滤.
当我在Apache Spark 1.0.0中运行它时,我在Scala程序中遇到以下错误.
14/07/15 16:16:31 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/07/15 16:16:31 WARN LoadSnappy: Snappy native library not loaded
14/07/15 16:16:31 INFO FileInputFormat: Total input paths to process : 1
14/07/15 16:16:38 WARN TaskSetManager: Lost TID 10 (task 80.0:0)
14/07/15 16:16:38 WARN TaskSetManager: Loss was due to java.lang.UnsatisfiedLinkError
java.lang.UnsatisfiedLinkError: org.jblas.NativeBlas.dposv(CII[DII[DII)I
at org.jblas.NativeBlas.dposv(Native Method)
at org.jblas.SimpleBlas.posv(SimpleBlas.java:369)
at org.jblas.Solve.solvePositive(Solve.java:68)
at org.apache.spark.mllib.recommendation.ALS$$anonfun$org$apache$spark$mllib$recommendation$ALS$$updateBlock$2.apply(ALS.scala:522)
at org.apache.spark.mllib.recommendation.ALS$$anonfun$org$apache$spark$mllib$recommendation$ALS$$updateBlock$2.apply(ALS.scala:509)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofInt.foreach(ArrayOps.scala:156) …Run Code Online (Sandbox Code Playgroud) scala collaborative-filtering apache-spark apache-spark-mllib
试图了解Spark的规范化算法.我的小测试集包含5个向量:
{0.95, 0.018, 0.0, 24.0, 24.0, 14.4, 70000.0},
{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 70000.0},
{-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 70000.0},
{-0.95, 0.018, 0.0, 24.0, 24.0, 14.4, 70000.0},
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 70000.0},
Run Code Online (Sandbox Code Playgroud)
我希望在每个向量要素被标准化的地方new Normalizer().transform(vectors)创建JavaRDD,其中(v-mean)/stdevfeature-0,`feature-1等
的所有值都被标准化.结果集合为:
[-1.4285714276967932E-5,-1.4285714276967932E-5,-1.4285714276967932E-5,-1.4285714276967932E-5,-1.4285714276967932E-5,-1.4285714276967932E-5,0.9999999993877552]
[1.357142668768307E-5,2.571428214508371E-7,0.0,3.428570952677828E-4,3.428570952677828E-4,2.057142571606697E-4,0.9999998611976999]
[-1.357142668768307E-5,2.571428214508371E-7,0.0,3.428570952677828E-4,3.428570952677828E-4,2.057142571606697E-4,0.9999998611976999]
[1.4285714276967932E-5,1.4285714276967932E-5,1.4285714276967932E-5,1.4285714276967932E-5,1.4285714276967932E-5,1.4285714276967932E-5,0.9999999993877552]
[0.0,0.0,0.0,0.0,0.0,0.0,1.0]
Run Code Online (Sandbox Code Playgroud)
请注意,所有原始值7000.0都会导致不同的"标准化"值.此外,如何,例如,1.357142668768307E-5被当值的计算:.95,1,-1,-.95,0?更重要的是,如果我删除一个功能,结果会有所不同.无法找到有关该问题的任何文档.
事实上,我的问题是,如何正确地规范化RDD中的所有向量?
该文件为随机森林不包括功能重要性有关.但是,它在Jira上列为已解决并且在源代码中.HERE还说"这个API和原始MLlib合奏API之间的主要区别是:
但是,我无法找出可以调用此新功能的语法.
scala> model
res13: org.apache.spark.mllib.tree.model.RandomForestModel =
TreeEnsembleModel classifier with 10 trees
scala> model.featureImportances
<console>:60: error: value featureImportances is not a member of org.apache.spark.mllib.tree.model.RandomForestModel
model.featureImportances
Run Code Online (Sandbox Code Playgroud) 我正在尝试在spark和scala中实现神经网络,但无法执行任何向量或矩阵乘法.Spark提供两个向量.Spark.util矢量支持点操作但不推荐使用.mllib.linalg向量不支持scala中的操作.
哪一个用于存储权重和训练数据?
如何使用像w*x这样的mllib在spark scala中执行向量乘法,其中w是向量或权重矩阵,x是输入.pyspark矢量支持点积,但在scala我无法在向量中找到这样的函数
我想在Spark上做一些DBSCAN.我目前发现了2个实现:
我已经使用其github中给出的sbt配置测试了第一个但是:
jar中的函数与doc或github上的源代码中的函数不同.例如,我在jar中找不到列车功能
我设法使用fit函数(在jar中找到)运行测试,但是epsilon的错误配置(从小到大)将代码置于无限循环中.
代码:
val model = DBSCAN.fit(eps, minPoints, values, parallelism)
Run Code Online (Sandbox Code Playgroud)
有人设法与第一个图书馆合作吗?
有人测试过第二个吗?
scala cluster-analysis dbscan apache-spark apache-spark-mllib
我修改了OneHotEncoder示例以实际训练LogisticRegression.我的问题是如何将生成的权重映射回分类变量?
def oneHotEncoderExample(sqlContext: SQLContext): Unit = {
val df = sqlContext.createDataFrame(Seq(
(0, "a", 1.0),
(1, "b", 1.0),
(2, "c", 0.0),
(3, "d", 1.0),
(4, "e", 1.0),
(5, "f", 0.0)
)).toDF("id", "category", "label")
df.show()
val indexer = new StringIndexer()
.setInputCol("category")
.setOutputCol("categoryIndex")
.fit(df)
val indexed = indexer.transform(df)
indexed.select("id", "categoryIndex").show()
val encoder = new OneHotEncoder()
.setInputCol("categoryIndex")
.setOutputCol("features")
val encoded = encoder.transform(indexed)
encoded.select("id", "features").show()
val lr = new LogisticRegression()
.setMaxIter(10)
.setRegParam(0.01)
val pipeline = new Pipeline()
.setStages(Array(indexer, encoder, lr))
// Fit the pipeline to …Run Code Online (Sandbox Code Playgroud) 我已经建立了一个简单的Spark-ML应用程序,我有一个独立的变换器管道,可以将列添加到原始数据的数据框中.由于变压器不看彼此的输出,我希望我可以在非线性(DAG)管道中并行运行它们.我可以找到关于此功能的所有内容来自Spark ML-Guide:
只要数据流图形成有向无环图(DAG),就可以创建非线性管道.目前,此图基于每个阶段的输入和输出列名称(通常指定为参数)隐式指定.如果管道形成DAG,则必须按拓扑顺序指定阶段.
我对段落的理解是,如果我为每个转换器设置inputCol(s),outputCol参数并在创建管道时以拓扑顺序指定阶段,那么引擎将使用该信息来构建执行DAG的阶段.一旦输入就绪,DAG就可以运行了.
关于这个的一些问题:
在为这个主题投入大量的网络搜索之后,如果我能得到一些指针,我将在这里结束.请进一步阅读
在分析Spark 2.0之后,我得出结论多项式回归是不可能的火花(单独的火花),所以是否有一些可用于多项式回归的火花扩展? - Rspark它可以完成(但寻找更好的替代方案) - 火花中的RFormula做预测,但系数不可用(这是我的主要要求,因为我主要对系数值感兴趣)
我试图在apache spark上使用scala运行自包含的应用程序,例如:http: //spark.apache.org/docs/latest/ml-pipeline.html
这是我的完整代码:
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.ml.linalg.{Vector, Vectors}
import org.apache.spark.ml.param.ParamMap
import org.apache.spark.sql.Row
object mllibexample1 {
def main(args: Array[String]) {
val spark = SparkSession
.builder()
.master("local[*]")
.appName("logistic regression example 1")
.getOrCreate()
val training = spark.createDataFrame(Seq(
(1.0, Vectors.dense(0.0, 1.1, 0.1)),
(0.0, Vectors.dense(2.0, 1.0, -1.0)),
(0.0, Vectors.dense(2.0, 1.3, 1.0)),
(1.0, Vectors.dense(0.0, 1.2, -0.5))
)).toDF("label", "features")
val lr = new LogisticRegression()
println("LogisticRegression parameters:\n" + lr.explainParams() + "\n")
lr.setMaxIter(100)
.setRegParam(0.01)
val model1 = lr.fit(training)
println("Model 1 was fit using parameters: " + …Run Code Online (Sandbox Code Playgroud) 我有一个由SQL查询产生的数据帧
df1 = sqlContext.sql("select * from table_test")
Run Code Online (Sandbox Code Playgroud)
我需要将此数据帧转换为libsvm格式,以便可以将其作为输入提供
pyspark.ml.classification.LogisticRegression
Run Code Online (Sandbox Code Playgroud)
我试着做以下事情.但是,这导致了以下错误,因为我正在使用spark 1.5.2
df1.write.format("libsvm").save("data/foo")
Failed to load class for data source: libsvm
Run Code Online (Sandbox Code Playgroud)
我想改用MLUtils.loadLibSVMFile.我在防火墙后面,不能直接pip安装它.所以我下载了文件,scp-ed然后手动安装它.一切似乎工作正常,但我仍然得到以下错误
import org.apache.spark.mllib.util.MLUtils
No module named org.apache.spark.mllib.util.MLUtils
Run Code Online (Sandbox Code Playgroud)
问题1:我的上述方法是将数据帧转换为正确方向的libsvm格式.问题2:如果问题1为"是",如何让MLUtils正常工作.如果"否",将数据帧转换为libsvm格式的最佳方法是什么
apache-spark apache-spark-sql pyspark spark-dataframe apache-spark-mllib