mean

How should I calculate the average speed by road segment for multiple segments?

不打扰是莪最后的温柔 提交于 2019-12-02 13:44:54
I have a table of driver speeds and road segments: driver_lpr | segment | speed 0000001 | A | 30 0000002 | B | 60 0000003 | A | 50 0000004 | A | 100 0000005 | B | 60 And I want to have a table of average speed per segment segment | average speed A | 47.368 B | 60 How can this be done in SQL ? Uri Goren When averaging speeds, the harmonic mean is in need. The straight forward AVG() approach is wrong, the arithmetic mean yields the wrong result for average velocity. There is no predefined function for the harmonic mean, but it could be achieved with this query: SELECT segment, COUNT(*)/SUM(1e0

calcuate the mean of trials for each subject in R

南楼画角 提交于 2019-12-02 13:18:33
问题 This is my first time on stack. I have tried searching for an answer but i can't seem to find anything relevant. I hope someone can help. I have a dataframe here: each subject does 6 trials, there are 105 subjects. I want to find the mean of 'skip' for 6 trials for each subj. Please can someone give me a hint as to how to start. > subj entropy n_gambles trial choice 1 0 high 2 0 skip 2 0 high 2 1 skip 3 0 high 2 2 skip 4 0 high 2 3 skip 5 0 high 2 4 skip 6 0 high 2 5 skip 7 1 high 32 0 buy 8

深度学习:mAP(mean average precision)

十年热恋 提交于 2019-12-02 11:40:25
mAP是指平均准确率,是机器学习中模型好坏的一种评价指标。在介绍mAP前应该首先了解几个概念: 1、P (percision) 准确率,在周志华的《机器学习》中,称为“查准率”。在信息检索中,准确率是指我检索出的信息有多少比例是用户感兴趣的。   P = 系统检索到的相关文件 / 系统检索到的文件总数 2、R (recall) 召回率,又称为“查全率”,指用户感兴趣的信息有多少被检测出来了   R = 系统检测到的相关文件 / 数据库中相关文件总数 举个例子来说,某数据库中有1000个文件,我要搜索跟机器学习相关的文件,而数据库中机器学习相关文件有200个。搜索后,系统检索出100个文件,80个跟机器学习相关,那么:   P(准确率) = 80 / 100 = 80% R(召回率)= 80 / 200 = 40% 在改变检索算法后,再进行一次检索,结果检索出180个文件,机器学习相关文件有120个,那么:   P(准确率)= 120 / 180 = 66.7%   R(召回率)= 120 / 200 = 60% 这两个算法到底哪个算法好呢,很难单一的用准确率或召回率来评判。 准确率和召回率一般有如下特点:准确率高,召回率就低。召回率高,准确率就低。这个也比较容易理解,比如要获得较高的召回率,势必要搜索出大量文件,还是上面那个例子,我搜索出500个文件,其中200个跟机器学习相关

How to calculate the mean of specific rows in R?

夙愿已清 提交于 2019-12-02 11:37:27
问题 I have a data file as following example but much more larger names num Y1 Y2 William 1 4.71 7.4 William 2 3.75 8 William 3 4.71 7.9 Katja 1 5.83 8.5 Katja 2 5.17 7.1 Katja 3 6.08 7.4 Aroma 1 4.04 7.5 Aroma 2 5 6.9 Aroma 3 4.3 7.9 ... I have to calculate the mean for each 3 of the same names (first column) for Y1 and Y2. And then make a bar chart by the average of each name with Y1 and Y2, separately. So on the x axis I will have the names and on the y axis the mean. Could anybody help me with

How do I find the rolling mean since the beginning of data using R?

。_饼干妹妹 提交于 2019-12-02 11:22:55
问题 I am trying to find the rolling mean since the beginning of the data: samp <- structure(list(samp = c(0.25, 0.4868, 0.6043, 0.5184, -0.3572, 0.4685, 0.8264, 0.8445, 0.1331, 0.293, 0.4756, 0.866, 0.6461, 0.0401, 0.0054, 0.0744, 0.6973, 0.6304, 0.5488, 0.5468, -0.2565, 0.2557, 0.0557, 0.3347, 0.7584, 0.3547, 0.2577, 0.1238, 0.2184, 0.5956, 0.4695, 0.6517, 0.7003, 0.8364, 0.5869, 0.4403, 0.538, 0.6168, 1.0843, 1.1801, 0.617, 0.8869, 0.8073, 0.7787, 0.5705, 0.8436, 0.8202, 0.847, 0.8608, 0.8978,

How to handle more than multiple sets of data in R programming?

不羁的心 提交于 2019-12-02 11:18:52
Ca data <- cut(data$Time, breaks=seq(0, max(data$Time)+400, 400))  by(data$Oxytocin, cuts, mean) but this would only work for only one person's data....But I have ten people with their own Time and oxytocin data....How would I get their averages simultaneously? Also instead of having this type output : cuts: (0,400] [1] 0.7 ------------------------------------------------------------ cuts: (400,800] [1] 0.805 Is there a way I can get a list of those cuts? Here's a solution using IRanges package. idx assumes your data format is Time , data , Time , data , ... and so on.. So, it creates indices

I want to calculate the mean of two rows in matlab

大城市里の小女人 提交于 2019-12-02 10:35:26
I have a 1028 by 18 matrix in matlab.I want to calculate the mean of 1st and 2nd row by column values,3rd and 4th and so on in Matlab and get a new matrix with the mean values. I think you want to calculate the column-wise mean of every pair of rows. Reshape the array to be 2 x 18*1028/2, calculate the mean (which operates column-wise), and reshape the result to be 1028/2 x 18: >> x = rand(1028, 18); >> result = reshape(x, 2, 1028/2*18); >> result = mean(result); >> result = reshape(result, 1028/2, 18); A quick test to demonstrate the speed of vectorized solution compared to a for-loop over

How to average columns based on ID in R? [duplicate]

核能气质少年 提交于 2019-12-02 10:09:38
问题 This question already has answers here : how to calculate mean/median per group in a dataframe in r [duplicate] (5 answers) Summarizing multiple columns with dplyr? [duplicate] (5 answers) Closed 4 years ago . I want to average the values by their IDs but not all ID's have the same number of values. How do I do this in R? I have two columns ID and Value ID Value 1000 0.51 1000 0.01 1001 0.81 1001 0.41 1001 0.62 1002 0.98 1002 0.12 1002 0.15 1003 0.12 ... ... 回答1: You can try by() : > with(df,

基本统计值计算

Deadly 提交于 2019-12-02 09:12:56
“基本统计值计算” 问题分析 1.1 问题分析 基本统计值 需求:给出一组数,对它们有一个概要理解 总个数,求和,平均值,方差,中位数 总个数(len) 求和:for ... in 平均值:求和/总个数 方差:各数据与平均数差的平方的和的平均数 中位数:排序然后 奇数找中间1个,偶数找中间2个取平均 二 “基本统计值计算的实例讲解” 获取多数据输入 通过函数分隔功能 def get_nums(): """获取数据""" nums = [] num = input('请输入数字:').strip() while num != '': nums.append(num) num = input('请输入数字:').strip() return nums def get_len(nums): """获取长度""" count = 0 for num in nums: count += 1 return count # nums = get_num() # print(get_len(nums)) def get_add(nums): """求和""" sum = 0 for num in nums: sum += eval(num) return sum # nums = get_num() # print(get_add(nums)) def get_mean(nums): ""

Pandas: Calculate mean leaving out own row's value

被刻印的时光 ゝ 提交于 2019-12-02 08:00:43
问题 I want to calculate means by group, leaving out the value of the row itself. import pandas as pd d = {'col1': ["a", "a", "b", "a", "b", "a"], 'col2': [0, 4, 3, -5, 3, 4]} df = pd.DataFrame(data=d) I know how to return means by group: df.groupby('col1').agg({'col2': 'mean'}) Which returns: Out[247]: col1 col2 1 a 4 3 a -5 5 a 4 But what I want is mean by group, leaving out the row's value. E.g. for the first row: df.query('col1 == "a"')[1:4].mean() which returns: Out[251]: col2 1.0 dtype: