【问题标题】:Values of Variable change to N/As after data normalization数据标准化后变量的值变为 N/As
【发布时间】:2019-07-02 05:52:26
【问题描述】:

对于多项式回归,我应该标准化我的数据集(来自世界银行数据的 1960-2017 年巴西 GDP)

使用:

x= x - min(x)
x= x/max(T)           

通过将“x”更改为我们的自变量。

我尝试联系讲师没有回应,也尝试了不同的数据集,但这个集是唯一不起作用的。

##Task 3.1##
##Load Data ##
GDP_Brazil <- read_excel("GDP Brazil.xlsx") 

View(GDP_Brazil)

##Plotting the original Data

G=GDP_Brazil[,3]
Time=GDP_Brazil[,2]

##3.2
##Normalization of data

Time= Time - min(Time)
Time= Time/max(Time)

运行此代码后,该变量的数据为 N/A

运行代码后,Variable Time 的结果从 [1960,2017] 变为 N/A,但应该在 [0,1] 之间。

【问题讨论】:

  • 值更改为 NA 的原因可能有多种,但如果没有可重现的示例,很难准确判断。可以分享dput(head(GDP_Brazil))吗?
  • 据推测,数据包含缺失的 (NA) 值。您可以在进行规范化时忽略它们,方法是执行 min(Time, na.rm = TRUE)max(Time, na.rm = TRUE)

标签: r normalization na minmax


【解决方案1】:

这里是信息。数据集不包含 N/As。每年都会给出这些值,这实际上是我选择这个数据集的原因。

dput(head(GDP_Brazil)
structure(list(`Series Name` = c("GDP (current US$ in billion)", 
"GDP (current US$ in billion)", "GDP (current US$ in billion)", 
"GDP (current US$ in billion)", "GDP (current US$ in billion)", 
"GDP (current US$ in billion)"), Time = c(1960, 1961, 1962, 1963, 
1964, 1965), Brazil = c(15.1655699125199, 15.236854859469, 19.9262938390163, 
23.0214772922093, 21.2118922599904, 21.79003511719)), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

【讨论】:

    【解决方案2】:

    它是tibble。所以,我们需要[[$ 来进行子集化,否则,它仍然是带有单列的tibble。当我们进行一些需要vector的计算时,这会产生影响

    G <- GDP_Brazil[[3]]
    Time <- GDP_Brazil[[2]]
    

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 2016-09-18
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 2018-07-15
      • 2020-10-16
      相关资源
      最近更新 更多