代码:
require(ggplot2)
set.seed(0)
xvar <- rnorm(100)
ggplot(data.frame(xvar), aes(xvar)) + geom_density(fill="lightblue") + scale_y_log10()
Run Code Online (Sandbox Code Playgroud)
该图是这样的:

如何使图形阴影位于密度估计的右侧(即下方)?
如何从非标准分布中获得归一化常数。前任:
x <- c(rnorm(500,10,1),rnorm(500,20,2),rnorm(500,35,1))
Run Code Online (Sandbox Code Playgroud)
在 R 中使用密度后
dens<-density(x,n=length(x),adjust=0.4)
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个图,其中我绘制了正态分布的变量,显示了它们在x轴上的平均值和y轴上的标准偏差(SD).有点像密度图,但不是在y轴上有密度,我想要SD(值).
我正在处理下面的数据,
set.seed(1)
mu1 <- rnorm(10^5, mean = 1, sd = 1)
mu3 <- rnorm(10^5, mean = 3, sd = 2)
Run Code Online (Sandbox Code Playgroud)
两个正态分布的变量.在这里他们的意思和sd,
# install.packages("tidyverse", dependencies = TRUE)
require(tidyverse)
tibble(mu1, mu3) %>% summarise_all(funs(mean, sd))
#> # A tibble: 1 x 4
#> mu1_mean mu3_mean mu1_sd mu3_sd
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0.9993454 3.000825 0.9982848 1.998234
Run Code Online (Sandbox Code Playgroud)
我玩过ggplot2和其他整齐的软件包,以便更接近我想要的东西.我也试过从一个盒子图中复制这个函数做类似的事情,但是还成功了.
这是我的开始,
tibble(mu1, mu3) %>% gather() %>% ggplot() +
geom_density(aes(x = value, colour = key)) +
labs(x = …Run Code Online (Sandbox Code Playgroud) 我很抱歉这个可能很愚蠢的问题,但我现在正试着用几个小时来估算一组2d数据的密度.我们假设我的数据由数组给出:sample = np.random.uniform(0,1,size=(50,2)).我只是想使用scipys scikit learn package来估算样本数组的密度(这当然是2d均匀密度),我正在尝试以下方法:
import numpy as np
from sklearn.neighbors.kde import KernelDensity
from matplotlib import pyplot as plt
sp = 0.01
samples = np.random.uniform(0,1,size=(50,2)) # random samples
x = y = np.linspace(0,1,100)
X,Y = np.meshgrid(x,y) # creating grid of data , to evaluate estimated density on
kde = KernelDensity(kernel='gaussian', bandwidth=0.2).fit(samples) # creating density from samples
kde.score_samples(X,Y) # I want to evaluate the estimated density on the X,Y grid
Run Code Online (Sandbox Code Playgroud)
但最后一步总是产生错误: score_samples() takes 2 positional arguments but 3 …
我有一个Dt像这样的Pandas数据帧():
Pc Cvt C1 C2 C3 C4 C5 C6 C7 C8 C9 C10
0 1 2 0.08 0.17 0.16 0.31 0.62 0.66 0.63 0.52 0.38
1 2 2 0.09 0.15 0.13 0.49 0.71 1.28 0.42 1.04 0.43
2 3 2 0.13 0.24 0.22 0.17 0.66 0.17 0.28 0.11 0.30
3 4 1 0.21 0.10 0.23 0.08 0.53 0.14 0.59 0.06 0.53
4 5 1 0.16 0.21 0.18 0.13 0.44 0.08 0.29 0.12 0.52
5 6 1 0.14 0.14 …Run Code Online (Sandbox Code Playgroud) 如何缩放seaborn联合图的边际kdeplot?
假设我们有 1000 个类型“a”的数据、100 个类型“b”的数据和“100”个类型“c”的数据。
在这种情况下,边际 kdeplot 的尺度看起来并不相同,因为分类数据的大小完全不同。
我如何使这些相同?
我制作了一个玩具脚本,如下所示:
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
ax, ay = 1 * np.random.randn(1000) + 2, 1 * np.random.randn(1000) + 2
bx, by = 1 * np.random.randn(100) + 3, 1 * np.random.randn(100) + 3
cx, cy = 1 * np.random.randn(100) + 4, 1 * np.random.randn(100) + 4
a = [{'x': x, 'y': y, 'kind': 'a'} for x, y in zip(ax, ay)]
b …Run Code Online (Sandbox Code Playgroud) 我想知道是否有一个参数来抑制 R 中附带的默认灰色水平abline(见下图)density()?
plot(density(rnorm(1e4)))
Run Code Online (Sandbox Code Playgroud)
我想生成一个具有两个 y 轴的图形:(Count来自直方图)和Density(来自 KDE)。
我想sns.displot在 Seaborn 中使用>= v 0.11。
import seaborn as sns
df = sns.load_dataset('tips')
# graph 1: This should be the Y-Axis on the left side of the figure
sns.displot(df['total_bill'], kind='hist', bins=10)
# graph 2: This should be the Y-axis on the right side of the figure
sns.displot(df['total_bill'], kind='kde')
Run Code Online (Sandbox Code Playgroud)
我编写的代码生成两个单独的图表;我可以只对两个单独的图形使用分面网格,但我想要更简洁,并将两个单独的网格上的两个 y 轴放置到共享相同 x 轴的单个图形中。
我遇到过一些可以进行核密度估计的方法,这些方法将为数据样本提供 PDF:
使用上述任何一种方法我都可以生成 PDF,但是我想知道如何获取我正在生成的 PDF 的 CDF。在数学中,我知道您可以对 PDF 进行积分以获得 CDF,但问题是这些方法仅提供 x 和 y 点,而不是要积分的函数。
我想知道如何将给出的数据转换为 CDF 图,或者找到数据的 PDF 函数,然后积分以获得 CDF。或者使用另一种方法,其中输出是 CDF 而不是 PDF。
kernel-density ×10
python ×5
r ×4
ggplot2 ×2
histogram ×2
scikit-learn ×2
seaborn ×2
statistics ×2
density-plot ×1
jointplot ×1
matplotlib ×1
normalizing ×1
pandas ×1
plot ×1
scaling ×1