- Practical Data Analysis Cookbook
- Tomasz Drabas
- 315字
- 2021-07-16 11:13:54
Normalizing and standardizing the features
We normalize (or standardize) data for computational efficiency and so we do not exceed the computer's limits. It is also advised to do so if we want to explore relationships between variables in a model.
Normalization transforms all the observations so that all their values fall between 0
and 1
(inclusive). Standardization shifts the distribution so that the mean of the resultant values is 0
and standard deviation equals 1
.
Getting ready
To execute this recipe, you will need the pandas
module.
No other prerequisites are required.
How to do it…
To perform normalization and standardization, we define two helper functions (the data_standardize.py
file):
def normalize(col): ''' Normalize column ''' return (col - col.min()) / (col.max() - col.min()) def standardize(col): ''' Standardize column ''' return (col - col.mean()) / col.std()
How it works…
To normalize a set of observations, that is, to make each and every single one of them to be between 0
and 1
, we subtract the minimum value from each observation and divide it by the range of the sample. The range in statistics is defined as a difference between the maximum and minimum value in the sample. Our normalize(...)
method does exactly as described previously: it takes a set of values, subtracts the minimum from each observation, and divides it by the range.
Standardization works in a similar way: it subtracts the mean from each observation and divides the result by the standard deviation of the sample. This way, the resulting sample has a mean equal to 0
and standard deviation equal to 1
. Our standardize(...)
method performs these steps for us:
csv_read['n_price_mean'] = normalize(csv_read['price_mean']) csv_read['s_price_mean'] = standardize(csv_read['price_mean'])
- TypeScript Blueprints
- Android Development with Kotlin
- Django Design Patterns and Best Practices
- Java Web開發(fā)技術(shù)教程
- 名師講壇:Java微服務(wù)架構(gòu)實戰(zhàn)(SpringBoot+SpringCloud+Docker+RabbitMQ)
- SharePoint Development with the SharePoint Framework
- Processing創(chuàng)意編程指南
- C++從入門到精通(第6版)
- Java Web開發(fā)實例大全(基礎(chǔ)卷) (軟件工程師開發(fā)大系)
- Modernizing Legacy Applications in PHP
- 深度實踐KVM:核心技術(shù)、管理運維、性能優(yōu)化與項目實施
- Puppet:Mastering Infrastructure Automation
- SCRATCH編程課:我的游戲我做主
- 產(chǎn)品架構(gòu)評估原理與方法
- JavaScript Unit Testing