我有分类文本的语料库.从这些我创建矢量.每个向量对应一个文档.矢量分量是本文档中的字权重,计算为TFIDF值.接下来,我构建一个模型,其中每个类都由一个向量表示.模型具有与语料库中的类一样多的向量.模型矢量的分量被计算为取自该类中矢量的所有分量值的平均值.对于未分类的矢量,我通过计算这些矢量之间的余弦来确定与模型矢量的相似性.
问题:
1)我可以使用未分类和模型向量之间的欧几里德距离来计算它们的相似性吗?
2)为什么欧几里德距离不能用作相似度量而不是两个矢量之间的角度余弦,反之亦然?
谢谢!
我收集了大约100万条记录,每条记录有20个字段.我需要更新flag每个记录(文档)中的整数字段,随机分配1或2到该flag字段.如何在整个集合上迭代光标时执行此操作?为了能够更新它,第二次搜索MongoDB已找到的对象似乎不是一个好主意:
DBCursor cursor = coll.find();
try {
while(cursor.hasNext()) {
BasicDBObject obj = (BasicDBObject) cursor.next();
...
coll.update(query,newObj)
}
} finally {
cursor.close();
}
Run Code Online (Sandbox Code Playgroud)
如何有效地更新具有不同值的巨大MongoDB集合的每个文档中的字段?
请帮助解释weka库中weka.classifiers.functions.Logistic产生的逻辑回归结果.
我使用来自Weka示例的数值数据:
@relation weather
@attribute outlook {sunny, overcast, rainy}
@attribute temperature real
@attribute humidity real
@attribute windy {TRUE, FALSE}
@attribute play {yes, no}
@data
sunny,85,85,FALSE,no
sunny,80,90,TRUE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
rainy,68,80,FALSE,yes
rainy,65,70,TRUE,no
overcast,64,65,TRUE,yes
sunny,72,95,FALSE,no
sunny,69,70,FALSE,yes
rainy,75,80,FALSE,yes
sunny,75,70,TRUE,yes
overcast,72,90,TRUE,yes
overcast,81,75,FALSE,yes
rainy,71,91,TRUE,no
Run Code Online (Sandbox Code Playgroud)
要创建逻辑回归模型,我使用命令:java -cp $ WEKA_INS/weka.jar weka.classifiers.functions.Logistic -t $ WEKA_INS/data/weather.numeric.arff -T $ WEKA_INS/data/weather.numeric.arff - d ./weather.numeric.model.arff
这三个论点意味着:
-t <name of training file> : Sets training file.
-T <name of test file> : Sets test file.
-d <name of output file> : Sets model output …Run Code Online (Sandbox Code Playgroud) 在Scala REPL中,可以找到值类型:
scala> val x = 1
x: Int = 1
scala> :t x
Int
Run Code Online (Sandbox Code Playgroud)
但是Scala REPL没有显示函数的类型信息:
scala> def inc(x:Int) = x + 1
inc: (x: Int)Int
scala> :t inc
<console>:9: error: missing arguments for method inc;
follow this method with `_' if you want to treat it as a partially applied function
inc
^
<console>:9: error: missing arguments for method inc;
follow this method with `_' if you want to treat it as a partially applied function
inc
^ …Run Code Online (Sandbox Code Playgroud) 从git获取代码后clone https://github.com/twitter/scalding.git,./sbt update我得到:
::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.hadoop.gplcompression#hadoop-lzo;0.4.16: not found
Run Code Online (Sandbox Code Playgroud)
然后:
sbt.ResolveException: unresolved dependency: com.hadoop.gplcompression#hadoop-lzo;0.4.16: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:213)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:116)
Run Code Online (Sandbox Code Playgroud)
我已经删除了~/.sbt目录,重新安装了最新的Scala和克隆的存储库.问题仍然存在.
我的配置:
[dk@localhost scalding]$ scala -version
Scala code runner version 2.10.3 -- Copyright 2002-2013, LAMP/EPFL
[dk@localhost scalding]$ uname -a
Linux localhost.localdomain 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
CentOS 6.5 (Final)
Run Code Online (Sandbox Code Playgroud)
什么可能是错的./sbt update?我应该hadoop-lzo单独安装依赖项并设置CLASSPATH来安装Scalding吗?还有其他方法吗? …
按照http://www.simplyscala.com/上的一个简单示例,我得到:
scala> val lst=List(1,7,2,8,5,6,3,9,14,12,4,10)
lst: List[Int] = List(1, 7, 2, 8, 5, 6, 3, 9, 14, 12, 4, 10)
scala> lst.sort(_>_)
<console>:9: error: value sort is not a member of List[Int]
lst.sort(_>_)
Run Code Online (Sandbox Code Playgroud)
怎么了?谢谢!
Scala REPL非常适合尝试不同的代码片段.如果可以使用Scala REPL中Maven存储库中的库运行代码,那将是很棒的.如何将远程Maven存储库添加到Scala REPL类路径?
我试图使用Weka的NaiveBayesUpdateable分类器.我的数据包含名义和数字属性:
@relation cars
@attribute country {FR, UK, ...}
@attribute city {London, Paris, ...}
@attribute car_make {Toyota, BMW, ...}
@attribute price numeric %% car price
@attribute sales numeric %% number of cars sold
Run Code Online (Sandbox Code Playgroud)
我需要根据其他属性预测销售数量(数字!).
据我所知,我不能在Weka中使用数字属性进行贝叶斯分类.一种技术是在长度为k的N个区间中分割数值属性的值,而使用标称属性,其中n是类名,如下所示:@attribute class {1,2,3,... N}.
然而,我需要预测的数字属性范围从0到1 000 000.创建1 000 000个类根本没有任何意义.如何用Weka预测数字属性或者在Weka没有这个任务的工具的情况下寻找什么算法?
什么是易于阅读和理解,Scala代码根据以下Java代码加载Java属性:
try {
Properties prop = new Properties();
prop.load(new FileInputStream("config.properties"));
this.host = prop.getProperty("mongo.host");
this.port = new Integer(prop.getProperty("mongo.port"));
this.dbName = prop.getProperty("mongo.db");
this.docsCollName = prop.getProperty("mongo.coll.docs");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
如何在UIWebView中添加侦听器到DOM事件?例如,对于以下html:
<button type="button" id="button1">Try it</button>
Run Code Online (Sandbox Code Playgroud)
是否可以在IOS应用程序中为按钮单击事件注册一个侦听器,该应用程序在UIWebView中加载html?
对我来说,(行< - 行)是如此具有破坏性!它完全展开了行迭代器.因此,运行以下代码段将使size = 0:
val lines = Source.fromFile(args(0)).getLines()
var cnt = 0
for (line <- lines) {
cnt = readLines(line, cnt)
}
val size = lines.size
Run Code Online (Sandbox Code Playgroud)
像这样具有隐藏的副作用是正常的Scala练习吗?
用foldl它来查看代码很难理解它的语法,例如:
def lstToMap(lst:List[(String,Int)], map: Map[String, Int] ):Map[String, Int] = {
(map /: lst) (addToMap)
}
Run Code Online (Sandbox Code Playgroud)
是中/:缀运营商?什么(map /: lst)意思,部分申请?为什么我不能这样打电话:
`/: map lst addToMap`
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用foldl将列表中的对添加到地图中.我收到以下错误:
"missing arguments for method /: in trait TraversableOnce; follow this method with `_' if you want to treat it as a partially applied function"
Run Code Online (Sandbox Code Playgroud)
码:
val pairs = List(("a", 1), ("a", 2), ("c", 3), ("d", 4))
def lstToMap(lst:List[(String,Int)], map: Map[String, Int] ) = {
(map /: lst) addToMap ( _, _)
}
def addToMap(pair: (String, Int), map: Map[String, Int]): Map[String, Int] = {
map + (pair._1 -> pair._2)
}
Run Code Online (Sandbox Code Playgroud)
怎么了?