AutoPlot不支持PRCOMP类型的对象

发布于 2025-02-12 08:50:20 字数 896 浏览 1 评论 0原文

我有多个列的数据框。我想进行PCA并与决策树进行分类,以检查iL.count.ratio上的信息是否到une.count.ratio实际上可以帮助区分这两个专业。

Profession    il.count.ratio   elle.count.ratio    un.count.ratio   une.count.ratio
secretary      1.7241              1.3514             1.473            0.7380
secretary      0.0000              2.8736             2.8536           0.8370
driver         1.7065              0.0000             0.0000           0.7380
driver         0.5284              1.4733             0.7380           0.5280

输出为:autoplot()中的错误: 呢AutoPlot不支持PRCOMP的对象。

有人知道可能是什么问题?

data %>%
  select(il.count.ratio:une.count.ratio) %>%
  prcomp() %>%
  autoplot(data = data,
           colour = 'Profession',
           loadings = TRUE,
           loadings.colour = "blue",
           loadings.label = TRUE,
           loadings.label.colour = "blue")

I have a data frame of multiple columns. I want to carry out PCA and classification with decision trees to check if information on il.count.ratio to une.count.ratio can actually help to differentiate the two professions.

Profession    il.count.ratio   elle.count.ratio    un.count.ratio   une.count.ratio
secretary      1.7241              1.3514             1.473            0.7380
secretary      0.0000              2.8736             2.8536           0.8370
driver         1.7065              0.0000             0.0000           0.7380
driver         0.5284              1.4733             0.7380           0.5280

output is : Error in autoplot():
! Objects of type prcomp not supported by autoplot.

someone know what may be the problem ?

data %>%
  select(il.count.ratio:une.count.ratio) %>%
  prcomp() %>%
  autoplot(data = data,
           colour = 'Profession',
           loadings = TRUE,
           loadings.colour = "blue",
           loadings.label = TRUE,
           loadings.label.colour = "blue")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿 2025-02-19 08:50:20

您可以使用Broom的增强(用于PC)和整理(用于加载)在ggplot ing之前获取数据框:

library(tidyverse)
library(broom)

data <- tribble(
  ~Profession, ~il.count.ratio, ~elle.count.ratio, ~un.count.ratio, ~une.count.ratio,
  "secretary", 1.7241, 1.3514, 1.473, 0.7380,
  "secretary", 0.0000, 2.8736, 2.8536, 0.8370,
  "driver", 1.7065, 0.0000, 0.0000, 0.7380,
  "driver", 0.5284, 1.4733, 0.7380, 0.5280
)

data %>%
  select(il.count.ratio:une.count.ratio) %>%
  prcomp() %>% 
  augment(data) %>% 
  ggplot(aes(.fittedPC1, .fittedPC2, colour = Profession)) +
  geom_point()

“”

  
# Use instead of augment for the loadings
# tidy(matrix = "loadings")

在2022-06-30创建的 reprex软件包(v2.0.1)

You could use broom's augment (for the PCs) and tidy (for the loadings) to get a dataframe before ggploting:

library(tidyverse)
library(broom)

data <- tribble(
  ~Profession, ~il.count.ratio, ~elle.count.ratio, ~un.count.ratio, ~une.count.ratio,
  "secretary", 1.7241, 1.3514, 1.473, 0.7380,
  "secretary", 0.0000, 2.8736, 2.8536, 0.8370,
  "driver", 1.7065, 0.0000, 0.0000, 0.7380,
  "driver", 0.5284, 1.4733, 0.7380, 0.5280
)

data %>%
  select(il.count.ratio:une.count.ratio) %>%
  prcomp() %>% 
  augment(data) %>% 
  ggplot(aes(.fittedPC1, .fittedPC2, colour = Profession)) +
  geom_point()

  
# Use instead of augment for the loadings
# tidy(matrix = "loadings")

Created on 2022-06-30 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文