How to implement Scaling in R

r
machine_learning

#1

HI Experts ,

PLease help me understanding the following code.

maxs <- apply(data, 2, max)
mins <- apply(data, 2, min)

scaled <- as.data.frame(scale(data, center = mins, scale = maxs - mins))

Regards,
tony


#2

@tillutony explanation

  1. maxs <- apply(data, 2, max) # you have used apply function to retrieve max value from data and store in object name maxs

  2. mins <- apply(data, 2, min) # you have used apply function to retrieve min value from data and store in object name mins

  3. scaled <- as.data.frame(scale(data, center = mins, scale = maxs - mins)) # 1st all scaling concept came in to picture when you have a dataset which contain different column, measured at different scale (i.e Weight, height,distance all in a data frame), to bring down all the column in a common scale range, we use scale function.
    In your code you have scaled the data by keeping the minus value at center and than getting the range by subtracting the maxs with mins and storing it in scale , after that using scale function to bring down the entire data-set in a common range .


#3

Thank a ton HUNAIDKHAN2000.

we have many options to scale or normalise the data which methods are good and when to use please kindly let me know.

Regards,
Tony


#4

Use the box cox transformation from caret package. Very easy and useful.