Python matplotlib.mlab.GaussianKDE() Examples
The following are 30
code examples of matplotlib.mlab.GaussianKDE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.mlab
, or try the search function
.
Example #1
Source File: test_mlab.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_kde_bandwidth_method(self): np.random.seed(8765678) n_basesample = 50 xn = np.random.randn(n_basesample) # Default gkde = mlab.GaussianKDE(xn) # Supply a callable gkde2 = mlab.GaussianKDE(xn, 'scott') # Supply a scalar gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor) xs = np.linspace(-7, 7, 51) kdepdf = gkde.evaluate(xs) kdepdf2 = gkde2.evaluate(xs) assert kdepdf.all() == kdepdf2.all() kdepdf3 = gkde3.evaluate(xs) assert kdepdf.all() == kdepdf3.all()
Example #2
Source File: test_mlab.py From neural-network-animation with MIT License | 6 votes |
def test_kde_bandwidth_method(self): np.random.seed(8765678) n_basesample = 50 xn = np.random.randn(n_basesample) # Default gkde = mlab.GaussianKDE(xn) # Supply a callable gkde2 = mlab.GaussianKDE(xn, 'scott') # Supply a scalar gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor) xs = np.linspace(-7, 7, 51) kdepdf = gkde.evaluate(xs) kdepdf2 = gkde2.evaluate(xs) assert_almost_equal(kdepdf.all(), kdepdf2.all()) kdepdf3 = gkde3.evaluate(xs) assert_almost_equal(kdepdf.all(), kdepdf3.all())
Example #3
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_kde_bandwidth_method(self): np.random.seed(8765678) n_basesample = 50 xn = np.random.randn(n_basesample) # Default gkde = mlab.GaussianKDE(xn) # Supply a callable gkde2 = mlab.GaussianKDE(xn, 'scott') # Supply a scalar gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor) xs = np.linspace(-7, 7, 51) kdepdf = gkde.evaluate(xs) kdepdf2 = gkde2.evaluate(xs) assert kdepdf.all() == kdepdf2.all() kdepdf3 = gkde3.evaluate(xs) assert kdepdf.all() == kdepdf3.all()
Example #4
Source File: test_mlab.py From coffeegrindsize with MIT License | 6 votes |
def test_kde_bandwidth_method(self): np.random.seed(8765678) n_basesample = 50 xn = np.random.randn(n_basesample) # Default gkde = mlab.GaussianKDE(xn) # Supply a callable gkde2 = mlab.GaussianKDE(xn, 'scott') # Supply a scalar gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor) xs = np.linspace(-7, 7, 51) kdepdf = gkde.evaluate(xs) kdepdf2 = gkde2.evaluate(xs) assert kdepdf.all() == kdepdf2.all() kdepdf3 = gkde3.evaluate(xs) assert kdepdf.all() == kdepdf3.all()
Example #5
Source File: test_mlab.py From ImageFusion with MIT License | 6 votes |
def test_kde_bandwidth_method(self): np.random.seed(8765678) n_basesample = 50 xn = np.random.randn(n_basesample) # Default gkde = mlab.GaussianKDE(xn) # Supply a callable gkde2 = mlab.GaussianKDE(xn, 'scott') # Supply a scalar gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor) xs = np.linspace(-7, 7, 51) kdepdf = gkde.evaluate(xs) kdepdf2 = gkde2.evaluate(xs) assert_almost_equal(kdepdf.all(), kdepdf2.all()) kdepdf3 = gkde3.evaluate(xs) assert_almost_equal(kdepdf.all(), kdepdf3.all())
Example #6
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_wrong_bw_method(self): """Test the error message that should be called when bw is invalid.""" np.random.seed(8765678) n_basesample = 50 data = np.random.randn(n_basesample) with pytest.raises(ValueError): mlab.GaussianKDE(data, bw_method="invalid")
Example #7
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_scalar_empty_dataset(self): """Use an empty array as the dataset and test the scalar's cov factor """ with pytest.raises(ValueError): mlab.GaussianKDE([], bw_method=5)
Example #8
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_scalar_covariance_dataset(self): """Use a dataset and test a scalar's cov factor """ np.random.seed(8765678) n_basesample = 50 multidim_data = [np.random.randn(n_basesample) for i in range(5)] kde = mlab.GaussianKDE(multidim_data, bw_method=0.5) assert kde.covariance_factor() == 0.5
Example #9
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_callable_singledim_dataset(self): """Use a single-dimensional array as the dataset and test the callable's cov factor""" np.random.seed(8765678) n_basesample = 50 multidim_data = np.random.randn(n_basesample) kde = mlab.GaussianKDE(multidim_data, bw_method='silverman') y_expected = 0.48438841363348911 assert_almost_equal(kde.covariance_factor(), y_expected, 7)
Example #10
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_wrong_bw_method(self): """Test the error message that should be called when bw is invalid.""" np.random.seed(8765678) n_basesample = 50 data = np.random.randn(n_basesample) with pytest.raises(ValueError): mlab.GaussianKDE(data, bw_method="invalid")
Example #11
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_evaluate_equal_dim_and_num_lt(self): """Test when line 3810 fails""" x1 = np.arange(3, 10, 2) x2 = np.arange(3, 8, 2) kde = mlab.GaussianKDE(x1) y_expected = [0.08797252, 0.11774109, 0.11774109] y = kde.evaluate(x2) np.testing.assert_array_almost_equal(y, y_expected, 7)
Example #12
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_scott_singledim_dataset(self): """Use a single-dimensional array as the dataset and test scott's output""" x1 = np.array([-7, -5, 1, 4, 5]) mygauss = mlab.GaussianKDE(x1, "scott") y_expected = 0.72477966367769553 assert_almost_equal(mygauss.covariance_factor(), y_expected, 7)
Example #13
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_scalar_empty_dataset(self): """Use an empty array as the dataset and test the scalar's cov factor """ with pytest.raises(ValueError): mlab.GaussianKDE([], bw_method=5)
Example #14
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_scalar_covariance_dataset(self): """Use a dataset and test a scalar's cov factor """ np.random.seed(8765678) n_basesample = 50 multidim_data = [np.random.randn(n_basesample) for i in range(5)] kde = mlab.GaussianKDE(multidim_data, bw_method=0.5) assert kde.covariance_factor() == 0.5
Example #15
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_callable_singledim_dataset(self): """Use a single-dimensional array as the dataset and test the callable's cov factor""" np.random.seed(8765678) n_basesample = 50 multidim_data = np.random.randn(n_basesample) kde = mlab.GaussianKDE(multidim_data, bw_method='silverman') y_expected = 0.48438841363348911 assert_almost_equal(kde.covariance_factor(), y_expected, 7)
Example #16
Source File: test_mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_evaluate_inv_dim(self): """ Invert the dimensions. i.e., Give the dataset a dimension of 1 [3,2,4], and the points will have a dimension of 3 [[3],[2],[4]]. ValueError should be raised""" np.random.seed(8765678) n_basesample = 50 multidim_data = np.random.randn(n_basesample) kde = mlab.GaussianKDE(multidim_data) x2 = [[1], [2], [3]] with pytest.raises(ValueError): kde.evaluate(x2)
Example #17
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_evaluate_inv_dim(self): """ Invert the dimensions. i.e., Give the dataset a dimension of 1 [3,2,4], and the points will have a dimension of 3 [[3],[2],[4]]. ValueError should be raised""" np.random.seed(8765678) n_basesample = 50 multidim_data = np.random.randn(n_basesample) kde = mlab.GaussianKDE(multidim_data) x2 = [[1], [2], [3]] with pytest.raises(ValueError): kde.evaluate(x2)
Example #18
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_scott_singledim_dataset(self): """Use a single-dimensional array as the dataset and test scott's output""" x1 = np.array([-7, -5, 1, 4, 5]) mygauss = mlab.GaussianKDE(x1, "scott") y_expected = 0.72477966367769553 assert_almost_equal(mygauss.covariance_factor(), y_expected, 7)
Example #19
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_scott_multidim_dataset(self): """Use a multi-dimensional array as the dataset and test scott's output """ x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) with pytest.raises(np.linalg.LinAlgError): mlab.GaussianKDE(x1, "scott")
Example #20
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_silverman_singledim_dataset(self): """Use a single dimension list as the dataset and test silverman's output.""" x1 = np.array([-7, -5, 1, 4, 5]) mygauss = mlab.GaussianKDE(x1, "silverman") y_expected = 0.76770389927475502 assert_almost_equal(mygauss.covariance_factor(), y_expected, 7)
Example #21
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_single_dataset_element(self): """Pass a single dataset element into the GaussianKDE class.""" with pytest.raises(ValueError): mlab.GaussianKDE([42])
Example #22
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_no_data(self): """Pass no data into the GaussianKDE class.""" with pytest.raises(ValueError): mlab.GaussianKDE([])
Example #23
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_gaussian_kde_covariance_caching(self): x1 = np.array([-7, -5, 1, 4, 5], dtype=float) xs = np.linspace(-10, 10, num=5) # These expected values are from scipy 0.10, before some changes to # gaussian_kde. They were not compared with any external reference. y_expected = [0.02463386, 0.04689208, 0.05395444, 0.05337754, 0.01664475] # set it to the default bandwidth. kde2 = mlab.GaussianKDE(x1, 'scott') y2 = kde2(xs) np.testing.assert_array_almost_equal(y_expected, y2, decimal=7)
Example #24
Source File: test_mlab.py From coffeegrindsize with MIT License | 5 votes |
def test_kde_integer_input(self): """Regression test for #1181.""" x1 = np.arange(5) kde = mlab.GaussianKDE(x1) y_expected = [0.13480721, 0.18222869, 0.19514935, 0.18222869, 0.13480721] np.testing.assert_array_almost_equal(kde(x1), y_expected, decimal=6)
Example #25
Source File: test_mlab.py From ImageFusion with MIT License | 5 votes |
def test_evaluate_equal_dim_and_num_lt(self): """Test when line 3810 fails""" x1 = np.arange(3, 10, 2) x2 = np.arange(3, 8, 2) kde = mlab.GaussianKDE(x1) y_expected = [0.08797252, 0.11774109, 0.11774109] y = kde.evaluate(x2) np.testing.assert_array_almost_equal(y, y_expected, 7) #***************************************************************** #*****************************************************************
Example #26
Source File: test_mlab.py From ImageFusion with MIT License | 5 votes |
def test_evaluate_dim_and_num(self): """ Tests if evaluated against a one by one array""" x1 = np.arange(3, 10, 2) x2 = np.array([3]) kde = mlab.GaussianKDE(x1) y_expected = [0.08797252] y = kde.evaluate(x2) np.testing.assert_array_almost_equal(y, y_expected, 7)
Example #27
Source File: test_mlab.py From ImageFusion with MIT License | 5 votes |
def test_evaluate_inv_dim(self): """ Invert the dimensions. i.e., Give the dataset a dimension of 1 [3,2,4], and the points will have a dimension of 3 [[3],[2],[4]]. ValueError should be raised""" np.random.seed(8765678) n_basesample = 50 multidim_data = np.random.randn(n_basesample) kde = mlab.GaussianKDE(multidim_data) x2 = [[1], [2], [3]] assert_raises(ValueError, kde.evaluate, x2)
Example #28
Source File: test_mlab.py From ImageFusion with MIT License | 5 votes |
def test_evaluate_diff_dim(self): """Test the evaluate method when the dim's of dataset and points are different dimensions""" x1 = np.arange(3, 10, 2) kde = mlab.GaussianKDE(x1) x2 = np.arange(3, 12, 2) y_expected = [ 0.08797252, 0.11774109, 0.11774109, 0.08797252, 0.0370153 ] y = kde.evaluate(x2) np.testing.assert_array_almost_equal(y, y_expected, 7)
Example #29
Source File: test_mlab.py From ImageFusion with MIT License | 5 votes |
def test_wrong_bw_method(self): """Test the error message that should be called when bw is invalid.""" np.random.seed(8765678) n_basesample = 50 data = np.random.randn(n_basesample) assert_raises(ValueError, mlab.GaussianKDE, data, bw_method="invalid")
Example #30
Source File: test_mlab.py From ImageFusion with MIT License | 5 votes |
def test_callable_singledim_dataset(self): """Use a single-dimensional array as the dataset and test the callable's cov factor""" np.random.seed(8765678) n_basesample = 50 multidim_data = np.random.randn(n_basesample) kde = mlab.GaussianKDE(multidim_data, bw_method='silverman') y_expected = 0.48438841363348911 assert_almost_equal(kde.covariance_factor(), y_expected, 7)