mean

深度学习中的batch normalization

匿名 (未验证) 提交于 2019-12-03 00:21:02
图1 算法说明 实现函数体 如下: with ops.name_scope(name, "batchnorm", [x, mean, variance, scale, offset]): inv = math_ops.rsqrt(variance + variance_epsilon) if scale is not None: inv *= scale # Note: tensorflow/contrib/quantize/python/fold_batch_norms.py depends on # the precise order of ops that are generated by the expression below. return x * math_ops.cast(inv, x.dtype) + math_ops.cast( offset - mean * inv if offset is not None else -mean * inv, x.dtype) 此处代码 为例。 使用位置:非线性函数之前 Y1l = tf.matmul(XX, W1) Y1bn, update_ema1 = batchnorm(Y1l, O1, S1, tst, iter) Y1 = tf.nn.sigmoid(Y1bn) 训练和测试时的不同:训练时,均值和方差由mini

K-means聚类算法

匿名 (未验证) 提交于 2019-12-02 23:59:01
K-means聚类算法简介 K-means算法是典型的基于距离的聚类算法,即对各个样本集采用距离作为相似性的评价指标,若两个样本集K个簇。让簇内的点尽量紧密的连在一起,且让簇间的距离尽量的大。最后把得到紧凑且独立的簇作为最终的目标。 二、相关知识点 1、距离度量:不同的距离量度会对距离的结果产生影响,常见的距离量度公式有很多。在该算法中一般采用欧几里得公式: 但是欧几里得距离度量会受指标不同单位刻度的影响,所以一般需要先进行标准化。距离越大,个体间差异越大; 2、聚类分析:聚类分析是在数据中发现数据对象之间的关系,将数据进行分组,组内的相似性越大,组间的差别越大,则聚类效果越好。 3、簇类型:用不同的簇类型划分数据的结果是不同的,簇的类型有很多种。如: K-means算法过程 1)随机选取K个初始质心 2)分别计算所有样本到这K个质心的距离 3)如果样本离某质心Ki最近,那么这个样本属于Ki点群;如果到多个质心的距离相等,则可划分到任意组中 4)按距离对所有样本分完组之后,计算每个组的均值(最简单的方法就是求样本每个维度的平均值),作为新的质心 5)重复(2)(3)(4)直到新的质心和原质心相等,算法结束 如上图所示,图a表达了初始的样本集,假设质心k=2。(×和绿色×表示两个不同的质心b中随机选择两个k类所对应的类别质心,即图中的红色质心和绿c所示

用K-近邻算法分类和回归

匿名 (未验证) 提交于 2019-12-02 23:49:02
import numpy as np from matplotlib import pyplot as plt X_train = np.array([ [158, 64], [170, 66], [183, 84], [191, 80], [155, 49], [163, 59], [180, 67], [158, 54], [178, 77] ]) y_train = ["male", "male", "male", "male", "female", "female", "female", "female", "female"] plt.figure() plt.title("Human Heights and Weights by Sex") plt.xlabel("Height in cm") plt.ylabel("Weight in kg") for i, x in enumerate(X_train): plt.scatter(x[0], x[1], c="k", marker="x" if y_train[i] == "male" else "D") plt.grid(True) plt.show() 代码结果: from collections import Counter import numpy as np X_train = np.array([ [158

How to add a line in boxplot?

给你一囗甜甜゛ 提交于 2019-12-02 23:09:40
I would like to add lines between "mean" in my boxplot. My code: library(ggplot2) library(ggthemes) Gp=factor(c(rep("G1",80),rep("G2",80))) Fc=factor(c(rep(c(rep("FC1",40),rep("FC2",40)),2))) Z <-factor(c(rep(c(rep("50",20),rep("100",20)),4))) Y <- c(0.19 , 0.22 , 0.23 , 0.17 , 0.36 , 0.33 , 0.30 , 0.39 , 0.35 , 0.27 , 0.20 , 0.22 , 0.24 , 0.16 , 0.36 , 0.30 , 0.31 , 0.39 , 0.33 , 0.25 , 0.23 , 0.13 , 0.16 , 0.18 , 0.20 , 0.16 , 0.15 , 0.09 , 0.18 , 0.21 , 0.20 , 0.14 , 0.17 , 0.18 , 0.22 , 0.16 , 0.14 , 0.11 , 0.18 , 0.21 , 0.30 , 0.36 , 0.40 , 0.42 , 0.26 , 0.23 , 0.25 , 0.30 , 0.27 , 0.15 ,

caffe2 教程入门(python版)

匿名 (未验证) 提交于 2019-12-02 22:54:36
Caffe2 Tutorials 原文链接: caffe2 教程入门(python版) ѧϰ˼· 1、先看官方文档,学习如何使用python调用caffe2包,包括 Basics of Caffe2 - Workspaces, Operators, and Nets Toy Regression Image Pre-Processing Loading Pre-Trained Models MNIST - Create a CNN from Scratch caffe2官方教程以python语言为主,指导如何使用python调用caffe2,文档依次从最基本caffe中的几个重要的类的概念、如何使用基础类搭建一个小网络、如何数据预处理、如何使用预训练的模型、如何构造复杂的网络来讲述caffe2的使用。初学者可以先行学习官方文档 caffe2-tutorials ,理解caffe2 中的网络构建、网络训练的理念与思路,体会caffe2与caffe在整体构造上的不同。 2、结合着caffe2源码看python实际调用的c++类 在python中,caffe2这个包中类与函数大部分是封装了源码文件夹caffe2/caffe2/core下的c++源文件,如基础数据类Tensor,操作类Operator等,通过使用python中类的使用,找到对应c++源码中类和函数的构造和实现,可以为使用c

python数据分析与挖掘实战---基于水色图像的水质评价

匿名 (未验证) 提交于 2019-12-02 22:51:30
抽取80%作为训练样本,剩下20%作为测试样本 此案例是《python数据分析与数据挖掘》的第九章,在p200我们可以看到特征的取值范围都在0~1之间,换句话说,如果我们直接输入SVM模型的话,彼此之间的区分度会比较小,因此我们需要做一个放大处理,当然放大系数K不能过大或者过小,经反复试验,我们发现30时,效果比较好。 代码如下: import pandas as pd inputfile ='chapter9/demo/ data /moment.csv' data =pd.read_csv ( inputfile , encoding =' gbk' ) #读取数据,指定编码 data = data .as_matrix () from random import shuffle #引入随机函数 ## shuffle(data) #随机打乱数据 **这样直接写有问题** #用下面的方式 num_example = data .shape[0] print (num_example) arr =np.arange(num_example) np .random.shuffle(arr) data = data [arr] data_train = data [:int (0.8* len ( data ) ),:] #选取前80%为训练数据 data_test = data

MATLAB error: “previously appeared to be used as a function or command”

无人久伴 提交于 2019-12-02 21:37:08
问题 I want to create a function called E7stats, which performs a simple statistical analysis on the scores of the first midterm, contained in a csv file. The function takes one string input, filename, which is the name of the csv file, and returns one output, a 1⇥2 structure array S , both of whose two entries contain four fields mean, std d ev, max, and min, which are the mean, standard deviation, maximum value and minimum value of the electronic and paper based midterm scores. The function also

Calculating mean by selecting from two columns in a data frame [duplicate]

主宰稳场 提交于 2019-12-02 21:22:33
问题 This question already has answers here : How to sum a variable by group (13 answers) Closed 4 years ago . I would like to calculate the mean of a data.frame by two variables. See an example of the data.frame (extraction) below: Station Time Year Month Value ARO 199501 1995 1 69 ARO 199502 1995 2 87 ARO 199503 1995 3 107 ARO 199601 1996 1 35 ARO 199602 1996 2 46 ARO 199603 1996 3 50 ANT 200401 2004 1 87 ANT 200402 2004 2 115 ANT 200403 2004 3 110 ANT 200501 2005 1 80 ANT 200502 2005 2 122 ANT

tensorflow2.0 损失函数

北城余情 提交于 2019-12-02 15:08:22
# 1. tf.losses.mean_squared_error:均方根误差(MSE) —— 回归问题中最常用的损失函数 # 优点是便于梯度下降,误差大时下降快,误差小时下降慢,有利于函数收敛。 # 缺点是受明显偏离正常范围的离群样本的影响较大 mse=tf.losses.mean_squared_error(y_true,y_pred) mse=tf.reduce_mean(tf.square(y_true-y_pred)) 2. tf.losses.absolute_difference:平均绝对误差(MAE) —— 想格外增强对离群样本的健壮性时使用 # 优点是其克服了 MSE 的缺点,受偏离正常范围的离群样本影响较小。 # 缺点是收敛速度比 MSE 慢,因为当误差大或小时其都保持同等速度下降,而且在某一点处还不可导,计算机求导比较困难。 maes=tf.compat.v1.losses.absolute_difference(y_true,y_pred) maes_loss=tf.reduce_sum(maes) # 3. tf.losses.huber_loss:Huber loss —— 集合 MSE 和 MAE 的优点,但是需要手动调超参数 # 核心思想是,检测真实值(y_true)和预测值(y_pred)之差的绝对值在超参数 δ 内时, # 使用 MSE 来计算

What is the difference between np.mean and tf.reduce_mean?

不打扰是莪最后的温柔 提交于 2019-12-02 14:47:56
In the MNIST beginner tutorial , there is the statement accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf.cast basically changes the type of tensor the object is, but what is the difference between tf.reduce_mean and np.mean ? Here is the doc on tf.reduce_mean : reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None) input_tensor : The tensor to reduce. Should have numeric type. reduction_indices : The dimensions to reduce. If None (the defaut), reduces all dimensions. # 'x' is [[1., 1. ]] # [2., 2.]] tf.reduce_mean(x) ==> 1.5 tf.reduce_mean(x, 0) ==> [1