mean

Pandas: using groupby to get mean for each data category

这一生的挚爱 提交于 2019-11-28 02:05:44
I have a dataframe that looks like this: >>> df[['data','category']] Out[47]: data category 0 4610 2 15 4610 2 22 5307 7 23 5307 7 25 5307 7 ... ... ... Both data and category are numeric so I'm able to do this: >>> df[['data','category']].mean() Out[48]: data 5894.677985 category 13.805886 dtype: float64 And i'm trying to get the mean for each category. It looks straight forward but when I do this: >>> df[['data','category']].groupby('category').mean() or >>> df.groupby('category')['data'].mean() It returns an error like this: DataError: No numeric types to aggregate There's no error if I

pd.rolling_mean becoming deprecated - alternatives for ndarrays

僤鯓⒐⒋嵵緔 提交于 2019-11-27 22:09:57
问题 It looks like pd.rolling_mean is becoming deprecated for ndarrays , pd.rolling_mean(x, window=2, center=False) FutureWarning: pd.rolling_mean is deprecated for ndarrays and will be removed in a future version but it seems to be the fastest way of doing this, according to this SO answer. Are there now new ways of doing this directly with SciPy or NumPy that are as fast as pd.rolling_mean ? 回答1: EDIT -- Unfortunately, it looks like the new way is not nearly as fast: New version of Pandas: In [1

z-Scores(standard deviation and mean) in PHP

天涯浪子 提交于 2019-11-27 20:39:45
I am trying to calculate Z-scores using PHP. Essentially, I am looking for the most efficient way to calculate the mean and standard deviation of a data set (PHP array). Any suggestions on how to do this in PHP? I am trying to do this in the smallest number of steps. to calculate the mean you can do: $mean = array_sum($array)/count($array) standard deviation is like so: // Function to calculate square of value - mean function sd_square($x, $mean) { return pow($x - $mean,2); } // Function to calculate standard deviation (uses sd_square) function sd($array) { // square root of sum of squares

MATLAB Accumarray weighted mean

∥☆過路亽.° 提交于 2019-11-27 18:34:47
问题 So I am currently using 'accumarray' to find the averages of a range of numbers wich correspond to matching ID's. Ex Input: ID----Value 1 215 1 336 1 123 2 111 2 246 2 851 My current code finds the unweighted average of the above values, using the ID as the 'seperator' so that I don't get the average for all of the values together as one number, but rather seperate results for just values which have corresponding ID's. EX Output: ID----Value 1 224.66 2 402.66 To achieve this I am using this

R - min, max and mean of off-diagonal elements in a matrix

邮差的信 提交于 2019-11-27 18:16:21
问题 I have like a matrix in R and I want to get: Max off - diagonal elements Min off – diagonal elements Mean off –diagonal elements With diagonal I used max(diag(A)) , min(diag(A)) , mean(diag(A)) and worked just fine But for off-diagonal I tried dataD <- subset(A, V1!=V2) Error in subset.matrix(A, V1 != V2) : object 'V1' not found to use: colMeans(dataD) # get the mean for columns but I cannot get dataD b/c it says object 'V1' not found Thanks! 回答1: Here the row() and col() helper functions are

Sort boxplot by mean (and not median) in R

拥有回忆 提交于 2019-11-27 17:55:14
问题 I have a simple boxplot, showing the distribution of a score for factor TYPE: myDataFrame = data.frame( TYPE=c("a","a","b","b","c","c"), SCORE=c(1,1,2,3,2,1) ) boxplot( SCORE~TYPE, data=myDataFrame ) The various types are shown in the order they have in the data frame. I'd like to sort the boxplot by the mean of SCORE in each TYPE (in the example above, the order should be a,c,b ). Any hint? 回答1: This is a job for reorder(): myDataFrame$TYPE <- with(myDataFrame, reorder(TYPE, SCORE, mean))

SSD检测几个小细节

让人想犯罪 __ 提交于 2019-11-27 16:41:57
目录 一. 抛砖引玉的Faster-RCNN 1.1 候选框的作用 1.2 下采样问题 二. SSD细节理解 2.1 六个LOSS 2.2 Anchor生成细节 2.3 Encode&&Decode 2.4 负样本挖掘 参考文献 之前感觉SSD很简单,这两天从头到尾把论文和源码都看了一下,发现之前很多细节都没掌握。 这篇文章只说一些之前遗漏的点,读者阅读有一定基础 @ 一. 抛砖引玉的Faster-RCNN 1.1 候选框的作用 之前看 Fast-RCNN 代码对 Selective Search 的操作一直有很大的疑惑? 为什么一张图会分割成这样大大小小的区域?分割后有啥意义呢? 第一个问题很简单,使用了 贪心算法 和 图论 方面的知识,区域合并等算法。 第二个问题到后来才明白,是深度学习的 学习成本 的问题。。。 看上图的 resnet 核心模块,就是降低了 学习成本 ,使得网络更容易学习 下面这张图预测区域通过两次平移到达目标区域 下面这张图预测区域先通过放大再做两次平移到达目标区域 下面这张图通过多个预测区域对不同的目标进行预测 通过上面的三幅图可以发现,回归的方式需要付出不同的 代价 当然代价越低越容易回归,可以看我之前的 文章EAST和改进的EAST ,就是通过回归的代价不同,最后效果提升挺大的。 最后一幅图,通过打不同的 回归点(Anchor)

calculating mean for every n values from a vector

吃可爱长大的小学妹 提交于 2019-11-27 14:54:56
So lets say I have a vector a <- rnorm(6000) I want to calculate the mean of the 1st value to the 60th, then again calculate the mean for the 61st value to the 120th and so fourth. So basically I want to calculate the mean for every 60th values giving me 100 means from that vector. I know I can do a for loop but I'd like to know if there is a better way to do this? I would use colMeans(matrix(a, 60)) .colMeans(a, 60, length(a) / 60) # more efficient (without reshaping to matrix) Enhancement on user adunaic 's request This only works if there are 60x100 data points. If you have an incomplete 60

express app server . listen all interfaces instead of localhost only

回眸只為那壹抹淺笑 提交于 2019-11-27 14:29:19
问题 I'm very new for this stuff, and trying to make some express app var express = require('express'); var app = express(); app.listen(3000, function(err) { if(err){ console.log(err); } else { console.log("listen:3000"); } }); //something useful app.get('*', function(req, res) { res.status(200).send('ok') }); When I start the server with the command: node server.js everything goes fine. I see on the console listen:3000 and when I try curl http://localhost:3000 I see 'ok'. When I try telnet

Mean Squared Error in Numpy?

无人久伴 提交于 2019-11-27 12:38:35
问题 Is there a method in numpy for calculating the Mean Squared Error between two matrices? I've tried searching but found none. Is it under a different name? If there isn't, how do you overcome this? Do you write it yourself or use a different lib? 回答1: You can use: mse = ((A - B)**2).mean(axis=ax) Or mse = (np.square(A - B)).mean(axis=ax) with ax=0 the average is performed along the row, for each column, returning an array with ax=1 the average is performed along the column, for each row,