Python scipy.stats.probplot() Examples
The following are 15
code examples of scipy.stats.probplot().
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
scipy.stats
, or try the search function
.
Example #1
Source File: ros.py From vnpy_crypto with MIT License | 6 votes |
def _norm_plot_pos(observations): """ Computes standard normal (Gaussian) plotting positions using scipy. Parameters ---------- observations : array-like Sequence of observed quantities. Returns ------- plotting_position : array of floats """ ppos, sorted_res = stats.probplot(observations, fit=False) return stats.norm.cdf(ppos)
Example #2
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_dist_keyword(self): np.random.seed(12345) x = stats.norm.rvs(size=20) osm1, osr1 = stats.probplot(x, fit=False, dist='t', sparams=(3,)) osm2, osr2 = stats.probplot(x, fit=False, dist=stats.t, sparams=(3,)) assert_allclose(osm1, osm2) assert_allclose(osr1, osr2) assert_raises(ValueError, stats.probplot, x, dist='wrong-dist-name') assert_raises(AttributeError, stats.probplot, x, dist=[]) class custom_dist(object): """Some class that looks just enough like a distribution.""" def ppf(self, q): return stats.norm.ppf(q, loc=2) osm1, osr1 = stats.probplot(x, sparams=(2,), fit=False) osm2, osr2 = stats.probplot(x, dist=custom_dist(), fit=False) assert_allclose(osm1, osm2) assert_allclose(osr1, osr2)
Example #3
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_plot_kwarg(self): np.random.seed(7654321) fig = plt.figure() fig.add_subplot(111) x = stats.t.rvs(3, size=100) res1, fitres1 = stats.probplot(x, plot=plt) plt.close() res2, fitres2 = stats.probplot(x, plot=None) res3 = stats.probplot(x, fit=False, plot=plt) plt.close() res4 = stats.probplot(x, fit=False, plot=None) # Check that results are consistent between combinations of `fit` and # `plot` keywords. assert_(len(res1) == len(res2) == len(res3) == len(res4) == 2) assert_allclose(res1, res2) assert_allclose(res1, res3) assert_allclose(res1, res4) assert_allclose(fitres1, fitres2) # Check that a Matplotlib Axes object is accepted fig = plt.figure() ax = fig.add_subplot(111) stats.probplot(x, fit=False, plot=ax) plt.close()
Example #4
Source File: ros.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _norm_plot_pos(observations): """ Computes standard normal (Gaussian) plotting positions using scipy. Parameters ---------- observations : array-like Sequence of observed quantities. Returns ------- plotting_position : array of floats """ ppos, sorted_res = stats.probplot(observations, fit=False) return stats.norm.cdf(ppos)
Example #5
Source File: test_gaussianize.py From gaussianize with MIT License | 6 votes |
def test_normality_increase_lambert(self): # Generate random data and check that it is more normal after inference for i, y in enumerate([np.random.standard_cauchy(size=ns), experimental_data]): print('Distribution %d' % i) print('Before') print(('anderson: %0.3f\tshapiro: %0.3f' % (anderson(y)[0], shapiro(y)[0])).expandtabs(30)) stats.probplot(y, dist="norm", plot=plt) plt.savefig(os.path.join(self.test_dir, '%d_before.png' % i)) plt.clf() tau = g.igmm(y) x = g.w_t(y, tau) print('After') print(('anderson: %0.3f\tshapiro: %0.3f' % (anderson(x)[0], shapiro(x)[0])).expandtabs(30)) stats.probplot(x, dist="norm", plot=plt) plt.savefig(os.path.join(self.test_dir, '%d_after.png' % i)) plt.clf()
Example #6
Source File: test_morestats.py From Computable with MIT License | 5 votes |
def test_probplot_bad_arg(): """Raise ValueError when given an invalid distribution.""" data = [1] assert_raises(ValueError, stats.probplot, data, dist="plate_of_shrimp")
Example #7
Source File: CrossValidation.py From pyKriging with MIT License | 5 votes |
def QQ_plot(self): """ returns the QQ-plot with normal distribution """ plt.figure(figsize=(12, 8), facecolor='w', edgecolor='k', linewidth= 2.0, frameon=True) stats.probplot(self.scvr, dist="norm", plot=plt) plt.xlabel('SCVR') plt.ylabel('Standard quantile') plt.show()
Example #8
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_basic(self): np.random.seed(12345) x = stats.norm.rvs(size=20) osm, osr = stats.probplot(x, fit=False) osm_expected = [-1.8241636, -1.38768012, -1.11829229, -0.91222575, -0.73908135, -0.5857176, -0.44506467, -0.31273668, -0.18568928, -0.06158146, 0.06158146, 0.18568928, 0.31273668, 0.44506467, 0.5857176, 0.73908135, 0.91222575, 1.11829229, 1.38768012, 1.8241636] assert_allclose(osr, np.sort(x)) assert_allclose(osm, osm_expected) res, res_fit = stats.probplot(x, fit=True) res_fit_expected = [1.05361841, 0.31297795, 0.98741609] assert_allclose(res_fit, res_fit_expected)
Example #9
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_sparams_keyword(self): np.random.seed(123456) x = stats.norm.rvs(size=100) # Check that None, () and 0 (loc=0, for normal distribution) all work # and give the same results osm1, osr1 = stats.probplot(x, sparams=None, fit=False) osm2, osr2 = stats.probplot(x, sparams=0, fit=False) osm3, osr3 = stats.probplot(x, sparams=(), fit=False) assert_allclose(osm1, osm2) assert_allclose(osm1, osm3) assert_allclose(osr1, osr2) assert_allclose(osr1, osr3) # Check giving (loc, scale) params for normal distribution osm, osr = stats.probplot(x, sparams=(), fit=False)
Example #10
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_probplot_bad_args(self): # Raise ValueError when given an invalid distribution. assert_raises(ValueError, stats.probplot, [1], dist="plate_of_shrimp")
Example #11
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_array_of_size_one(self): with np.errstate(invalid='ignore'): assert_equal(stats.probplot([1], fit=True), ((np.array([0.]), np.array([1])), (np.nan, np.nan, 0.0)))
Example #12
Source File: test_morestats.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_empty(self): # For consistency with probplot return for one empty array, # ppcc contains all zeros and svals is the same as for normal array # input. svals, ppcc = stats.ppcc_plot([], 0, 1) assert_allclose(svals, np.linspace(0, 1, num=80)) assert_allclose(ppcc, np.zeros(80, dtype=float))
Example #13
Source File: gaussianize.py From gaussianize with MIT License | 5 votes |
def qqplot(self, x: np.ndarray, prefix: Text = 'qq', output_dir: Text = "/tmp/"): """Show qq plots compared to normal before and after the transform.""" x = _update_x(x) y = self.transform(x) n_dim = y.shape[1] for i in range(n_dim): stats.probplot(x[:, i], dist="norm", plot=plt) plt.savefig(os.path.join(output_dir, prefix + '_%d_before.png' % i)) plt.clf() stats.probplot(y[:, i], dist="norm", plot=plt) plt.savefig(os.path.join(output_dir, prefix + '_%d_after.png' % i)) plt.clf()
Example #14
Source File: Plots.py From pyaf with BSD 3-Clause "New" or "Revised" License | 5 votes |
def decomp_plot(df, time, signal, estimator, residue, name = None, format='png', max_length = 1000, horizon = 1) : assert(df.shape[0] > 0) assert(df.shape[1] > 0) assert(time in df.columns) assert(signal in df.columns) assert(estimator in df.columns) assert(residue in df.columns) import matplotlib # print("MATPLOTLIB_BACKEND", matplotlib.get_backend()) # matplotlib.use('Agg') import matplotlib.pyplot as plt df1 = df.tail(max(max_length , 4 * horizon)); if(name is not None): plt.switch_backend('Agg') fig, axs = plt.subplots(ncols=2, figsize=(32, 16)) lColor = COMPONENT_COLOR; if(name is not None and name.endswith("Forecast")): lColor = FORECAST_COLOR; df1.plot.line(time, [signal, estimator, residue], color=[SIGNAL_COLOR, lColor, RESIDUE_COLOR], ax=axs[0] , grid = True, legend=False) add_patched_legend(axs[0] , [signal, estimator, residue]) residues = df1[residue].values import scipy.stats as scistats resid = residues[~np.isnan(residues)] scistats.probplot(resid, dist="norm", plot=axs[1]) if(name is not None): plt.switch_backend('Agg') fig.savefig(name + '_decomp_output.' + format) plt.close(fig)
Example #15
Source File: Plots.py From pyaf with BSD 3-Clause "New" or "Revised" License | 5 votes |
def decomp_plot_as_png_base64(df, time, signal, estimator, residue, name = None, max_length = 1000, horizon = 1) : assert(df.shape[0] > 0) assert(df.shape[1] > 0) assert(time in df.columns) assert(signal in df.columns) assert(estimator in df.columns) assert(residue in df.columns) import matplotlib # matplotlib.use('Agg') import matplotlib.pyplot as plt plt.switch_backend('Agg') df1 = df.tail(max(max_length, 4 * horizon)); fig, axs = plt.subplots(ncols=2, figsize=(16, 8)) lColor = COMPONENT_COLOR; if(name is not None and name.endswith("Forecast")): lColor = FORECAST_COLOR; df1.plot.line(time, [signal, estimator, residue], color=[SIGNAL_COLOR, lColor, RESIDUE_COLOR], ax=axs[0] , grid = True, legend = False) add_patched_legend(axs[0] , [signal, estimator, residue]) residues = df1[residue].values import scipy.stats as scistats resid = residues[~np.isnan(residues)] scistats.probplot(resid, dist="norm", plot=axs[1]) figfile = BytesIO() fig.savefig(figfile, format='png') figfile.seek(0) # rewind to beginning of file figdata_png = base64.b64encode(figfile.getvalue()) plt.close(fig) return figdata_png.decode('utf8')