【问题标题】:how can i denormalization the data of a dataframe [duplicate]我如何对数据框的数据进行非规范化[重复]
【发布时间】:2017-06-23 03:21:40
【问题描述】:

我已经尝试过遵循一个数据框的规范化。我在非规范化数据帧方面遇到问题。 如何对其进行非规范化。

      form <- function(x) {(x - min(x, na.rm=TRUE))/(max(x,na.rm=TRUE) - 
                                             min(x, na.rm=TRUE))} 
      normed <- as.data.frame(lapply(m1, form)) 

数据集

      'data.frame': 96611 obs. of  10 variables:
       $ Timestamp       : num  1388619000 1388619900 1388620800 1388621700    1388622600 ...
       $ avg.price       : num  -14.55 -10.73 0.65 0.62 0.18 ...
       $ weekday         : num  4 4 5 5 5 5 5 5 5 5 ...
       $ total.energy    : num  0.76 0.18 330.56 1.75 1.62 ...
       $ O.avgprice      : num  -10.17 -13.79 -2.64 -9.77 -2.96 ...
       $ O.firstquartil  : num  -20 -24.25 -5.42 -13.74 -4.45 ...
       $ O.thirdquartil  : num  -3.29 -6.78 -1.3 -0.19 -2.2 0 5 -1.92 0.22 5.08 ...

【问题讨论】:

  • 请添加您的数据的工作示例。
  • 感谢它的工作 - @ saurabh

标签: r


【解决方案1】:

您为什么不直接反转您的公式?如果使用归一化

(x - min(x, na.rm=TRUE))/(max(x,na.rm=TRUE) - min(x, na.rm=TRUE))

使用

(x * (max(y, na.rm=TRUE) - min(y, na.rm=TRUE)) + min(y, na.rm=TRUE))

用于非规范化,y 在规范化之前引用您的原始数据。

工作示例:

test <- list(c(1,5,6,7,10), c(2,4,6,6,12))
> test
[[1]]
[1]  1  5  6  7 10

[[2]]
[1]  2  4  6  6 12

testnorm <- lapply(test, function(x) (x-min(x))/(max(x)-min(x)))
> testnorm
[[1]]
[1] 0.0000000 0.4444444 0.5555556 0.6666667 1.0000000

[[2]]
[1] 0.0 0.2 0.4 0.4 1.0

testdenorm <- mapply(function(x, y) (x*(max(y)-min(y)))+min(y), testnorm, test)
> testdenorm
     [,1] [,2]
[1,]    1    2
[2,]    5    4
[3,]    6    6
[4,]    7    6
[5,]   10   12

确保使用原始数据的 min()max() 值。如果你没有这些,恐怕你不走运。

【讨论】:

  • 我已经试过了,它给了我和正常化一样的效果
  • 我已经包含了一个例子。
  • 感谢您的时间和努力。
猜你喜欢
  • 2017-03-29
  • 2017-10-05
  • 2010-10-22
  • 1970-01-01
  • 2013-06-30
  • 2021-09-05
  • 1970-01-01
  • 2018-12-12
  • 2017-03-01
相关资源
最近更新 更多