Statistic for ML
statistical concept 統計學概念
免費完整內容
PMF and CDF
PMF定義的值是P(X=x),而CDF定義的值是P(X <= x),x為所有的實數線上的點。
probability mass function (PMF) 概率質量函數
p X ( x ) = P ( X = x ) pX(x)=P(X=x) pX(x)=P(X=x)
是離散隨機變數在各個特定取值上的概率。有時也被稱為離散密度函數。
概率密度函數通常是定義離散隨機分佈的主要方法,
並且此類函數存在於其定義域是:
- 離散的純量變數
- 多遠隨機變數
維基百科
Cumulative distribution function(CDF)累積分佈函數
F X ( x ) = P ( X < = x ) FX(x)=P(X<=x) FX(x)=P(X<=x)
也叫概率分佈函數或分佈函數
是概率密度函數的積分
能夠完整的描述一個實隨機變數X的概率分佈
維基百科
probability density function(PDF)概率密度函數
概率密度函數(Probability Density Function, PDF)-CSDN博客
Central Limits 中央界限
Support we have a set of independent random variables X i X_{i} Xi for i = 1 , . . . . , n i=1,....,n i=1,....,n with:
M e a n ( X i ) = μ Mean(X_{i})=\mu Mean(Xi)=μ V a r ( X i ) = V Var(X_{i})=V Var(Xi)=V for all i i i
Then as n n n becomes large, the sum:
S m = ∑ i = 1 n X i → N ( n μ , n V ) S_{m}=\sum\limits_{i = 1}^n {{X_i} \to {\rm N}(n\mu ,nV)} Sm=i=1∑nXi→N(nμ,nV)
tends to become normally distributed.
Absence of Central Limits
Another case is where the moments are not defined / infinite 另一種情況是力矩不確定或無限大
Randomness 隨機性
Motivation 動機
Three main ways that random comes into data science:
- The data themselves are often best understood as random 數據本身通常最好被理解為隨機
- **When we want to reason under **subjective uncertainty **(for example in Bayesian approaches) then unknown quantities can be represented as random. Often when we make predictions they will be **probabilitic 當我們主管不確定性的情況下進行推理時,可以將未知量表示為隨機量,當我們進行預測時,他們將是概率性的
- Many of the most effective / efficient / commonly‑used algorithms in data science—typically called Monte Carlo algorithms—exploit randomness. 蒙特卡洛算法
- Unpredictable 不可預測性
- Subjective uncertainty 主管不確定性
The logistic map 邏輯地圖(單峰映象)
是一個二次多項式映射(遞歸關係)经常作为典型范例来说明复杂的混沌现象是如何从非常简单的非线性动力学方程中产生的。
is an example of deterministic chaos 是確定性混沌的一個例子 but whose results are apparently not easy to predict. 結果不容易被預測
它在一定程度上是一个时间离散的人口统计模型
Logistic模型可以描述生物種群的演化,它可以表示成一維非線性迭代方程 x n + 1 = r x n ( 1 − x n ) x_{n+1}=rx_{n}(1-x_{n}) xn+1=rxn(1−xn)
Math:
x ( t + 1 ) = μ x ( t ) ( 1 − x ( t ) ) \displaystyle{ x(t+1)=\mu x(t)(1-x(t)) } x(t+1)=μx(t)(1−x(t))
其中,t为迭代时间步,对于任意的t,x(t)∈[0,1],μ为一可调参数,为了保证映射得到的x(t)始终位于[0,1]内,则μ∈[0,4]。x(t)为在t时刻种群占最大可能种群规模的比例(即现有人口数与最大可能人口数的比率)。当变化不同的参数μ时,该方程会展现出不同的动力学极限行为(即当t趋于无穷大,x(t)的变化情况),包括:稳定点(即最终x(t)始终为同一个数值)、周期(x(t)会在2个或者多个数值之间跳跃)、以及混沌(x(t)的终态不会重复,而会等概率地取遍某区间)。
当μ超过[1,4]时,就会发生混沌现象。该非线性差分方程意在观察两种情形:
• 当人口规模很小时,人口将以与当前人口成比例的速度增长进行繁殖。
• 饥饿(与密度有关的死亡率) ,其增长率将以与环境的”承受能力”减去当前人口所得值成正比的速度下降
然而,Logistic映射作为一种人口统计模型,存在着一些初始条件和参数值(如μ >4)为某值时所导致的混沌问题。这个问题在较老的瑞克模型中没有出现,该模型也展示了混沌动力学。
0 < = μ < = 1 0<=μ<=1 0<=μ<=1:
entropy 熵
另一种方法是利用计算机外部因素来产生随机性, 例如鼠标点击的位置和时间。 在此, 我们将考虑把代码运行的时间作为外部因素
即使用系统时钟当前时间的小数点后六位数字(分辨率为微秒)
R和Matlab 使用軟件包提供隨機數生成的函數
Estimation of π π π using Monte Carlo methods
假設我們將 π \pi π 定義為半徑為1的圓的面積根據其定義來估算這個數字,
we will pick random values of x x x and y y y independently from a uniform distribution between 0 and 1, then let the random variable Z Z Z equal 1 if the point ( x , y ) (x, y) (x,y) falls within the quarter-circle shown and 0 otherwise. This Z Z Z allows us to make an estimate of π π π in that its expected value, E [ Z ] = π / 4 E[Z] = π/4 E[Z]=π/4. We can then define a random variable An to be the average of n n n independent samples of Z Z Z. Formally:
A n = 1 n ∑ i = 1 n Z i = π 4 + ε n {{\rm{A}}_n} = \frac{1}{n}\sum\limits_{i = 1}^n {{Z_i} = \frac{\pi }{4} + {\varepsilon _n}} An=n1i=1∑nZi=4π+εn
Code operation
To deal with this, we’ll repeat the experiment m m m times and make a list of all the estimates
we get. We’ll then arrange these results in ascending order and throw away a certain fraction α \alpha α of the largest and smallest results. The remaining values should provide decent upper and lower bounds for an interval containing π \pi π.
m = 100 # Number of estimates taken
n = 80000 # Number of points used in each estimate
If we increase n n n above, we should get a more accurate estimates of π \pi π each tme we run the experiment, while if we increase m m m, we’ll get more accurate estimates of the endpoints of an interval containing π \pi π.
#Generate a set of m estimates of the area of a unit-radius quarter-circle
np.random.seed(42) # Seed the random number generator
A = np.zeros(m) # A will hold our m estimates
for i in range(0,m):for j in range(0,n):# Generate an (x, y) pair in the unit squarex = np.random.rand()y = np.random.rand()# Decide whether the point lies in or on# the unit circle and set Z accordinglyr = x**2 + y**2if ( r <= 1.0):Z = 1.0else:Z = 0# Add up the contribution to the current estimateA[i] = A[i] + Z# Convert the sum we've built to an estimate of piA[i] = 4.0 * A[i] / float( n )
# Calculate approximate 95% confidence interval for pi based on our Monte Carlo estimates
pi_estimates = np.sort(A)
piLower = np.percentile(pi_estimates,2.5)
piUpper = np.percentile(pi_estimates,97.5)
print(f'We estimate that pi lies between {piLower:.3f} and {piUpper:.3f}.')
standard distribution
Bernoulli 伯努利分佈
P ( X = x ) = p x ( 1 − p ) 1 − x , x = 0 , 1 ; 0 < p < 1 P(X=x) = p^{x}(1-p)^{1-x}, x = 0, 1; 0 < p < 1 P(X=x)=px(1−p)1−x,x=0,1;0<p<1
only have two choices(binary situations). 只有兩個結果 例如成功失敗 硬幣正反面
Random Variable (X): In the context of Bernoulli Distribution, X represents the variable that can take the values 1 or 0, denoting the number of successes occurring.
Bernoulli Trial: An individual experiment or trial with only two possible outcomes.
Bernoulli Parameter: This refers to the probability of success § in a Bernoulli Distribution.
Mean:
E [ X ] = μ = p E[X] = μ = p E[X]=μ=p
Variance:
V a r [ X ] = E [ X 2 ] − ( E [ X ] ) 2 = σ 2 = p ( 1 − p ) o r p q Var[X] = E[X^{2}] - (E[X])^2 \\ =σ2 = p(1 - p) \ or\ pq Var[X]=E[X2]−(E[X])2=σ2=p(1−p) or pq
Applications of Bernoulli Distribution in Business Statistics
1. Quality Control: In manufacturing, every product undergoes quality checks. Bernoulli Distribution helps assess whether a product passes (success) or fails (failure) the quality standards. By analysing the probability of success, manufacturers can evaluate the overall quality of their production process and make improvements.
2. Market Research: Bernoulli Distribution is useful in surveys and market research when dealing with yes/no questions. For instance, when surveying customer satisfaction, responses are often categorised as satisfied (success) or dissatisfied (failure). Analysing these binary outcomes using Bernoulli Distribution helps companies gauge customer sentiment.
3. Risk Assessment: In the context of risk management, the Bernoulli Distribution can be applied to model events with binary outcomes, such as a financial investment succeeding (success) or failing (failure). The probability of success serves as a key parameter for assessing the risk associated with specific investments or decisions.
4. Marketing Campaigns: Businesses use Bernoulli Distribution to measure the effectiveness of marketing campaigns. For instance, in email marketing, success might represent a recipient opening an email, while failure indicates not opening it. Analysing these binary responses helps refine marketing strategies and improve campaign success rates.
Difference between Bernoulli Distribution and Binomial Distribution 伯努利分佈和二項分佈的區分
The Bernoulli Distribution and the Binomial Distribution are both used to model random experiments with binary outcomes, but they differ in how they handle multiple trials or repetitions of these experiments. 同樣是對具有二元結果的隨機實驗進行建模,但在處理多次實驗的方式上有所不同
Basis | Bernoulli Distribution | Binomial Distribution |
---|---|---|
Number of Trials | Single trial | Multiple trials |
Possible Outcomes | 2 outcomes (1 for success, 0 for failure) | Multiple outcomes (e.g., success or failure) |
Parameter | Probability of success is p | Probability of success in each trial is p and the number of trials is n |
Random Variable | X can only be 0 or 1 | X can be any non-negative integer (0, 1, 2, 3, …) |
Purpose | Describes single trial events with success/failure. | Models the number of successes in multiple trials. |
Example | Coin toss (Heads/Tails), Pass/Fail, Yes/No, etc. | Counting the number of successful free throws in a series of attempts, number of defective items in a batch, etc. |
Arithmetic with normally-distributed variables
Suppose we have two random variables, X1 and X2 that are independent and are both normally distributed with means µ1 and µ2 **and variances σ12 and σ2 2, respectively.
W = X 1 + X 2 W=X_{1}+X_{2} W=X1+X2
will also be normally distributed
mean:
μ W = μ 1 + μ 2 {\mu_{W}}={\mu_{1}} + {\mu_{2}} μW=μ1+μ2
variance:
σ W 2 = σ 1 2 + σ 2 2 {\sigma^{2}_{W}}={\sigma^{2}_{1}}+{\sigma^{2}_{2}} σW2=σ12+σ22
Y = a X 1 + b Y=aX_{1}+b Y=aX1+b
will also be normally distributed
mean:
μ Y = a μ 1 + b \mu_{Y}=a\mu_{1}+b μY=aμ1+b
variance:
σ Y 2 = a 2 σ 1 2 \sigma^{2}_{Y}=a^{2}\sigma^{2}_{1} σY2=a2σ12
CDF
Cauchy 柯西分佈
The Cauchy distribution has probability density function
f ( x ) = 1 π s ( 1 + ( ( x − t ) / s ) 2 ) f(x) = \frac{1}{{\pi s(1 + {{((x - t)/s)}^2})}} f(x)=πs(1+((x−t)/s)2)1
s s s is positive t t t is parameter can be any parameters
It has “heavy tails”, which means that large values are so common that the Cauchy distribution lacks a well-defined mean and variance!
But the parameter t t t gives the location of the mode and median, which are well-defined.
The parameter s s s determines the ‘width’ of the distribution as measured using e.g. the distances between percentiles, which are also well defined.
CDF
EDA: Exploratory data analysis
motivation:
EDA is about getting an intuitive understanding of the data, and as such different people will find different techniques useful.
Data quality
The first thing understand is where the data come from and how accurate they are. 數據的來源和準確性
star rating 星級評級
This is based on experience rather than any formal theory:
- 4: Numbers we can believe. Examples: official statistics(官方統計數據); well controlled laboratory experiments
- 3: Numbers that are reasonably accurate. Examples: well conducted surveys / samples; field measurements; less well controlled experiments.
- 2:Numbers that could be out by quite a long way. Examples: poorly conducted surveys / samples; measurements of very noisy systems
- 1: Numbers that are unreliable. Examples: highly biased / unrepresentative surveys / samples; measurements using biased / low-quality equipment
- 0: Numbers that have just been made up. Examples: urban legends / memes; fabricated experimental data
Univariate Data Vectors
univariate case: one measurement per ‘thing’ 每個變量都單獨探索
Mathematically, we represent a univariate dataset as a length-n vector:
x = ( x 1 , x 2 , . . . , x n ) x = (x_{1},x_{2},...,x_{n}) x=(x1,x2,...,xn)
The sample mean of a function f (x) is
⟨ f ( x ) ⟩ = 1 n ∑ i = 1 n f ( x i ) = 1 n [ f ( x 1 ) + f ( x 2 ) + . . . . + f ( x n ) ] \left\langle {{\rm{f}}(x)} \right\rangle = \frac{1}{n}\sum\limits_{i = 1}^n {f({x_i}) = \frac{1}{n}[f({x_1}) + f({x_2}) + .... + f({x_n})]} ⟨f(x)⟩=n1i=1∑nf(xi)=n1[f(x1)+f(x2)+....+f(xn)]
Visualisation and Information
There is an important distinction in visualisations between
- Lossless(無損) ones from which, if viewed at sufficiently high resolution, one could recover the original dataset
- Lossy(有損) ones, where a given plot would be consistent with many different raw datasets
Typically for complex data, choosing the lossy visualistaion that loses the ‘right’ information is key to successful visualisation.
Multivariate Exploratory Data Analysis
- In real applications, we almost almost always have multiple features of different things measured, and are so in a multivariate rather than univariate situation
Professional Skill
Data types
- Nominal or categorical (e.g. colours, car names): not ordered; cannot be added or compared; can be relabelled.
- Ordinal (e.g. small/medium/large): sometimes represented by numbers; can be ordered, but differences or ratios are not meaningful.
- Measurement: meaningful numbers, on which (some) operations make sense. They can be:
- Discrete (e.g. publication year, number of cylinders): typically integer.
- Continuous (e.g. height): precision limited only by measurement accuracy.
Measurements can be in an interval scale (e.g. temperature in degrees Celsius), ratio scale (say, weights in kg), or circular scale (time of day on the 24 hr clock), depending on the 0 value and on which operations yield meaningful results
Summary Statistics
Measures of Central Tendency 集中趨勢測度
Often, we are interested in what a typical value of the data;
- The mean of the data is:
M e a n ( x ) = ⟨ x ⟩ = 1 n ∑ i = 1 n x i Mean(x)=\left\langle {\rm{x}} \right\rangle = \frac{1}{n}\sum\limits_{i = 1}^n {{x_i}} Mean(x)=⟨x⟩=n1i=1∑nxi
- The median of the data is the value that sits in the middle when the data are sorted by value
- A mode in data is a value of x x x that is ‘more common’ than those around it, or a ‘local maximum’ in the density.
- For discrete data[离散数据] this can be uniquely determined as the most common value
- For continuous data, modes need to be estimated, one aspect of a major strand in data science, estimating distributions.
Visualising
For the data, we estimate from the kernel density that there is one mode, and its location and calculate the mean and median directly
Example:
The data are right-skewed(右偏的), and as a consequence of this the mode is smallest and the mean is largest – we will consider this further; (note that for a normal distribution all would be equal.)
Variance
特性 | 有偏差方差 | 無偏差方差 |
---|---|---|
分母 | n | n-1 |
應用場景 | 描述樣本的離散型 | 估計總體的方差 |
偏差 | 對總體方差的估計存在低估偏差 | 對總體方差的估計是無偏的 |
應用場景 | 數據分析、機器學習中的樣本優化 | 統計學中總體方差估計 |
何时使用?
- 有偏差方差 :在机器学习中,通常计算样本的有偏差方差(分母为 nnn),因为重点在于优化模型对样本的适配性,而非推断总体。
- 无偏差方差 :在统计学和推断中,需要用无偏差方差(分母为 n−1n-1n−1),因为它更准确地估计总体参数。
V a r ( x ) = ⟨ ( x − ⟨ x ⟩ ) 2 ⟩ = 1 n ∑ i = 1 n ( x i − ⟨ x ⟩ ) 2 = 1 n ∑ i = 1 n ( x 2 i − 2 x i ⟨ x ⟩ + ⟨ x ⟩ 2 ) = ( 1 n ∑ i = 1 n x i 2 ) + 2 ( 1 n ∑ i = 1 n x i ) ⟨ x ⟩ + 1 n ( ∑ i = 1 n 1 ) ⟨ x ⟩ 2 = 1 n ( ∑ i = 1 n x i 2 ) − ( 1 n ∑ i = 1 n x i ) 2 = ⟨ x 2 ⟩ − ⟨ x ⟩ 2 \begin{array}{ccccc} Var(x) = \left\langle {{{(x - \left\langle x \right\rangle )}^2}} \right\rangle\\ = \frac{1}{n}\sum\limits_{i = 1}^n {{{({x_i} - \left\langle x \right\rangle )}^2}}\\ =\frac{1}{n}\sum\limits_{i = 1}^n {({x^2}_i - 2{x_i}\left\langle x \right\rangle + {{\left\langle x \right\rangle }^2})}\\ =\left( {\frac{1}{n}\sum\limits_{i = 1}^n {x_i^2} } \right) + 2\left( {\frac{1}{n}\sum\limits_{i = 1}^n {{x_i}} } \right)\left\langle x \right\rangle + \frac{1}{n}\left( {\sum\limits_{i = 1}^n 1 } \right){\left\langle x \right\rangle ^2}\\ =\frac{1}{n}\left( {\sum\limits_{i = 1}^n {x_i^2} } \right) - {\left( {\frac{1}{n}\sum\limits_{i = 1}^n {{x_i}} } \right)^2}\\ =\left\langle {{x^2}} \right\rangle - {\left\langle x \right\rangle ^2} \end{array} Var(x)=⟨(x−⟨x⟩)2⟩=n1i=1∑n(xi−⟨x⟩)2=n1i=1∑n(x2i−2xi⟨x⟩+⟨x⟩2)=(n1i=1∑nxi2)+2(n1i=1∑nxi)⟨x⟩+n1(i=1∑n1)⟨x⟩2=n1(i=1∑nxi2)−(n1i=1∑nxi)2=⟨x2⟩−⟨x⟩2
Unbiased Variance and Computation 無偏方差
V a r ^ ( x ) = n n − 1 V a r ( x ) = 1 n − 1 ∑ i = 1 n ( x i − ⟨ x ⟩ ) 2 = 1 n − 1 ( ∑ i = 1 n x i 2 − 1 n ( ∑ i = 1 n x i ) 2 ) \begin{array}{ccccc} \widehat {Var}(x) = \frac{n}{{n - 1}}Var(x) \\ = \frac{1}{{n - 1}}\sum\limits_{i = 1}^n {{{({x_i} - \left\langle x \right\rangle )}^2}}\\ = \frac{1}{{n - 1}}\left( {\sum\limits_{i = 1}^n {x_i^2 - \frac{1}{n}{{\left( {\sum\limits_{i = 1}^n {{x_i}} } \right)}^2}} } \right) \end{array} Var (x)=n−1nVar(x)=n−11i=1∑n(xi−⟨x⟩)2=n−11(i=1∑nxi2−n1(i=1∑nxi)2)
默認情況下, python計算有偏差的,R計算無偏差的
無偏差樣本
‘Natural’ units
there are two commonly-used quantities that have the same units as the data 與數據有相同單位
- mean μ = M e a n ( x ) \mu = Mean(x) μ=Mean(x)
- standard deviation σ = V a r ( x ) \sigma = \sqrt {Var(x)} σ=Var(x)
These two quantities let us define two transformations commonly applied to data 用於數據轉換
- centring y i = x i − μ {y_i} = {x_i} - \mu yi=xi−μ | M e a n ( y ) = 0 Mean(y) = 0 Mean(y)=0
- standardisation z i = y i σ {z_i} = \frac{{{y_i}}}{\sigma } zi=σyi | V a r ( z ) = 1 Var(z)=1 Var(z)=1
Higher moments
-
In general, the r r r-th moment of the data is 第 r r r時刻的數據是 m r = ⟨ x r ⟩ {m_r} = \left\langle {{x^r}} \right\rangle mr=⟨xr⟩
-
The r r r-th central moment中心距 of the data is μ r = ⟨ ( x − μ ) r ⟩ = ⟨ y r ⟩ {\mu _r} = \left\langle {{{(x - \mu )}^r}} \right\rangle = \left\langle {{y^r}} \right\rangle μr=⟨(x−μ)r⟩=⟨yr⟩
where the y’s are the centred versions of the data.
-
The r r r-th standardised moment of the data is μ r = ⟨ ( x − μ σ ) r ⟩ = ⟨ z r ⟩ = ⟨ ( x − μ ) 2 ⟩ σ r = μ r σ r {\mu _r} = \left\langle {{{(\frac{{x - \mu }}{\sigma })}^r}} \right\rangle = \left\langle {{z^r}} \right\rangle = \frac{{\left\langle {{{\left( {x - \mu } \right)}^2}} \right\rangle }}{{{\sigma ^r}}} = \frac{{{\mu _r}}}{{{\sigma ^r}}} μr=⟨(σx−μ)r⟩=⟨zr⟩=σr⟨(x−μ)2⟩=σrμr
In theory, all higher moments are informative about the data, but in practice those with r = 3 and r = 4 are most commonly reported
standardised moment
M k = μ k σ k = 原始矩 標準差 {M_k} = \frac{{{\mu _k}}}{{{\sigma ^k}}}=\frac{{{原始矩}}}{{{標準差}}} Mk=σkμk=標準差原始矩
- M k M_k Mk:第 k k k阶标准化矩。
- μ k \mu_k μk:第 k k k 阶原始矩。
- σ \sigma σ:标准差
标准化矩通过除以标准差的 k k k 次方,使矩的量纲消失,方便分布的比较
第一阶标准化矩
M 1 = μ 1 σ 1 {M_1} = \frac{{{\mu _1}}}{{{\sigma ^1}}} M1=σ1μ1
表示分布的中心位置,但通常为 0(如果中心点选均值)
第二阶标准化矩
M 2 = μ 2 σ 2 {M_2} = \frac{{{\mu _2}}}{{{\sigma ^2}}} M2=σ2μ2
恒等于 1,因为分布已经用标准差标准化。
第三阶标准化矩(偏度,Skewness)
M 3 = μ 3 σ 3 = μ 3 ~ = S k e w ( x ) {M_3} = \frac{{{\mu _3}}}{{{\sigma ^3}}}=\widetilde {{\mu _3}} = Skew(x) M3=σ3μ3=μ3 =Skew(x)
-
用于描述分布的对称性或偏斜程度
- M 3 > 0 {{\rm{M}}_3} > 0 M3>0: 分佈 偏右(右尾較長)
- M 3 < 0 {{\rm{M}}_3} < 0 M3<0: 分佈偏左(左尾較長)
- M 3 = 0 {{\rm{M}}_3} = 0 M3=0: 分佈對稱
-
A larger (more positive) value of this quantity indicates right-skewness, meaning that more of the data’s variability arises from values of x larger than the mean
-
Conversely, a smaller (more negative) value of this quantity indicates left-skewness, meaning that more of the data’s variability arises from values of x smaller than the mean.
-
A value close to zero means that the variability of the data is similar either side of the mean (but does not imply an overall symmetric distribution).
第四阶标准化矩(峰度,Kurtosis)
M 4 = μ 4 σ 4 {M_4} = \frac{{{\mu _4}}}{{{\sigma ^4}}} M4=σ4μ4
- 用于描述分布的尖峰或平坦程度.
- M 4 > 3 {{\rm{M}}_4} > 3 M4>3: 尖峰分佈
- M 4 < 3 {{\rm{M}}_4} < 3 M4<3: 平坦分佈
用途
- 描述分布形状 :偏度和峰度是最常用的标准化矩,用于研究数据分布的对称性和尾部特性。
- 模型假设检验 :例如,判断数据是否符合正态分布。
- 分布比较 :通过标准化,消除了尺度和单位的影响,可以直接比较不同数据集的形状特征。
- A value of this quantity larger than 3 means that more of the variance of the data arises from the tails than would be expected if it were normally distributed
- A value of this quantity less than 3 means that less of the variance of the data arises from the tails than would be expected if it were normally distributed.
- A value close to 3 is consistent with, though not strong evidence for, a normal distribution.
- The difference between the kurtosis and 3 is called the excess kurtosis.
functions
Quantiles and Order Statistics
- The z-th percentile, P z P_z Pz is the value of x for which z% of the data is ≤ x
- So the median is median(x) = P 50 P_{50} P50
- This is related to the ECDF as illustrated below
- A measure of dispersal of the data is the inter-quartile range I Q R ( x ) = P 75 − P 25 IQR(x) = {P_{75}} - {P_{25}} IQR(x)=P75−P25
Density Estimation
Histograms
histogram can be used to make an estimate of the probability density underlying a data set. Given data{ x 1 , . . . , x n { {x_1}, . . . , {x_n} } x1,...,xn} and a collection of q + 1 bin-boundaries, b = ( b 0 , b 1 , . . . , b q ) b = (b_0, b_1, . . . , b_q ) b=(b0,b1,...,bq)
chosen so that b 0 < m i n ( x ) a n d m a x ( x ) < b q {b_0} < min(x) \ and \ max(x) < {b_q} b0<min(x) and max(x)<bq , we can think of the histogram-based density estimate as a piecewise-constant (that is, constant on intervals) function arranged so that the value of the estimator in the interval b a − 1 ≤ x < b a b_{a−1} ≤ x < b_{a} ba−1≤x<ba is
f ( x ∣ b ) = 1 b a − b a − 1 ( ∣ { x j ∣ b a − 1 ≤ x j < b a } ∣ n ) f(x|b) = \frac{1}{{{b_a} - {b_{a - 1}}}}\left( {\frac{{\left| {\{ {x_j}|{b_{a - 1}} \le {x_j} < {b_a}\} } \right|}}{n}} \right) f(x∣b)=ba−ba−11(n∣{xj∣ba−1≤xj<ba}∣)
where the second factor is the proportion of the x j {x_j} xj that fall into the interval and b a − b a − 1 b_a − b_{a−1} ba−ba−1 is the width of the interval. These choices mean that the bar (of the histogram) above the interval has an area equal to the proportion of the data points x j x_j xj that fall in that interval
Estimating a Density with Kernels
f ^ ( x ∣ w ) = 1 n ∑ j = 1 n 1 w K ( x − x j w ) \widehat f(x|w) = \frac{1}{n}\sum\limits_{j = 1}^n {\frac{1}{w}K\left( {\frac{{x - {x_j}}}{w}} \right)} f (x∣w)=n1j=1∑nw1K(wx−xj)
The main players in this formula are
K ( x ) K(x) K(x): the kernel, typically some bump-shaped function such as a Gaussian or a parabolic bump. It should be normalised in the sense that
∫ − ∞ ∞ K ( x ) d x = 1 \int_{ - \infty }^\infty {K(x)\ dx = 1} ∫−∞∞K(x) dx=1
w w w : the bandwidth, which sets the width of the bumps
Kernel Density Estimation (KDE)
是一种 非参数方法 ,用于估计随机变量的概率密度函数(PDF,Probability Density Function)。它提供了一种平滑方式来描述数据的分布,不依赖特定的分布假设(如正态分布)
目标 :
- KDE 的目标是从有限的样本数据中估计其背后的概率密度函数。
- 与直方图类似,KDE 描述了数据的分布,但比直方图更平滑且不受特定区间(bin)的影响。
核心公式 :
给定 n n n 个数据点 { x 1 , x 2 , … , x n } \{x_1, x_2, \dots, x_n\} {x1,x2,…,xn},KDE 在位置 x x x 处的估计值为:
f ( x ) = 1 n h ∑ i = 1 n K ( x − x i h ) f ^ ( x ) = 1 n h ∑ i = 1 n K ( x − x i h ) :在 x 处的密度估计。 f^(x)=1nh∑i=1nK(x−xih)\hat{f}(x) = \frac{1}{n h} \sum_{i=1}^{n} K\left(\frac{x - x_i}{h}\right):在 x 处的密度估计。 f(x)=1nh∑i=1nK(x−xih)f^(x)=nh1i=1∑nK(hx−xi):在x处的密度估计。
- K ( ⋅ ) K(\cdot) K(⋅): 核函数 (Kernel Function),定义如何分布平滑权重。
- h h h: 带宽参数 (Bandwidth),控制平滑的程度。
- x i x_i xi:数据点。
核函数 K ( ⋅ ) K(\cdot) K(⋅) :
- 核函数是一个对称的非负函数,其积分为 1,通常用来为每个点分配权重。
- 常见核函数:
- 高斯核(Gaussian Kernel): K ( u ) = 12 π e − u 22 K ( u ) = 1 2 π e − u 2 2 K(u)=12πe−u22K(u) = \frac{1}{\sqrt{2\pi}} e^{-\frac{u^2}{2}} K(u)=12πe−u22K(u)=2π1e−2u2
- 均匀核(Uniform Kernel): K ( u ) = 12 K ( u ) = 1 2 K(u)=12K(u) = \frac{1}{2} K(u)=12K(u)=21(如果 ∣ u ∣ ≤ 1 ∣ u ∣ ≤ 1 ∣u∣≤1|u| \leq 1 ∣u∣≤1∣u∣≤1,否则为 0)
- 三角核(Triangular Kernel): K ( u ) = 1 − ∣ u ∣ K ( u ) = 1 − ∣ u ∣ K(u)=1−∣u∣K(u) = 1 - |u| K(u)=1−∣u∣K(u)=1−∣u∣(如果 ∣ u ∣ ≤ 1 ∣ u ∣ ≤ 1 ∣u∣≤1|u| \leq 1 ∣u∣≤1∣u∣≤1,否则为 0)
带宽 h h h:
-
带宽控制了核的扩展范围。
-
h h h 的选择非常重要:
- h h h 太小:估计函数会过于波动(过拟合)。
- h h h 太大:估计函数会过于平滑(欠拟合)。
-
KDE 的核心思想是用核函数 K ( ⋅ ) K(\cdot) K(⋅)平滑地“覆盖”每个数据点。
-
通过将核函数中心放在每个数据点上,并根据带宽 h h h 调整宽度,最终生成一个连续的概率密度曲线
KDE与直方图的比较
特點 | 直方圖 | KDE |
---|---|---|
區間 | 数据被划分成固定宽度的区间(bin) | 不需要固定区间 |
平滑性 | 曲线可能不连续,有棱角 | 曲线连续、平滑 |
參數 | 区间宽度(bin width) | 核函数和带宽(kernel + bandwidth) |
靈活性 | 对区间位置敏感 | 更灵活,适用于复杂数据分布 |
应用场景
- 数据分布可视化 :如观察数据的集中趋势和分布形态。
- 异常检测 :识别不符合密度分布的数据点。
- 概率密度估计 :用于机器学习和统计建模中的特征分布建模。
相关文章:
Statistic for ML
statistical concept 統計學概念 免費完整內容 PMF and CDF PMF定義的值是P(Xx),而CDF定義的值是P(X < x),x為所有的實數線上的點。 probability mass function (PMF) 概率質量函數 p X ( x ) P ( X x ) pX(x)P(Xx) pX(x)P(Xx) 是離散隨機變數…...
Node.js 函数
Node.js 函数 1. 概述 Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时环境,它允许开发者使用 JavaScript 编写服务器端和网络应用程序。在 Node.js 中,函数是一等公民,意味着它们可以作为变量传递,可以作为参数传递给其他函数,也可以从其他函数返回。本文将详细…...
数据结构:时间复杂度和空间复杂度
我们知道代码和代码之间算法的不同,一定影响了代码的执行效率,那么我们该如何评判算法的好坏呢?这就涉及到了我们算法效率的分析了。 📖一、算法效率 所谓算法效率的分析分为两种:第一种时间效率,又称时间…...
使用 Docker 安装 Redis
随着微服务架构和分布式应用的广泛应用,缓存技术已经成为提升系统性能和响应速度的关键手段。而 Redis 作为一个高效、轻量级的内存数据存储解决方案,因其极高的性能和丰富的数据结构支持,广泛应用于缓存、消息队列、实时分析等领域。 在现代…...
【源码+文档+调试讲解】“健康早知道”微信小程序
摘 要 随着信息化时代的到来,管理系统都趋向于智能化、系统化,“健康早知道”微信小程序也不例外,但目前国内的市场仍都使用人工管理,市场规模越来越大,同时信息量也越来越庞大,人工管理显然已无法应对时代…...
Linux中操作中的无痕命令history技巧
当我们需要查看Linux下的操作记录时,就可以用history命令来查看历史记录 1、关闭history记录功能,如果不想让别人看到自己在Linux上的操作命令,可以用这个命令 set o history 2、打开history记录功能 set -o history3、清空记录 histor…...
Springboot+NettySocket通讯教程
需求背景 最近需要对接一些硬件设备,他们选择了socket通讯,并且使用的是私有化协议加密通讯。这种情况下适合原生的socket加解密解析,不适合NettySocket,这在开发中增加了难度。所有的代码都要手动去敲。 // springboot原生socket通讯教程https://blog.csdn.net/renkai72…...
Spingboot定时任务与过滤器,拦截器
文章目录 Spingboot定时任务与过滤器,拦截器1. 定时任务Scheduled2. 拦截器 Spingboot定时任务与过滤器,拦截器 1. 定时任务Scheduled 一种是使用 Spring 自带的定时任务处理器 Scheduled 注解另一种就是使用第三方框架 Quartz ,Spring Boo…...
大数据学习(33)-续集
今天开始重新更新大数据 -- 感谢大家的支持!!!...
overleaf写学术论文常用语法+注意事项+审阅修订
常用语法 导入常用的宏包 \usepackage{cite} \usepackage{amsmath,amssymb,amsfonts} \usepackage{algorithmic} \usepackage{algorithm} \usepackage{graphicx} \usepackage{subfigure} \usepackage{textcomp} \usepackage{xcolor} \usepackage{lettrine} \usepackage{booktab…...
基于fMRI数据计算脑脊液(CSF)与全脑BOLD信号的时间耦合分析
一、前言 笔者之前的文章《基于Dpabi和spm12的脑脊液(csf)分割和提取笔记》,介绍了如何从普通的fMRI数据中提取CSF信号。首先是基础的预处理,包括时间层校正、头动校正,再加上0.01-0.1Hz的带通滤波。接着用SPM12分割出CSF区域,设置一个比较严格的0.9阈值,确保提取的真是…...
使用Dockerfile构建镜像
由于格式和图片解析问题,为了更好体验可前往 阅读原文 前面我们学习了可以使用docker commit命令式构建新的镜像,而此方式相对来说比较繁琐且对于旁人来说内部都是黑箱操作,无法了解制作的具体细节。很有可能很长时间后制作者也会对其忘却&am…...
SQL字符串截取函数——Left()、Right()、Substring()用法详解
SQL字符串截取函数——Left()、Right()、Substring()用法详解 1. LEFT() 函数:从字符串的左侧提取指定长度的子字符串。 LEFT(string, length)string:要操作的字符串。length&#x…...
python字符串函数用法大全
目录 1.0 capitalize()函数 2.0 title()函数 3.0 swapcase()函数 4.0 lower()函数 5.0 upper()函数 7.0 center()函数 8.0 ljust()函数 9.0 rjust()函数 10.0 zfill()函数 11.0 count()函数 13.0 decode()函数 14.0 expandtabs()函数 15.0 find()函数 16.0 rfind()…...
纵览!报表控件 Stimulsoft Reports、Dashboards 和 Forms 2025.1 新版本发布!
Stimulsoft 2025.1 新版发布,旨在增强您创建报告、仪表板和 PDF 表单的体验!此最新版本为您带来了许多改进和新功能,使数据处理更加高效和用户友好。亮点包括对 .NET 9 的支持、Microsoft Analysis Services 的新数据适配器、发布向导中适用于…...
【蓝桥杯——物联网设计与开发】Part2:OLED
目录 一、OLED (1)资源介绍 🔅原理图 🔅驱动原理 (2)STM32CubeMX 软件配置 (3)代码编写 (4)实验现象 二、OLED接口函数封装 🟡️OLED_Wri…...
壁纸样机神器,这个工具适合专业设计师用吗?
壁纸样机神器在一定程度上适合专业设计师使用,但是否适合具体取决于设计师的需求和使用场景: 适合专业设计师的方面 快速实现设计想法:专业设计师在创作过程中,有时需要快速将设计想法变为可视化的效果图,以便进行初…...
Linux环境(CentOs7) 安装 Node环境
Linux环境(CentOs7) 安装 Node环境 使用NodeSource安装Node.js 1、清除缓存(可选但推荐) sudo yum clean all2、添加NodeSource仓库,根据你想要安装的Node.js版本,选择相应的NodeSource安装脚本。例如&am…...
【Springboot知识】Springboot集成assembly打包组件
assembly系统打包 概述一、项目结构二、配置Maven Assembly插件三、配置assembly.xml四、打包项目五、部署和使用六、注意事项 assembly配置文件说明一、assembly配置文件的基本结构二、assembly配置文件的关键元素三、assembly配置文件的示例四、assembly配置文件与Spring Boo…...
逻辑推理算法
为说明逻辑推理算法的用法,下面是一个简单的逻辑推理算法的伪代码示例,使用了命题逻辑的推理规则(例如:命题逻辑中的合取、析取、否定等)。代码实现了一个简单的推理引擎,可以根据已知的前提推导出新的结论…...
鸿蒙1.2:第一个应用
1、create Project,选择Empty Activity 2、配置项目 project name 为项目名称,建议使用驼峰型命名 Bundle name 为项目包名 Save location 为保存位置 Module name 为模块名称,即运行时需要选择的模块名称,见下图 查看模块名称&…...
数据结构考前一天
线性表:矩阵,链表(单链表必考) 栈和队列:出入判断,括号匹配,中缀转后缀 字符串数组:模式匹配next,nextval数组,数组寻址,三角矩阵对应一维数组k…...
【记录】Angr|Angr 标准库函数替换怎么看哪些库函数被Angr支持?
文章目录 前言分析什么是库函数替换?为什么需要库函数替换? 如何查找支持的库函数官方支持列表目录结构说明 常用的替换包括哪些?1. 字符串处理函数2. 内存管理函数3. 文件操作函数 高级技巧1. 自定义库函数实现2. 条件替换 常见问题与解决方案详解1. 找不到合适的…...
npx和npm和pnpm的异同
npx、npm 和 pnpm 都是用于管理和运行 JavaScript/Node.js 包的工具,但它们的功能和使用场景有所不同。以下是它们之间的异同点: 一、共同点 Node.js 包管理生态的一部分: 它们都围绕 Node.js 生态系统,提供包管理功能。 支持安装…...
【蓝桥杯比赛-C++组-经典题目汇总】
1. 最短路 题目描述: 如下图所示,G是一个无向图,其中蓝色边的长度是1、橘色边的长度是2、绿色边的长度是3。 则从 A 到 S 的最短距离是多少? #include <iostream> #include <cstring> using namespace std; const i…...
redis7基础篇2 redis的主从模式1
目录 一 主从模式 1.1 主从复制的作用 1.2 配置常用命令 1.3 主从复制常见问题 1.4 主从复制的缺点 1.5 redis主从复制原理 二 redis主从复制的搭建流程 2.1 注意事项 2.2 redis的主从复制架构图 2.3 以6379.conf配置文件配置为例 2.4 以6380.conf配置文件配置为例 …...
QT----------QT Data Visualzation
实现思路: 配置项目:在 .pro 文件中添加 QT datavisualization 以引入 QT Data Visualization 模块。创建主窗口:使用 QMainWindow 作为主窗口,添加 Q3DScatter、Q3DBars 和 Q3DSurface 等三维视图组件。初始化和创建三维图表&a…...
默认ip无法访问,利用dhcp功能获取ip进行访问的方法
应用场景: ac的默认ip如192.168.1.1在pc与ac的eth2以后网口直连无法ping通,而且pc改为dhcp自动获取ip也获取不到ip地址,无法进行web配置和命令行操作。 原因是ac或其他设备被修改了默认ip或者端口vlanid,现在的端口vlan对应子接…...
重学 Android 自定义 View 系列(十):带指针的渐变环形进度条
前言 该篇文章根据前面 重学 Android 自定义 View 系列(六):环形进度条 拓展而来。 最终效果如下: 1. 扩展功能 支持进度顺时针或逆时针显示在进度条末尾添加自定义指针图片使用线性渐变为进度条添加颜色效果 2. 关键技术点解析 2.1 进度方向控制的…...
websocket在各主流浏览器中默认的请求头是如何设置的?
谷歌浏览器(Chrome) 在谷歌浏览器中,当创建一个 WebSocket 连接时,会自动添加一些标准的请求头。其中包括Sec - WebSocket - Key,这个是一个 Base64 - 编码的随机值,长度为 16 字节。它用于在服务器端进行安全验证,确保连接的合法性。例如,Sec - WebSocket - Key: dGhl…...
C++之map和set的模拟实现
目录 引言 红黑树迭代器实现 红黑树元素的插入 map模拟实现 set模拟实现 之前我们已经学习了map和set的基本使用,但是因为map和set的底层都是用红黑树进行封装实现的,上期我们已经学习了红黑树的模拟实现,所以本期我们在红黑树模拟实现…...
大学物理(2)期末复习笔记【1】
图片不知道咋回事居然不能直接复制上来,过段时间修改好再编辑一下 9. 振动 一、振动 def:某一物理量在某一数值附近做周期性变化 周期(T):完成一次往复运动所需要的时间(s) 频率(…...
25.1.3
java数组: dataType[] arrayRefVar //推荐写法 //int[] mylist //或 dataType arrayRefVar[] //int mylist[]创建数组对象: arrayRefVar new dataType[arraySize]; dataType[] arrayRefVar new dataType[arraySize];for-each循环: jav…...
数据库知识汇总2
一. 范式 定义:范式是符合某一种级别的关系模式的集合。 关系数据库中的关系必须满足一定的要求。满足不同程度要求的为不同范式; 一个低一级范式的关系模式,通过模式分解(schema decomposition)可以转换为若干个高一…...
SpringBoot:生成条形码的项目
在软件开发中,条形码和二维码的生成与解析是一项常见需求,特别是在商品管理、物流跟踪、支付验证等场景。Spring Boot 作为一个流行的微服务框架,提供了快速构建应用的能力。本文将介绍如何在 Spring Boot 项目中生成条形码,并提供…...
docker内外如何实现ROS通信
写在前面 在一台电脑上装有docker,docker内外均装有ROS系统,现在想要实现docker内外的ROS通信,怎么办呢? 首先,因为是同一台电脑的docker内外,所以IP本身是互通的,不需要在/etc/hosts中添加IP…...
leetcode 面试经典 150 题:多数元素
链接多数元素题序号169题型数组解法1. 排序法、2. Boyer-Moore投票算法难度简单熟练度✅✅✅✅✅ 题目 给定一个大小为 n 的数组 nums ,返回其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。 你可以假设数组是非空的,并且给定的…...
SpringBoot返回文件让前端下载的几种方式
01 背景 在后端开发中,通常会有文件下载的需求,常用的解决方案有两种: 不通过后端应用,直接使用nginx直接转发文件地址下载(适用于一些公开的文件,因为这里不需要授权)通过后端进行下载&#…...
论述数据、数据库、数据库管理系统、数据库系统的概念。
数据是指描述事物特征的符号记录,可以是数字、文字、图像、音频等形式。数据在现代社会中广泛存在于各个领域,对于组织和管理数据,提供数据的可靠性、一致性和安全性至关重要。 数据库是一个有组织的数据集合,它存储在计算机系统…...
【深度学习基础之多尺度特征提取】多尺度卷积神经网络(MS-CNN)是如何在深度学习网络中提取多尺度特征的?附代码(二)
【深度学习基础之多尺度特征提取】多尺度卷积神经网络(MS-CNN)是如何在深度学习网络中提取多尺度特征的?附代码(二) 【深度学习基础之多尺度特征提取】多尺度卷积神经网络(MS-CNN)是如何在深度…...
企业AAA认证的好处
体系认证#ISO三体系认证 #三体系认证好处 #企业双软认证好处 #ISO体系认证有哪些#体系认证办理流程及费用#招投标#招投标必备资质 企业信用评级AAA认证 办理条件及流程! 一、企业申请3A认证好处有哪些? 1.提高企业信誉: 拥有3A企业信用等级证书意味…...
PyTorch AMP 混合精度中grad_scaler.py的scale函数解析
PyTorch AMP 混合精度中的 scale 函数解析 混合精度训练(AMP, Automatic Mixed Precision)是深度学习中常用的技术,用于提升训练效率并减少显存占用。在 PyTorch 的 AMP 模块中,GradScaler 类负责动态调整和管理损失缩放因子&…...
分数阶傅里叶变换代码 MATLAB实现
function Faf myfrft(f, a) %分数阶傅里叶变换函数 %输入参数: %f:原始信号 %a:阶数 %输出结果: %原始信号的a阶傅里叶变换N length(f);%总采样点数 shft rem((0:N-1)fix(N/2),N)1;%此项等同于fftshift(1:N),起到翻…...
腾讯云OCR在制造业的应用:内存模组产品识别实战指南
腾讯云OCR在制造业的应用 一、 背景二、 腾讯云OCR技术概述三、 内存模组产品识别需求四、基于腾讯云OCR的内存模组产品识别4.1、准备工作4.2、API调用与代码实现 五、 代码示例六、 应用场景七、 总结 一、 背景 制造业在产品识别环节经历着前所未有的挑战。传统的依赖人工进…...
基于STM32F1的基本定时器的原理
一,基本定时器原理 1,进入数据手册,了解基本定时器的主要特征 2,看懂理解基本定时器框图 3,查阅2.3章中的存储器映像以及时钟树就可以知道定时器是挂载在哪个总线下,从而知道对应是时钟频率 4,…...
Adobe Acrobat Pro DC 2023 下载安装教程,附详细图文
简介: Adobe Acrobat Pro DC 2023 是由 Adobe 公司推出的一款全面的 PDF 编辑、查看和管理软件。这款软件无论是个人用户还是企业级用户,都可以凭借其强大的功能满足不同的需求。作为一款业内领先的 PDF 处理工具,Adobe Acrobat Pro DC 不仅…...
活动预告 |【Part1】 Azure 在线技术公开课:迁移和保护 Windows Server 和 SQL Server 工作负载
课程介绍 通过 Microsoft Learn 免费参加 Microsoft Azure 在线技术公开课,掌握创造新机遇所需的技能,加快对 Microsoft 云技术的了解。参加我们举办的“迁移和保护 Windows Server 和 SQL Server 工作负载”活动,了解 Azure 如何为将工作负载…...
根据 el-dialog 的高度动态计算 el-table 的高度
根据 el-dialog 的高度动态计算 el-table 的高度,可以使用 Vue 的 ref 和生命周期钩子来实现。以下是一个实现方案: 首先,给 el-dialog 和 el-table 添加 ref: <el-dialogv-model"testInstrumentDialogVisible"tit…...
算法解析-经典150(双指针、滑动窗口)
文章目录 双指针1.验证回文串1.答案2.思路 2.判断子序列1.动态规划解法2.双指针 3.两数之和 II - 输入有序数组1.答案2.思路 4.盛最多水的容器1.答案2.思路 5.三数之和1.答案2.思路 滑动窗口1.长度最小的子数组1.答案2.思路 2.无重复字符的最长子串1.答案2.思路 3.最小覆盖子串…...
Postman[2] 入门——界面介绍
可参考官方 文档 Postman 导航 | Postman 官方帮助文档中文版Postman 拥有各种工具、视图和控件,帮助你管理 API 项目。本指南是对 Postman 主要界面区域的高级概述:https://postman.xiniushu.com/docs/getting-started/navigating-postman 1. Header&a…...