Raj*_*ina 3 visualization r graph
假设我有以下数据框,其中包含与他们相关的分数的人:
Score | hasDefaulted
10 | 0
13 | 0
15 | 1
17 | 0
...
Run Code Online (Sandbox Code Playgroud)
我想在 R 中制作一个提升图,首先按分数对人口进行排序,然后在 X 轴上有人口的百分比,在 Y 轴上有默认的百分比。我找不到一个好的包来让我控制这样做。我已经探索了Package Lift和Package Gains,但我无法弄清楚如何对它们进行足够的控制来执行我上面描述的操作。例如,当我尝试使用 Package Lift 时,作为
plotLift(sort(dataFrame$Score, decreasing=FALSE), dataFrame$hasDefaulted)
Run Code Online (Sandbox Code Playgroud)
但鉴于我的愿望,该图最终应该看起来像一个累积密度函数。
有人可以告诉我如何正确使用这些包,或者将我引导到满足要求的包吗?提前致谢。
小智 8
我总是尝试构建自己的代码,而不是尝试不那么灵活的代码。
以下是我认为您可以解决此问题的方法:
# Creating the data frame
df <- data.frame("Score"=runif(100,1,100),
"hasDefaulted"=round(runif(100,0,1),0))
# Ordering the dataset
df <- df[order(df$Score),]
# Creating the cumulative density
df$cumden <- cumsum(df$hasDefaulted)/sum(df$hasDefaulted)
# Creating the % of population
df$perpop <- (seq(nrow(df))/nrow(df))*100
# Ploting
plot(df$perpop,df$cumden,type="l",xlab="% of Population",ylab="% of Default's")
Run Code Online (Sandbox Code Playgroud)
那是你要的吗?
小智 5
我认为您正在寻找增益图,而不是提升图。我注意到它们之间存在一些混淆。您可以参考提升图了解更多信息。
require(ROCR)
data(ROCR.simple)
pred <- prediction(ROCR.simple$predictions, ROCR.simple$labels)
gain <- performance(pred, "tpr", "rpp")
plot(gain, main = "Gain Chart")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15832 次 |
| 最近记录: |