是否有一些技巧可以让人们使用bc(或其他一些标准实用程序)来返回任意数量的数字的标准偏差?为方便起见,假设数字以下列方式存储在Bash变量中:
myNumbers="0.556
1.456
45.111
7.812
5.001"
Run Code Online (Sandbox Code Playgroud)
所以,我正在寻找的答案将采用如下形式:
standardDeviation="$(echo "${myNumbers}" | <insert magic here>)"
Run Code Online (Sandbox Code Playgroud) 我想提前澄清我正在寻找一种使用Streams计算标准偏差的方法(我目前有一种计算和返回SD但不使用Streams的工作方法).
我正在使用的数据集与Link中的匹配密切相关.如此链接所示,我能够对数据进行分组并获得平均值但无法弄清楚如何获得SD.
码
outPut.stream()
.collect(Collectors.groupingBy(e -> e.getCar(),
Collectors.averagingDouble(e -> (e.getHigh() - e.getLow()))))
.forEach((car,avgHLDifference) -> System.out.println(car+ "\t" + avgHLDifference));
Run Code Online (Sandbox Code Playgroud)
我还检查了DoubleSummaryStatistics上的Link,但它似乎对SD没有帮助.
我想编写一个将时间序列和标准偏差作为参数并返回调整后的时间序列的函数,该时间序列看起来像是预测。
使用此功能,我想测试系统的稳定性,该系统将获取天气预报的时间序列表作为输入参数。
我对这种功能的使用方法,如下所述:
vector<tuple<datetime, double>> get_adjusted_timeseries(vector<tuple<datetime, double>>& timeseries_original, const double stddev, const double dist_mid)
{
auto timeseries_copy(timeseries_original);
int sign = randInRange(0, 1) == 0 ? 1 : -1;
auto left_limit = normal_cdf_inverse(0.5 - dist_mid, 0, stddev);
auto right_limit = normal_cdf_inverse(0.5 + dist_mid, 0, stddev);
for (auto& pair : timeseries_copy)
{
double number;
do
{
nd_value = normal_distribution_r(0, stddev);
}
while (sign == -1 && nd_value > 0.0 || sign == 1 && nd_value < 0.0);
pair = make_tuple(get<0>(pair), get<1>(pair) + …Run Code Online (Sandbox Code Playgroud) c++ normal-distribution prediction forecasting standard-deviation
我试图使用StDev函数,并得到空白结果.我用它作为......
SELECT StDev(fldMean) FROM myTable
Run Code Online (Sandbox Code Playgroud)
其中fldMean包含值2.3并且应该计算为0但是我只是得到一个空结果.我似乎无法理解如何在函数中使用表达式,微软的手册确实无济于事.
所以我发布了几次,以前我的问题很模糊
我本周开始使用C++,并且做了一个小项目
所以我试图计算标准偏差和方差
我的代码加载一个100个整数的文件,并将它们放入一个数组,计算它们,计算平均值,总和,var和sd
但我的方差有点麻烦
我不断得到一个巨大的数字 - 我感觉它与它的计算有关
我的意思和总和还可以
任何帮助或提示?
注意:
干杯,
插口
using namespace std;
int main()
{
int n = 0;
int Array[100];
float mean;
float var;
float sd;
string line;
float numPoints;
ifstream myfile(“numbers.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline(myfile, line);
stringstream convert(line);
if (!(convert >> Array[n]))
{
Array[n] = 0;
}
cout << Array[n] << endl;
n++;
}
myfile.close();
numPoints = n;
}
else cout<< "Error loading file" <<endl;
int sum = accumulate(begin(Array), end(Array), 0, …Run Code Online (Sandbox Code Playgroud) 是否有其他人rolling.std()在熊猫中遇到新问题?弃用的方法是rolling_std().新方法运行正常但产生一个不随时间序列滚动的常数.
示例代码如下.如果您交易股票,您可能会认识到布林带的公式.我得到的输出rolling.std()每天跟踪股票,显然没有滚动.
这在大熊猫0.19.1.任何帮助,将不胜感激.
import datetime
import pandas as pd
import pandas_datareader.data as web
start = datetime.datetime(2012,1,1)
end = datetime.datetime(2012,12,31)
g = web.DataReader(['AAPL'], 'yahoo', start, end)
stocks = g['Close']
stocks['Date'] = pd.to_datetime(stocks.index)
stocks['AAPL_LO'] = stocks['AAPL'] - stocks['AAPL'].rolling(20).std() * 2
stocks['AAPL_HI'] = stocks['AAPL'] + stocks['AAPL'].rolling(20).std() * 2
stocks.dropna(axis=0, how='any', inplace=True)
Run Code Online (Sandbox Code Playgroud) 假设我有一批尺寸为 (B x C x W x H) 的张量形式的图像,其中 B 是批量大小,C 是图像中的通道数,W 和 H 是宽度和高度图像分别。我希望使用该transforms.Normalize()函数根据跨 C 图像通道的数据集的均值和标准差对我的图像进行归一化,这意味着我想要 1 x C 形式的结果张量。 有没有直接的方法这个?
我试过了torch.view(C, -1).mean(1),torch.view(C, -1).std(1)但出现错误:
view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
Run Code Online (Sandbox Code Playgroud)
编辑
在研究了view()PyTorch 的工作原理后,我知道为什么我的方法不起作用;但是,我仍然无法弄清楚如何获得每个通道的平均值和标准偏差。
我试图获得用户输入字符串的标准偏差.我有如下,但它返回错误的SD值.计算应如下所示:总和值/数值=均方(每个值均值相加)求和/数值.
协助表示赞赏(如有可能,请予以解释)
function sum() {
var val = document.getElementById('userInput').value;
var temp = val.split(" ");
var total = 0;
var v;
var mean = total / temp.length;
var total1 = 0;
var v1;
var temp23;
var square;
for (var i = 0; i < temp.length; i++) {
v = parseFloat(temp[i]);
total += v;
}
mean = total / temp.length;
for (var i = 0; i < temp.length; i++) {
v1 = parseFloat(Math.pow(temp[i] - mean), 2);
total1 += v1;
}
temp23 = …Run Code Online (Sandbox Code Playgroud)我有具有离散x值的数据,例如
x = c(3,8,13,8,13,3,3,8,13,8,3,8,8,13,8,13,8,3,3,8,13,8,13,3,3)
y = c(4,5,4,6,7,20,1,4,6,2,6,8,2,6,7,3,2,5,7,3,2,5,7,3,2);
Run Code Online (Sandbox Code Playgroud)
如何生成x和y值的新数据集,其中我消除了值对,其中y值比该bin的平均值高2个标准偏差.例如,在x = 3 bin中,20比平均值高2个SD以上,因此应删除数据点.
我想从OLS模型中找到样本外预测的标准偏差和置信区间.
此问题类似于模型预测的置信区间,但明确侧重于使用样本外数据.
这个想法是针对一个函数wls_prediction_std(lm, data_to_use_for_prediction=out_of_sample_df),它返回prstd, iv_l, iv_u样本数据帧之外的函数.
例如:
import pandas as pd
import random
import statsmodels.formula.api as smf
from statsmodels.sandbox.regression.predstd import wls_prediction_std
df = pd.DataFrame({"y":[x for x in range(10)],
"x1":[(x*5 + random.random() * 2) for x in range(10)],
"x2":[(x*2.1 + random.random()) for x in range(10)]})
out_of_sample_df = pd.DataFrame({"x1":[(x*3 + random.random() * 2) for x in range(10)],
"x2":[(x + random.random()) for x in range(10)]})
formula_string = "y ~ x1 + x2"
lm = smf.ols(formula=formula_string, data=df).fit()
# …Run Code Online (Sandbox Code Playgroud) python linear-regression confidence-interval standard-deviation statsmodels
python ×3
c++ ×2
arrays ×1
average ×1
bash ×1
forecasting ×1
java ×1
java-8 ×1
java-stream ×1
javascript ×1
mean ×1
ms-access ×1
pandas ×1
prediction ×1
pytorch ×1
r ×1
sql ×1
statsmodels ×1
variables ×1
variance ×1