kernel-density

Error: operator *: nonconformant arguments (op1 is rxc, op2 is rxc )

核能气质少年 提交于 2020-02-16 05:29:23
问题 I have implemented the following function to estimate Parzen Density of a matrix, parzen.m function [retval] = parzen (matrix, dataPoint, variance) [r c] = size(matrix); A = ones(r, c)*dataPoint; sub = matrix - A; up = sub.^2; dw = 2 * variance; firstPart = 1/(sqrt(2*pi*variance)); retval = firstPart * exp((-1)*(up/dw)); Error >> parzen(train, test, 0.25) error: parzen: operator *: nonconformant arguments (op1 is 1824x8, op2 is 1824x8 ) error: called from parzen at line 3 column 4 >> How can

What is _passthrough_scorer and How Can I Change Scorers in GridsearchCV (sklearn)?

为君一笑 提交于 2020-01-04 07:28:43
问题 http://scikit-learn.org/stable/modules/generated/sklearn.grid_search.GridSearchCV.html (for reference) x = [[2], [1], [3], [1] ... ] # about 1000 data grid = GridSearchCV(KernelDensity(), {'bandwidth': np.linspace(0.1, 1.0, 10)}, cv=10) grid.fit(x) When I use GridSearchCV without specifying scoring function like the , the value of grid.scorer_ is . Could you explain what kind of function _passthrough_scorer is? In addition to this, I want to change the scoring function to mean_squared_error

How to implement Kernel density estimation in multivariate/3D

那年仲夏 提交于 2020-01-04 01:56:06
问题 I have dataset like the following fromat and im trying to find out the Kernel density estimation with optimal bandwidth. data = np.array([[1, 4, 3], [2, .6, 1.2], [2, 1, 1.2], [2, 0.5, 1.4], [5, .5, 0], [0, 0, 0], [1, 4, 3], [5, .5, 0], [2, .5, 1.2]]) but I couldn't figure out how to approach it. also how to find the Σ matrix. UPDATE I tried KDE function from scikit-learn toolkits to find out univariate(1D) kde, # kde function def kde_sklearn(x, x_grid, bandwidth): kde = KernelDensity(kernel=

Illustrate mean and standard deviation in ggplot2 density plot

半腔热情 提交于 2020-01-01 19:21:07
问题 I'm trying to construct a plot where I plot normally distributed variables showing their mean on the x-axis and the standard deviation (SD) on the y-axis. Kinda like a density plot, but instead of having the density on the y-axis I want to have the SD (value). I'm working with the data below, set.seed(1) mu1 <- rnorm(10^5, mean = 1, sd = 1) mu3 <- rnorm(10^5, mean = 3, sd = 2) two normally distributed variables. Here their mean and sd, # install.packages("tidyverse", dependencies = TRUE)

2D Kernel Density Estimate in Matlab

喜欢而已 提交于 2020-01-01 19:18:28
问题 I am using this function to estimate kernel density in 2D. I am slightly confused by the parameters of this function however. Here is an example, viewed from directly above, where density is being calculated at each point (O) in the figure. i.e: over very small areas. I want to change the KDE function parameters so that density is computed over a larger area (for example, the area circled in red). Which parameters do I need to change? I presume it is one (or both) of these: "n: size of the n

how does 2d kernel density estimation in python (sklearn) work?

无人久伴 提交于 2020-01-01 03:42:09
问题 I am sorry for the probably stupid question but I am trying now for hours to estimate a density from a set of 2d data. Let's assume my data is given by the array: sample = np.random.uniform(0,1,size=(50,2)) . I just want to use scipys scikit learn package to estimate the density from the sample array (which is here of course a 2d uniform density) and I am trying the following: import numpy as np from sklearn.neighbors.kde import KernelDensity from matplotlib import pyplot as plt sp = 0.01

`plot.density` extends “xlim” beyond the range of my data. Why and how to fix it?

徘徊边缘 提交于 2019-12-31 04:34:07
问题 Using the code below, I am trying to get density plot for different distributions. dens <- apply(df[,c(7,9,12,14,16,18)], 2, density) plot(NA, xlim=range(sapply(dens, "[", "x")), ylim=range(sapply(dens, "[", "y"))) mapply(lines, dens, col=1:length(dens)) legend("topright", legend=names(dens), fill=1:length(dens),bty = "n",lwd=1, cex=0.7) The maximum upper limit for all variables is 5. But I got lines exceeded the 5. What do I need to change in my code to fix the plot? 回答1: By default, density

Using scipy.stats.gaussian_kde with 2 dimensional data

吃可爱长大的小学妹 提交于 2019-12-30 03:22:06
问题 I'm trying to use the scipy.stats.gaussian_kde class to smooth out some discrete data collected with latitude and longitude information, so it shows up as somewhat similar to a contour map in the end, where the high densities are the peak and low densities are the valley. I'm having a hard time putting a two-dimensional dataset into the gaussian_kde class. I've played around to figure out how it works with 1 dimensional data, so I thought 2 dimensional would be something along the lines of:

Weighted Gaussian kernel density estimation in `python`

99封情书 提交于 2019-12-30 01:01:26
问题 It is currently not possible to use scipy.stats.gaussian_kde to estimate the density of a random variable based on weighted samples. What methods are available to estimate densities of continuous random variables based on weighted samples? 回答1: Neither sklearn.neighbors.KernelDensity nor statsmodels.nonparametric seem to support weighted samples. I modified scipy.stats.gaussian_kde to allow for heterogeneous sampling weights and thought the results might be useful for others. An example is

geom_density doesn't fill correctly with scale_y_log10

限于喜欢 提交于 2019-12-24 14:08:41
问题 Code: require(ggplot2) set.seed(0) xvar <- rnorm(100) ggplot(data.frame(xvar), aes(xvar)) + geom_density(fill="lightblue") + scale_y_log10() The graph is something like this: How can I make the graph shade on the right side of (viz. below) the density estimate? 回答1: The problem is that stat_density by default fills between the density and the y=0 line of the transformed data. So transformations that alter the y=0 line will fall victim to problems of this sort. I personally think this is a bug