mean

How to calculate mean of every three values of a list [closed]

痴心易碎 提交于 2020-01-28 11:31:48
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 13 days ago . I have a list: first = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] I want another list with mean of three values and so the new list be: new = [2,5,8,11,14,17] There will be only 6 values in the new list as there are only 18 elements in the first. I am looking for an elegant way to do this with

踩坑记----keras,训练准确率远高于验证准确率,keras底层代码解剖

吃可爱长大的小学妹 提交于 2020-01-28 04:16:50
前几天,帮朋友处理一个深度学习网络问题,具体场景是这样的,总共有12张,分为3个类别,同时作为训练集跟验证集,训练集跟验证集的预处理一样,使用的模型为ResNet50,最后的激活函数为softmax。使用keras框架,总共10个epoch,每个epoch都是只有1个batch(因为数据集就12张图片,所以一个batch也就12张图片)。 在训练前几个epoch时,训练准确率便达到100%,因为模型较为复杂,而且数据集也有12张,所以很好拟合,但验证准确率只有33%,也即出现训练准确率远高于验证准确率的问题, 在验证了 https://blog.csdn.net/qq_16564093/article/details/103563517 中提到可能出现的情况后,仍然未能解决问题。于是我花了三天时间去寻找答案。 接下来是我的问题解决思路: (1).模型是否出现过拟合现象 猜测,模型可能过于复杂,出现过拟合现象,导致模型过度拟合训练数据,而不适用于验证数据集。 于是,为了验证这个猜想,我将训练数据集与验证数据集统一使用同一份,即数据迭代器都是同一份数据,但结果,训练准确率依然远高于验证准确率,可推测,并非模型过度拟合训练数据集。于是,我用同一份数据,对模型进行测试,得出结果是,准确率只有33%,即可以说明一个问题,模型是完全未拟合,那么,问题,为什么模型的训练准确率能达到100%呢

特征工程&特征选择

白昼怎懂夜的黑 提交于 2020-01-26 06:43:59
特征工程 #核心代码举例 # 统计特征 #计算均值 gp = train . groupby ( by ) [ fea ] . mean ( ) #计算中位数 gp = train . groupby ( by ) [ fea ] . median ( ) #计算方差 gp = train . groupby ( by ) [ fea ] . std ( ) #计算最大值 gp = train . groupby ( by ) [ fea ] . max ( ) #计算最小值 gp = train . groupby ( by ) [ fea ] . min ( ) #计算出现次数 gp = train . groupby ( by ) [ fea ] . size ( ) # groupby生成统计特征:mean,std # 按照communityName分组计算面积的均值和方差 temp = data . groupby ( 'communityName' ) [ 'area' ] . agg ( { 'com_area_mean' : 'mean' , 'com_area_std' : 'std' } ) # 特征拆分 # 将houseType转为'Room','Hall','Bath' def Room ( x ) : Room = int ( x . split ( '室

3.1 Tensorflow: 批标准化(Batch Normalization)

前提是你 提交于 2020-01-26 04:31:18
BN 简介 背景 批标准化(Batch Normalization )简称BN算法,是为了克服神经网络层数加深导致难以训练而诞生的一个算法。根据ICS理论,当训练集的样本数据和目标样本集分布不一致的时候,训练得到的模型无法很好的泛化。 而在神经网络中,每一层的输入在经过层内操作之后必然会导致与原来对应的输入信号分布不同,,并且前层神经网络的增加会被后面的神经网络不对的累积放大。这个问题的一个解决思路就是根据训练样本与目标样本的比例对训练样本进行一个矫正,而BN算法(批标准化)则可以用来规范化某些层或者所有层的输入,从而固定每层输入信号的均值与方差。 使用方法 批标准化一般用在非线性映射(激活函数)之前,对 y= Wx + b 进行规范化,是结果(输出信号的各个维度)的均值都为0,方差为1,让每一层的输入有一个稳定的分布会有利于网络的训练 在神经网络收敛过慢或者梯度爆炸时的那个无法训练的情况下都可以尝试 优点 减少了参数的人为选择,可以取消dropout和L2正则项参数,或者采取更小的L2正则项约束参数 减少了对学习率的要求 可以不再使用局部响应归一化了,BN本身就是归一化网络(局部响应归一化-AlexNet) 更破坏原来的数据分布,一定程度上缓解过拟合 计算公式 其过程类似于归一化但是又不同. 参考 BN原理的详细参考建议:BN学习笔记:点击 这里 BN with TF 组成部分

Calculate Mean of Multiply Columns with Condition in R

こ雲淡風輕ζ 提交于 2020-01-25 20:21:25
问题 I want to calculate mean of several variables but with condition, if 2 of those columns have NA, mean will be NA, if less than 2, find mean df <- data.frame(ID = c(1:10),X1 = c(rep(1,5),rep(2,5)),X2 = c(1:10),X3 = c(1,NA,2,NA,NA,1,NA,2,NA,NA),X4 = c(rep(NA,10)),X5=c(rep(1,5),rep(NA,5)), Y1 = c(rep(1,5),rep(2,5)),Y2 = c(1:10),Y3 = c(1,NA,2,NA,NA,1,NA,2,NA,NA),Y4 = c(rep(NA,10)),Y5=c(rep(1,5),rep(NA,5))) MeanX = round(apply(df[,c(2:6)],1, mean,na.rm = TRUE),2) MeanY = round(apply(df[,c(7:11)],1

Calculate Mean of Multiply Columns with Condition in R

我们两清 提交于 2020-01-25 20:21:22
问题 I want to calculate mean of several variables but with condition, if 2 of those columns have NA, mean will be NA, if less than 2, find mean df <- data.frame(ID = c(1:10),X1 = c(rep(1,5),rep(2,5)),X2 = c(1:10),X3 = c(1,NA,2,NA,NA,1,NA,2,NA,NA),X4 = c(rep(NA,10)),X5=c(rep(1,5),rep(NA,5)), Y1 = c(rep(1,5),rep(2,5)),Y2 = c(1:10),Y3 = c(1,NA,2,NA,NA,1,NA,2,NA,NA),Y4 = c(rep(NA,10)),Y5=c(rep(1,5),rep(NA,5))) MeanX = round(apply(df[,c(2:6)],1, mean,na.rm = TRUE),2) MeanY = round(apply(df[,c(7:11)],1

基于贝叶斯估计的星级得分排名

风格不统一 提交于 2020-01-25 11:41:12
问题阐述 互联网早已成为人们生活的一部分,没事在网上看看电影、逛逛淘宝、定定外卖(有时间还是要多出去走走)。互联网的确为我们提供了非常多的便利,但它毕竟是一个虚拟的环境,具有更多的不确定性,大多数情况下我们只能通过别人的评论及打分来判别某个商品的好坏。五星打分是许多网站采用的商品排名方法,它也是消费者最直观最简单的评价尺度,我想大部分人都会去点击那些星级排名比较高的商品以最大限度降低我们的顾虑。 多数情况下,星级排名都能准确的反映一个商品的好坏,因为它是多人的一个综合得分,减小了个人偏好的影响。但是这里有一个前提条件,即打分的人要足够多。 考虑下面两种商品: 1.A商品的星级平均得分为5(1位评论者) 2.B商品的星级平均得分为4.1(87位评论者) A、B两种商品谁的得分排名更高呢?我想大部分都认为B应该排在A的前面吧,尽管B的平均星级得分要低于A,但是它有更多的体验人数,其得分更具有说服力。 现在我们已经明白,一个商品的排名应同时考虑它的星级得分与评论人数。那么我们应该如何将二者结合起来呢?也许会有人想到,我们可以给评论人数设定一个阀值,使得小于该阀值的商品,其排名会相对较低。上述过程可以使用下面的式子来表达: 这里的 m代表平均星级得分,n代表打分的人数,k代表修正的阀值。K值该如何确定呢,它在某些极端的情况下准吗?这些都有待进一步考证。这里我们不采用该方法

Reduce daily data in month and get the mean per month [duplicate]

房东的猫 提交于 2020-01-24 20:48:31
问题 This question already has answers here : Get monthly means from dataframe of several years of daily temps (3 answers) Closed 2 years ago . I have a daily data of precipitation for 10 years like this for the example only generate for 2 years A <- seq(as.Date("2008/1/1"), as.Date("2009/12/31"), by = "day") PP <- seq(1,731,1) PPday <- data.frame(A,PP) I manage to reduce de daily dates in month like this Date <- as.POSIXct(strptime(A,"%Y-%m-%d")) Datemonth <- seq.POSIXt(from=Date[1],to=Date[731]

sklearn 模型选择和评估

纵然是瞬间 提交于 2020-01-24 16:27:04
一、模型验证方法如下: 通过交叉验证得分:model_sleection.cross_val_score(estimator,X) 对每个输入数据点产生交叉验证估计:model_selection.cross_val_predict(estimator,X) 计算并绘制模型的学习率曲线:model_selection.learning_curve(estimator,X,y) 计算并绘制模型的验证曲线:model_selection.validation(estimator,...) 通过排序评估交叉验证的得分在重要性:model_selection.permutation_test_score(...) ①通过交叉验证得分:model_sleection.cross_val_score(estimator,X) import numpy as np from sklearn.model_selection import cross_val_score from sklearn import datasets,svm digits=datasets.load_digits() X=digits.data y=digits.target svc=svm.SVC(kernel='linear') C_s=np.logspace(-10,0,10) print("参数列表长度",len

The result of dataframe.mean() is incorrect

僤鯓⒐⒋嵵緔 提交于 2020-01-24 09:35:32
问题 I am workint in Python 2.7 and I have a data frame and I want to get the average of the column called 'c', but only the rows that verify that the values in another column are equal to some value. When I execute the code, the answer is unexpected, but when I execute the calculation, calculating the median, the result is correct. Why is the output of the mean incorrect? The code is the following: df = pd.DataFrame( np.array([['A', 1, 2, 3], ['A', 4, 5, np.nan], ['A', 7, 8, 9], ['B', 3, 2, np