我有一个DataFrame架构
root
|-- label: string (nullable = true)
|-- features: struct (nullable = true)
| |-- feat1: string (nullable = true)
| |-- feat2: string (nullable = true)
| |-- feat3: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
同时,我能够使用过滤数据框
val data = rawData
.filter( !(rawData("features.feat1") <=> "100") )
Run Code Online (Sandbox Code Playgroud)
我无法删除列
val data = rawData
.drop("features.feat1")
Run Code Online (Sandbox Code Playgroud)
这是我在这里做错了吗?我也试过(不成功)做drop(rawData("features.feat1")),虽然这样做没有多大意义.
提前致谢,
尼基尔
scala dataframe apache-spark apache-spark-sql apache-spark-ml
我正在将CSV文件(使用spark-csv)导入到DataFrame具有空String值的文件中.应用时OneHotEncoder,应用程序崩溃并出错requirement failed: Cannot have an empty string for name..有没有办法解决这个问题?
val df = sqlContext.createDataFrame(Seq(
(0, "a"),
(1, "b"),
(2, "c"),
(3, ""), //<- original example has "a" here
(4, "a"),
(5, "c")
)).toDF("id", "category")
val indexer = new StringIndexer()
.setInputCol("category")
.setOutputCol("categoryIndex")
.fit(df)
val indexed = indexer.transform(df)
val encoder = new OneHotEncoder()
.setInputCol("categoryIndex")
.setOutputCol("categoryVec")
val encoded = encoder.transform(indexed)
encoded.show()
Run Code Online (Sandbox Code Playgroud)
这很烦人,因为缺失/空值是一种非常普遍的情况.
提前谢谢,Nikhil
scala apache-spark spark-csv apache-spark-ml apache-spark-mllib
我正在查看Spark 1.5 dataframe/row api和逻辑回归的实现.据我所知,train其中的方法首先将其转换dataframe为RDD[LabeledPoint]as,
override protected def train(dataset: DataFrame): LogisticRegressionModel = {
// Extract columns from data. If dataset is persisted, do not persist oldDataset.
val instances = extractLabeledPoints(dataset).map {
case LabeledPoint(label: Double, features: Vector) => (label, features)
}
...
Run Code Online (Sandbox Code Playgroud)
然后它继续进行功能标准化等.
我很困惑与是,该DataFrame类型是RDD[Row]并Row允许有任何valueTypes,对于例如(1, true, "a string", null)似乎是一个数据帧的有效行.如果是这样,extractLabeledPoints以上是什么意思?它似乎只选择Array[Double]作为特征值Vector.如果数据框中的列是什么,会发生什么strings?此外,整数分类值会发生什么?
提前谢谢,Nikhil
apache-spark apache-spark-sql apache-spark-ml apache-spark-mllib
我有一个字符串(有一些固定长度),我需要压缩然后比较压缩长度(作为数据冗余的代理或作为Kolmogorov复杂度的粗略近似).目前,我正在使用boost :: iostreams进行压缩,这似乎运行良好.但是,我不知道如何获取压缩数据的大小.有人可以帮帮忙吗?
代码片段是
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/filesystem.hpp>
#include <string>
#include <sstream>
namespace io = boost::iostreams;
int main() {
std::string memblock;
std::cout << "Input the string to be compressed:";
std::cin >> memblock;
std::cout << memblock << std::endl;
io::filtering_ostream out;
out.push(io::gzip_compressor());
out.push(io::file_descriptor_sink("test.gz"));
out.write (memblock.c_str(), memblock.size());
std::cout << out.size() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个已经在iOS 6上进行了广泛测试并且运行良好的应用程序,而在iOS 7上它几乎总是崩溃(但不是100%)Thread 1: EXC_BAD_ACCESS主要错误,没有太多的痕迹.我完全不知道它的下落.我相信我的代码中的某些内容与iOS核心方法不兼容.
我能够识别的最好的是,在评论代码的以下部分时,一切运行良好.
UIGraphicsBeginImageContext(coverView.bounds.size);
[coverView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *coverImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[UIImageJPEGRepresentation(coverImage, 0.8f) writeToFile:coverFilePath atomically:YES];
//Create thumbnail of cover image
CGSize size = CGSizeMake(116.0f, 152.0f);
UIGraphicsBeginImageContext(size);
[coverImage drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)];
coverImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[UIImageJPEGRepresentation(coverImage, 0.8f) writeToFile:coverThumbnailFilePath atomically:YES];
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我下一步要调试的地方吗?请注意,同样的应用程序在iOS 6中运行得非常好,而且这个bug非常适合iOS 7.
编辑:附加僵尸堆栈跟踪:到目前为止我无法使用它,但可能对专家眼睛有用:)

提前致谢,
尼基尔
当我运行这个简单的代码时,
int main(int argc, const char * argv[])
{
bool digit(true);
std::cout << digit << " " << ~digit << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
输出是
1 -2
Run Code Online (Sandbox Code Playgroud)
我期待1和0(对于真和假).我在这里错过了什么吗?