Question: need a help in Transform the Data, can you please help in correcting my below code Question 2 - Transform the Data ################################ I <

need a help in Transform the Data, can you please help in correcting my below code
Question 2-Transform the Data
################################
I <-c(1,2,3,4,6)# Choose any four X variables and Y
head(data.subset)
variables_for_transform <-data.subset[,I] # obtain a 400by 5matrix
# Initialize transformed data matrix
data.transformed <-variables_for_transform
head(data.transformed)
# for each variable, you need to figure out a good data transformation method,
# such as Polynomial, log and negation transformation. The k-S test and Skewness
# calculation may be helpful to select the transformation method
p=0.5# for example, using p=0.5to transform the first variable. You should change p based on your distribution.
data.transformed[,1]<-variables_for_transform[,1]^p # Power transformation for Citric Acid (weak positive correlation)
data.transformed[,2]<-log(variables_for_transform[,2]+1) # Log transformation for Chlorides (negative correlation)
data.transformed[,3]<--variables_for_transform[,3] # Negation for Total Sulfur Dioxide (negative correlation)
data.transformed[,4]<-variables_for_transform[,4]^p # Power transformation for pH (no clear relationship)
#data.transformed[,5]<-variables_for_transform[,5] #alcohol variable will not undergo any transformation (e.g.,power, log,or negation)since it already has a clear positive correlation with the target variable (quality)
# A Min-Max and/or Z-score transformation should then be used to adjust the scale of each variable
# min-max normalisation
minmax <-function(x){
(x -min(x))/(max(x)-min(x))
}
# z-score standardisation and scaling to unit interval
unit.z <-function(x){
0.15*((x-mean(x))/sd(x))+0.5
}
# Apply scaling
data.transformed[,1]<-minmax(data.transformed[,1]) # Min-Max for Citric Acid
data.transformed[,2]<-unit.z(data.transformed[,2]) # Z-Score for Chlorides
data.transformed[,3]<-minmax(data.transformed[,3]) # Min-Max for Total Sulfur Dioxide
data.transformed[,4]<-unit.z(data.transformed[,4]) # Z-Score for pH
#data.transformed[,5]<-minmax(data.transformed[,5]) # Min-Max for Quality
# Save this transformed data to a text file
write.table(data.transformed, "test-transformed.txt")
can you help in transformation? I am not getting what i am doing wrong here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!