在Spark中使用Scala时,每当我使用结果转储结果时saveAsTextFile,它似乎将输出分成多个部分.我只是将一个参数(路径)传递给它.
val year = sc.textFile("apat63_99.txt").map(_.split(",")(1)).flatMap(_.split(",")).map((_,1)).reduceByKey((_+_)).map(_.swap)
year.saveAsTextFile("year")
Run Code Online (Sandbox Code Playgroud)
在下面的例子中,i有函数范围.但似乎我不能i在第二个for循环使用.为什么不起作用for (i : v1),但for (int i : v1)有效?
#include<iostream>
#include<string>
#include<vector>
int main()
{
std::vector<int> v1;
int i;
while(std::cin>>i)
{
v1.push_back(i);
}
for(i : v1) //for (int i:v1) works
std::cout<<i<<"\t";
cout<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 时间序列分解是将时间序列数据集分成三个(或更多)分量的方法.例如:
x(t) = s(t) + m(t) + e(t)
Run Code Online (Sandbox Code Playgroud)
哪里
t is the time coordinate
x is the data
s is the seasonal component
e is the random error term
m is the trend
Run Code Online (Sandbox Code Playgroud)
Scikit-learn采用了一种非常方便的方法fit和predict方法.我有适合fit和的格式的时间序列数据predict.
例如,我有以下内容Xs:
[[1.0, 2.3, 4.5], [6.7, 2.7, 1.2], ..., [3.2, 4.7, 1.1]]
Run Code Online (Sandbox Code Playgroud)
和相应的ys:
[[1.0], [2.3], ..., [7.7]]
Run Code Online (Sandbox Code Playgroud)
这些数据具有以下含义.存储的值ys形成时间序列.值Xs是对应的时间相关"因子",已知这些因素对值ys(例如:温度,湿度和大气压力)有一些影响.
现在,当然,我可以使用fit(Xs,ys).但后来我得到了一个模型,其中未来的值ys仅依赖于因子,并且不依赖于先前的Y值(至少直接),这是模型的限制.我想有其中一个模型Y_n也依赖Y_{n-1}和Y_{n-2}等.例如,我可能想使用指数移动平均线作为模型.在scikit-learn中最优雅的方法是什么
添加
正如评论中提到的那样,我可以Xs通过添加来扩展ys.但这种方式有一些局限性.例如,如果我将最后5个值添加y为5个新列X,则有关时间排序的信息ys将丢失.例如,没有迹象表明X第5列中的值跟随第4列中的值,依此类推.作为一个模型,我可能希望得到最后五个的线性拟合,ys并使用找到的线性函数进行预测.但如果我在5列中有5个值,那就不是那么简单了.
增加2
为了使我的问题更加清楚,我想举一个具体的例子.我想有一个"线性"模型y_n = c + k1*x1 + k2*x2 + k3*x3 + k4*EMOV_n,其中EMOV_n只是一个指数移动平均线.怎样,我可以在scikit-learn中实现这个简单的模型吗?
我需要能够基于线性回归模型创建一个用于预测的python函数,并在时间序列数据上使用置信带:
该函数需要一个参数来指定预测的距离.例如1天,7天,30天,90天等.根据参数,它将需要创建带有置信区段的Holt-Winters预测:
我的时间序列数据如下所示:
print series
[{"target": "average", "datapoints": [[null, 1435688679], [34.870499801635745, 1435688694], [null, 1435688709], [null, 1435688724], [null, 1435688739], [null, 1435688754], [null, 1435688769], [null, 1435688784], [null, 1435688799], [null, 1435688814], [null, 1435688829], [null, 1435688844], [null, 1435688859], [null, 1435688874], [null, 1435688889], [null, 1435688904], [null, 1435688919], [null, 1435688934], [null, 1435688949], [null, 1435688964], [null, 1435688979], [38.180000209808348, 1435688994], [null, 1435689009], [null, 1435689024], [null, 1435689039], [null, 1435689054], [null, 1435689069], [null, 1435689084], [null, 1435689099], [null, 1435689114], [null, 1435689129], [null, 1435689144], [null, 1435689159], [null, 1435689174], [null, 1435689189], [null, 1435689204], …Run Code Online (Sandbox Code Playgroud) 我希望以下内容可以buf_iter指向角色n字符开始后的点.相反,它指向最后一个字符读取.为什么是这样?也就是说,如果我在copy_n之前和之后进行in_stream.tellg(),它们的区别不n在于(n-1).如果我用n字符读取字符in_stream.read,那么该位置将被提前n.
std::istreambuf_iterator<char> buf_iter(in_stream);
std::copy_n(buf_iter, n, sym.begin());
Run Code Online (Sandbox Code Playgroud)
我已经查看了实现,它显然是故意这样做的,跳过最后的增量.
这里的另一篇文章提到,当迭代器连接起来时,从迭代器开始递增cin会导致读取次数过多而导致读取次数过多operator++().这听起来像是一个问题cin- 为什么不进行读取operator*()?
标准是否在任何地方指定了它?我见过的文档没有提到from迭代器会发生什么,我看到两个不同的页面提供了"可能正确的实现",它们执行每个行为:
template< class InputIt, class Size, class OutputIt>
OutputIt copy_n(InputIt first, Size count, OutputIt result)
{
if (count > 0) {
*result++ = *first;
for (Size i = 1; i < count; ++i) {
*result++ = *++first;
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
template<class InputIterator, class …Run Code Online (Sandbox Code Playgroud) 我在包中有一个文件名中带有“test”,当我运行 pytest 时出现错误
import file mismatch:
imported module 'my_project.my_file_test' has this __file__ attribute:
/my_project/src/my_project/build/lib/python2.7/site-packages/foo/my_file_test.py
which is not the same as the test file we want to collect:
/my_project/src/my_project/build/private/python2.7/lib/foo/my_file_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
Run Code Online (Sandbox Code Playgroud)
如果我从文件中删除“测试”,它可以正常工作,但不幸的是我无法更改它。
所以问题是如何告诉pytest忽略这个文件?
我的一个朋友问我哪个会加载第一个静态变量或静态块.
我的答案指向静态变量.
所以他给了我两个方程,并说要区分它们的
第一个方程式
public class Some {
public static void main(String args[])
{
System.out.println(Some.x);
}
static {
System.out.println(Some.x);
}
static int x=90;
}
Run Code Online (Sandbox Code Playgroud)
O/P:0 90
第二个等式
public class Some {
public static void main(String args[])
{
System.out.println(Some.x);
}
static int x=90;
static {
System.out.println(Some.x);
}
}
Run Code Online (Sandbox Code Playgroud)
O/P:90 90
我试图反编译字节码,发现它对于上述两个方程都是一样的.请帮我区分它们.当静态变量初始化时我很困惑.
我目前正在使用以下代码查看决策树.有没有办法我们可以将一些计算字段输出为输出?
例如,是有可能在树的叶子在每个节点显示输入属性的总和,特征1的从"X"的数据数组,即总和.
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data[:]
y = iris.target
#%%
from sklearn.tree import DecisionTreeClassifier
alg=DecisionTreeClassifier( max_depth=5,min_samples_leaf=2, max_leaf_nodes = 10)
alg.fit(X,y)
#%%
## View tree
import graphviz
from sklearn import tree
dot_data = tree.export_graphviz(alg,out_file=None, node_ids = True, proportion = True, class_names = True, filled = True, rounded = True)
graph = graphviz.Source(dot_data)
graph
Run Code Online (Sandbox Code Playgroud)
python ×5
c++ ×2
scikit-learn ×2
time-series ×2
algorithm ×1
apache-spark ×1
c++11 ×1
clion ×1
cmake ×1
core ×1
java ×1
pygraphviz ×1
pytest ×1
pytest-cov ×1
scala ×1
stack ×1
static ×1
stl ×1