正態分布高斯分布泊松分布_正態分布:將數據轉換為高斯分布

正態分布高斯分布泊松分布

For detailed implementation in python check my GitHub repository.

有關在python中的詳細實現,請查看我的GitHub存儲庫。

介紹 (Introduction)

Some machine learning model like linear and logistic regression assumes a Gaussian distribution or normal distribution. One of the first steps of statistical analysis of your data is therefore to check the distribution of the data.

某些機器學習模型(例如線性和邏輯回歸)采用高斯分布或正態分布。 因此,對數據進行統計分析的第一步就是檢查數據的分布。

The familiar bell curve shows a normal distribution.

熟悉的鐘形曲線顯示正態分布。

Image for post

If your data has a Gaussian distribution, the machine learning methods are powerful and well understood.

如果您的數據具有高斯分布,則機器學習方法功能強大且易于理解。

Most of the data scientists claim they are getting more accurate results when they transform the predictor variables.

大多數數據科學家聲稱,他們在轉換預測變量時會獲得更準確的結果。

To transform data, you perform a mathematical operation on each observation, then use these transformed data in our model.

要轉換數據,您需要對每個觀測值執行數學運算,然后在我們的模型中使用這些轉換后的數據。

為什么我們需要正態分布? (Why do we need a normal distribution?)

If a method that assumes a Gaussian distribution, and your data was drawn from a different distribution other then normal distribution, then the findings may be misleading or plain wrong.

如果采用假定高斯分布的方法,并且您的數據是從不同于正態分布的其他分布中提取的,則發現可能會產生誤導或明顯錯誤。

It is possible that your data does not look Gaussian or fails a normality test, but can be transformed to make it fit a Gaussian distribution.

您的數據看起來可能不是高斯或未通過正態性檢驗,但可以進行轉換以使其適合高斯分布。

轉換類型 (Type of transformation)

  1. Log Transformation

    日志轉換
  2. Reciprocal Transformation

    相互轉換
  3. Square-Root Transformation

    平方根變換
  4. Cube root Transformation

    立方根轉換
  5. Exponential Transformation

    指數變換
  6. Box-Cox Transformation

    Box-Cox轉換
  7. Yeo-Johnson Transformation

    楊約翰遜變換

可視化并檢查分布 (Visualize and Checks distribution)

We can create plots of the data to check whether it is Gaussian or not.

我們可以創建數據圖以檢查其是否為高斯。

We will look at two common methods for visually inspecting a dataset to check if it was drawn from a Gaussian distribution.

我們將看兩種常見的方法,以可視方式檢查數據集以檢查它是否是從高斯分布中提取的。

  1. Histogram

    直方圖
  2. Quantile-Quantile plot (Q-Q plot)

    分位數圖(QQ圖)

1.直方圖 (1. Histogram)

A histogram is a plot that lets you discover, and show, the underlying frequency distribution (shape) of a set of continuous data. This allows the inspection of the data for its underlying distribution (e.g., normal distribution), outliers, skewness, etc.

直方圖是一種圖表,可讓您發現并顯示一組連續數據的基礎頻率分布(形狀)。 這允許檢查數據的基本分布(例如,正態分布),離群值,偏度等。

Image for post

2. QQ圖 (2. Q-Q Plot)

The Q-Q plot, or quantile-quantile, are plots of two quantiles against each other. A quantile is a fraction where certain values fall below that quantile.

QQ圖(或分位數)是兩個分位數彼此相對的圖。 分位數是某些值低于該分位數的分數。

For example, the median is a quantile where 50% of the data fall below that point and 50% lie above it.

例如,中位數是一個分位數,其中50%的數據低于該點,而50%的數據位于該點之上。

The purpose of Q Q plots is to find out if two sets of data come from the same distribution. A 45-degree angle is plotted on the Q Q plot; if the two data sets come from a common distribution, the points will fall on that reference line.

QQ圖的目的是找出兩組數據是否來自同一分布。 QQ圖上繪制了45度角; 如果兩個數據集來自同一分布,則這些點將落在該參考線上。

Image for post

數據 (Data)

We will use randomly generated data in this article to demonstrate all techniques.

我們將在本文中使用隨機生成的數據來演示所有技術。

# generate a univariate data sample
np.random.seed(142)
datas = sorted(stats.lognorm.rvs(s=0.5, loc=1, scale=1000, size=1000))# convert to dataframe
data = pd.DataFrame(datas, columns=['values'])#

生成圖的方法 (Method to generate a graph)

After we transform our data each time we will call this method to generate a graph.

每次轉換數據后,我們將調用此方法來生成圖形。

def gen_graph(value):
plt.figure(figsize=(15,5))
plt.subplot(1, 2, 1)
plt.hist(value, color='g', alpha=0.5) plt.subplot(1, 2, 2)
stats.probplot(value, dist="norm", plot=plt) plt.show()

轉換前可視化數據 (visualize data before transformation)

gen_graph(data['values'])
Image for post

1.日志轉換 (1. Log Transformation)

Log or Logarithmic transformation is a data transformation method in which we replace each variable x with a log(x). When our original continuous data do not follow the bell curve, we can log transform this data to make it “normal”.

對數或對數轉換是一種數據轉換方法,其中我們將每個變量x替換為log(x)。 當我們的原始連續數據不遵循鐘形曲線時,我們可以對數據進行對數轉換以使其“正常”。

data_log = np.log(data['values'])gen_graph(data_log)
Image for post

2.相互轉化 (2. Reciprocal Transformation)

The reciprocal transformation is defined as the transformation of x to 1/x. The transformation has a dramatic effect on the shape of the distribution, reversing the order of values with the same sign. The transformation can only be used for non-zero values.

互逆變換定義為x到1 / x的變換。 變換對分布的形狀產生了巨大影響,顛倒了具有相同符號的值的順序。 轉換只能用于非零值。

data_rec = np.reciprocal(data['values'])# ordata_rec_2 = 1/data['values']gen_graph(data_rec)
Image for post

3.平方根變換 (3. Square-Root Transformation)

The square root of your variables, i.e. x → x(1/2) = sqrt(x). This will have a moderate effect on the distribution and usually works for data with non-constant variance. However, it is considered to be weaker than logarithmic or cube root transforms.

變量的平方根,即x→x(1/2)= sqrt(x)。 這將對分布產生適度的影響,并且通常適用于具有非恒定方差的數據。 但是,它被認為比對數或立方根轉換要弱。

data_square = np.sqrt(data['values'])# or 
data_square_2 = (data)**(1/2)gen_graph(data_square)
Image for post

4.多維數據集根轉換 (4. Cube root Transformation)

The cube root transformation involves converting x to x^(1/3).

立方根轉換涉及將x轉換為x ^(1/3)。

It is useful for reducing the right skewness. This is a fairly strong transformation with a substantial effect on the distribution shape but is weaker than the logarithm. It can be applied to negative and zero values too. Negatively skewed data.

這對于減少正確的偏斜很有用。 這是一個相當強的變換,對分布形狀有很大影響,但比對數弱。 它也可以應用于負值和零值。 負偏斜數據。

data_cube = np.cbrt(data['values'])gen_graph(data_cube)
Image for post

5.指數變換 (5. Exponential Transformation)

An exponential transformation provides a useful alternative to Box and Cox’s, one parameter power transformation, and has the advantage of allowing negative data values.

指數變換是Box和Cox變換的一種有用的替代方法,它是一種參數冪變換,并且具有允許負數據值的優點

It has been found in particular that this transformation is quite effective at turning skew unimodal distribution into nearly symmetric normal like distribution.

特別地,已經發現該變換在將偏斜單峰分布轉變成近似對稱的正態分布方面非常有效。

Image for post
data_expo =  data['values'] ** (1/5)gen_graph(data_expo)
Image for post

6. Box-Cox轉換 (6. Box-Cox Transformation)

At the core of the Box-Cox transformation is an exponent, lambda (λ), which varies from -5 to 5.

Box-Cox變換的核心是指數lambda(λ),從-5到5不等。

All values of λ are considered, and the optimal value for your data is selected; The “optimal value” is the one which results in the best approximation of a normal distribution curve. The transformation of Y has the form:

考慮所有λ值,并選擇數據的最佳值; “最佳值”是導致正態分布曲線最佳近似的值。 Y的轉換形式為:

Image for post
data_boxcox, a = stats.boxcox(data['values'])gen_graph(data_boxcox)
Image for post

7.楊約翰遜轉型 (7. Yeo-Johnson Transformation)

This is one of the older transformation technique which is very similar to Box-cox transformation but does not require the values to be strictly positive.This transformation is also having the ability to make the distribution more symmetric.

這是較舊的變換技術之一,與Box-cox變換非常相似,但不需要嚴格將值設為正數。此變換還具有使分布更加對稱的能力。

data_yeo, a = stats.yeojohnson(data['values'])gen_graph(data_yeo)
Image for post

結論 (Conclusion)

In this article, we have seen the different types of transformations to normalized the distribution of data. Box-cox and log transformation is one of the best transformation technique that gives us a good result.

在本文中,我們已經看到了不同類型的轉換以標準化數據的分布。 Box-cox和log轉換是最好的轉換技術之一,可以為我們帶來良好的效果。

Hope you like this article.

希望您喜歡這篇文章。

Follow me for more such interesting article

跟隨我獲得更多如此有趣的文章

Please clap and show your appreciation :)

請鼓掌并表示感謝:)

Thanks for reading. 😃

謝謝閱讀。 😃

翻譯自: https://medium.com/next-gen-machine-learning/normal-distribution-data-transformation-to-gaussian-distribution-405941324f53

正態分布高斯分布泊松分布

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388507.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388507.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388507.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

BABOK - 開篇:業務分析知識體系介紹

本文更新版已挪至 http://www.zhoujingen.cn/itbang/328.html ---------------------------------------------- 當我們作項目時,下面這張圖很多人都明白,從計劃、構建、測試、部署實施后發現提供的方案并不能真正解決用戶的問題,那么我們是…

對象-檢測屬性

<h3>判斷某個屬性是否存在于某個對象中&#xff1b;</h3><ol><li>in&#xff1a;檢查一個屬性是否屬于某個對象&#xff0c;包括繼承來的屬性&#xff1b;<pre>var person {name:yourname, age:10};console.log(name in person); //trueconsole…

黑蘋果 wifi android,動動手指零負擔讓你的黑蘋果連上Wifi

動動手指零負擔讓你的黑蘋果連上Wifi2019-12-02 10:08:485點贊36收藏4評論購買理由黑蘋果Wifi是個頭疼的問題&#xff0c;高“貴”的原機Wifi藍牙很貴&#xff0c;比如我最近偶然得到的BCM94360CS2&#xff0c;估計要180。稍微便宜的一點的&#xff0c;搞各種ID&#xff0c;各種…

洛谷——P2018 消息傳遞

P2018 消息傳遞 題目描述 巴蜀國的社會等級森嚴&#xff0c;除了國王之外&#xff0c;每個人均有且只有一個直接上級&#xff0c;當然國王沒有上級。如果A是B的上級&#xff0c;B是C的上級&#xff0c;那么A就是C的上級。絕對不會出現這樣的關系&#xff1a;A是B的上級&#xf…

axios異步請求數據的簡單使用

使用Mock模擬好后端數據之后&#xff08;Mock模擬數據的使用參考&#xff1a;https://segmentfault.com/a/11...&#xff09;&#xff0c;就需要嘗試請求加載數據了。數據請求選擇了axios&#xff0c;現在都推薦使用axios。 axios&#xff08;https://github.com/axios/axios&a…

float在html語言中的用法,float屬性值包括

html中不屬于float常用屬性值的是float常用的值就三個:left\right\none。沒有其他的值了。 其中none這個值是默認的&#xff0c;所以一般不用寫。css中float屬性有幾種用法&#xff1f;值 描述left 元素向左浮動。 right 元素向右浮動。 none 默認值。元素不浮動&#xff0c;并…

它們是什么以及為什么我們不需要它們

Once in a while, when reading papers in the Reinforcement Learning domain, you may stumble across mysterious-sounding phrases such as ‘we deal with a filtered probability space’, ‘the expected value is conditional on a filtration’ or ‘the decision-mak…

LoadRunner8.1破解漢化過程

LR8.1版本已經將7.8和8.0中通用的license封了&#xff0c;因此目前無法使用LR8.1版本&#xff0c;包括該版本的中文補丁。 破解思路&#xff1a;由于軟件的加密程序和運行的主程序是分開的&#xff0c;因此可以使用7.8的加密程序覆蓋8.1中的加密程序&#xff0c;這樣老的7.8和…

TCP/IP網絡編程之基于TCP的服務端/客戶端(二)

回聲客戶端問題 上一章TCP/IP網絡編程之基于TCP的服務端/客戶端&#xff08;一&#xff09;中&#xff0c;我們解釋了回聲客戶端所存在的問題&#xff0c;那么單單是客戶端的問題&#xff0c;服務端沒有任何問題&#xff1f;是的&#xff0c;服務端沒有問題&#xff0c;現在先讓…

談談iOS獲取調用鏈

本文由云社區發表iOS開發過程中難免會遇到卡頓等性能問題或者死鎖之類的問題&#xff0c;此時如果有調用堆棧將對解決問題很有幫助。那么在應用中如何來實時獲取函數的調用堆棧呢&#xff1f;本文參考了網上的一些博文&#xff0c;講述了使用mach thread的方式來獲取調用棧的步…

python 移動平均線_Python中的移動平均線

python 移動平均線There are situations, particularly when dealing with real-time data, when a conventional average is of little use because it includes old values which are no longer relevant and merely give a misleading impression of the current situation.…

Ireport制作過程

Ireport制作過程 1、首先要到Option下設置一下ClassPath添加文件夾 2、到預覽->報表字段設置一下將要用到的字段 3、到編輯->查詢報表->寫sql語句&#xff0c;然后把語句查詢的字段結果與上面設置的報表字段的名要對應上 4、Option->選項->Compiler設置一下…

2018.09.16 loj#10243. 移棋子游戲(博弈論)

傳送門 題目中已經給好了sg圖&#xff0c;直接在上面跑出sg函數即可。 最后看給定點的sg值異或和是否等于0就判好了。 代碼&#xff1a; #include<bits/stdc.h> #define N 2005 #define M 6005 using namespace std; int n,m,k,sg[N],first[N],First[N],du[N],cnt0,an…

html5字體的格式轉換,font字體

路由器之家網今天精心準備的是《font字體》&#xff0c;下面是詳解&#xff01;html中的標簽是什么意思HTML提供了文本樣式標記&#xff0c;用來控制網頁中文本的字體、字號和顏色&#xff0c;多種多樣的文字效果可以使網頁變得更加絢麗。其基本語法格式&#xff1a;文本內容fa…

紅星美凱龍牽手新潮傳媒搶奪社區消費市場

瞄準線下流量紅利&#xff0c;紅星美凱龍牽手新潮傳媒搶奪社區消費市場 中新網1月14日電 2019年1月13日&#xff0c;紅星美凱龍和新潮傳媒戰略合作發布會在北京召開&#xff0c;雙方宣布建立全面的戰略合作伙伴關系。未來&#xff0c;新潮傳媒的梯媒產品將入駐紅星美凱龍的全國…

機器學習 啤酒數據集_啤酒數據集上的神經網絡

機器學習 啤酒數據集Artificial neural networks (ANNs), usually simply called neural networks (NNs), are computing systems vaguely inspired by the biological neural networks that constitute animal brains.人工神經網絡(ANN)通常簡稱為神經網絡(NNs)&#xff0c;是…

實例演示oracle注入獲取cmdshell的全過程

以下的演示都是在web上的sql plus執行的&#xff0c;在web注入時 把select SYS.DBMS_EXPORT_EXTENSION.....改成   /xxx.jsp?id1 and 1<>a||(select SYS.DBMS_EXPORT_EXTENSION.....)   的形式即可。(用" a|| "是為了讓語句返回true值)   語句有點長…

html視頻位置控制器,html5中返回音視頻的當前媒體控制器的屬性controller

實例檢測該視頻是否有媒體控制器&#xff1a;myViddocument.getElementById("video1");alert("Controller: " myVid.controller);定義和用法controller 屬性返回音視頻的當前媒體控制器。默認地&#xff0c;音視頻元素不會有媒體控制器。如果規定了媒體控…

ER TO SQL語句

ER TO SQL語句的轉換&#xff0c;在數據庫設計生命周期的位置如下所示。 一、轉換的類別 從ER圖轉化得到關系數據庫中的SQL表&#xff0c;一般可分為3類&#xff1a; 1&#xff09;轉化得到的SQL表與原始實體包含相同信息內容。該類轉化一般適用于&#xff1a; 二元“多對多”關…

dede 5.7 任意用戶重置密碼前臺

返回了重置的鏈接&#xff0c;還要把&amp刪除了&#xff0c;就可以重置密碼了 結果只能改test的密碼&#xff0c;進去過后&#xff0c;這個居然是admin的密碼&#xff0c;有點頭大&#xff0c;感覺這樣就沒有意思了 我是直接上傳的一句話&#xff0c;用菜刀連才有樂趣 OK了…