本文整理汇总了Python中scipy.stats.norm.fit方法的典型用法代码示例。如果您正苦于以下问题:Python norm.fit方法的具体用法?Python norm.fit怎么用?Python norm.fit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats.norm
的用法示例。
在下文中一共展示了norm.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_pdf
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def draw_pdf(var1, var2=None, label1='var1', label2='var2', xlab='variable', \
ylab='Normalized frequency', linewidth=2, framealpha=0.3, \
markersize=5, fontsize=18, xmax=18, binfac=1):
bins = range(xmax+1)
(mu, sigma) = norm.fit(var1)
y1 = mlab.normpdf(bins, mu, sigma)
figure()
grid('on')
plot(bins, y1, 'b-o', linewidth=linewidth, markersize=markersize, label=label1)
if var2 != None:
(mu, sigma) = norm.fit(var2)
y2 = mlab.normpdf(bins, mu, sigma)
plot(bins, y2, 'r-o', linewidth=linewidth, markersize=markersize, label=label2)
xlabel(xlab, fontsize=fontsize)
ylabel(ylab, fontsize=fontsize)
xlim(0,xmax)
tick_params(axis='both', which='major', labelsize=fontsize)
if var2 != None:
legend(fancybox=True, framealpha=framealpha, loc='upper right', fontsize=fontsize)
return
示例2: doc_thres
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def doc_thres(model, data, model_type, scale = 2.):
train_y = data['train_set_Y']
if "mlp" in model_type:
train_pred = model.predict(data['train_set_X'])
else:
train_pred = model.predict(data['train_set_idx_X'])
#print train_y.shape, train_pred.shape
def fit(prob_pos_X):
prob_pos = [p for p in prob_pos_X]+[2-p for p in prob_pos_X]
pos_mu, pos_std = dist_model.fit(prob_pos)
return pos_std
stds = []
for c in range(train_pred.shape[-1]):
idx = [train_y == c]
c_pred = train_pred[idx]
c_prob = c_pred[:,c]
std = fit(c_prob)
stds.append(std)
thres = [max(0.5, 1. - scale * std) for std in stds]
return thres
示例3: fit_predict
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def fit_predict(self, X, y=None):
"""Fit the model according to the given training data and predict if a
particular training sample is an outlier or not.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training Data.
y : ignored
Returns
-------
y_pred : array-like of shape (n_samples,)
Return -1 for outliers and +1 for inliers.
"""
if hasattr(self, 'novelty'):
check_novelty(self.novelty, 'fit_predict')
return self.fit(X).predict()
示例4: plot_t_value_hist
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def plot_t_value_hist(
img_path='~/ni_data/ofM.dr/l1/as_composite/sub-5703/ses-ofM/sub-5703_ses-ofM_task-EPI_CBV_chr_longSOA_tstat.nii.gz',
roi_path='~/ni_data/templates/roi/DSURQEc_ctx.nii.gz',
mask_path='/usr/share/mouse-brain-atlases/dsurqec_200micron_mask.nii',
save_as='~/qc_tvalues.pdf',
):
"""Make t-value histogram plot"""
f, axarr = plt.subplots(1, sharex=True)
roi = nib.load(path.expanduser(roi_path))
roi_data = roi.get_data()
mask = nib.load(path.expanduser(mask_path))
mask_data = mask.get_data()
idx = np.nonzero(np.multiply(roi_data,mask_data))
img = nib.load(path.expanduser(img_path))
data = img.get_data()[idx]
(mu, sigma) = norm.fit(data)
n, bins, patches = axarr.hist(data,'auto',normed=1, facecolor='green', alpha=0.75)
y = mlab.normpdf(bins, mu, sigma)
axarr.plot(bins, y, 'r--', linewidth=2)
axarr.set_title('Histogram of t-values $\mathrm{(\mu=%.3f,\ \sigma=%.3f}$)' %(mu, sigma))
axarr.set_xlabel('t-values')
plt.savefig(path.expanduser(save_as))
示例5: test_megkde_2d_basic
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def test_megkde_2d_basic():
# Draw from normal, fit KDE, see if sampling from kde's pdf recovers norm
np.random.seed(1)
data = np.random.multivariate_normal([0, 1], [[1.0, 0.], [0., 0.75 ** 2]], size=10000)
xs, ys = np.linspace(-4, 4, 50), np.linspace(-4, 4, 50)
xx, yy = np.meshgrid(xs, ys, indexing='ij')
samps = np.vstack((xx.flatten(), yy.flatten())).T
zs = MegKDE(data).evaluate(samps).reshape(xx.shape)
zs_x = zs.sum(axis=1)
zs_y = zs.sum(axis=0)
cs_x = zs_x.cumsum()
cs_x /= cs_x[-1]
cs_x[0] = 0
cs_y = zs_y.cumsum()
cs_y /= cs_y[-1]
cs_y[0] = 0
samps_x = interp1d(cs_x, xs)(np.random.uniform(size=10000))
samps_y = interp1d(cs_y, ys)(np.random.uniform(size=10000))
mu_x, std_x = norm.fit(samps_x)
mu_y, std_y = norm.fit(samps_y)
assert np.isclose(mu_x, 0, atol=0.1)
assert np.isclose(std_x, 1.0, atol=0.1)
assert np.isclose(mu_y, 1, atol=0.1)
assert np.isclose(std_y, 0.75, atol=0.1)
示例6: fit_t
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def fit_t(ret):
parm = t.fit(ret)
nu, mu_t, sig_t = parm
nu = np.round(nu)
return mu_t, sig_t, nu
示例7: get_stroke_properties
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def get_stroke_properties(self, stroke_widths):
if len(stroke_widths) == 0:
return (0, 0, 0, 0, 0, 0)
try:
most_probable_stroke_width = mode(stroke_widths, axis=None)[0][0]
most_probable_stroke_width_count = mode(stroke_widths, axis=None)[1][0]
except IndexError:
most_probable_stroke_width = 0
most_probable_stroke_width_count = 0
try:
mean, std = norm.fit(stroke_widths)
x_min, x_max = int(min(stroke_widths)), int(max(stroke_widths))
except ValueError:
mean, std, x_min, x_max = 0, 0, 0, 0
return most_probable_stroke_width, most_probable_stroke_width_count, mean, std, x_min, x_max
示例8: _rerender
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def _rerender(self):
nmr_maps = len(self.maps_to_show)
if self._show_trace:
nmr_maps *= 2
grid = GridSpec(nmr_maps, 1, left=0.04, right=0.96, top=0.94, bottom=0.06, hspace=0.2)
i = 0
for map_name in self.maps_to_show:
samples = self._voxels[map_name]
if self._sample_indices is not None:
samples = samples[:, self._sample_indices]
title = map_name
if map_name in self.names:
title = self.names[map_name]
if isinstance(self._nmr_bins, dict) and map_name in self._nmr_bins:
nmr_bins = self._nmr_bins[map_name]
else:
nmr_bins = self._nmr_bins
hist_plot = plt.subplot(grid[i])
try:
n, bins, patches = hist_plot.hist(np.nan_to_num(samples[self.voxel_ind, :]), nmr_bins, normed=True)
plt.title(title)
i += 1
if self._fit_gaussian:
mu, sigma = norm.fit(samples[self.voxel_ind, :])
bincenters = 0.5*(bins[1:] + bins[:-1])
y = mlab.normpdf(bincenters, mu, sigma)
hist_plot.plot(bincenters, y, 'r', linewidth=1)
if self._show_trace:
trace_plot = plt.subplot(grid[i])
trace_plot.plot(samples[self.voxel_ind, :])
i += 1
except IndexError:
pass
示例9: _get_random_variable
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def _get_random_variable(self):
"""Get the RV object according to the derived anomaly scores."""
loc, scale = norm.fit(self.anomaly_score_)
return norm(loc=loc, scale=scale)
示例10: fit
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def fit(self, X, y=None):
"""Fit the model according to the given training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : ignored
Returns
-------
self : object
Return self.
"""
self._check_params()
X = self._check_array(X, estimator=self)
self._fit(X)
self.classes_ = np.array([NEG_LABEL, POS_LABEL])
_, self.n_features_ = X.shape
self.anomaly_score_ = self._anomaly_score(X)
self.threshold_ = self._get_threshold()
self.contamination_ = self._get_contamination()
self.random_variable_ = self._get_random_variable()
return self
示例11: plot_galaxy_fit_subplot
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def plot_galaxy_fit_subplot(self, fit):
if self.plot_subplot_galaxy_fit:
fit_galaxy_plots.subplot_fit_galaxy(
fit=fit, include=self.include, sub_plotter=self.sub_plotter
)
示例12: plot_fit_individuals
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def plot_fit_individuals(self, fit):
fit_galaxy_plots.individuals(
fit=fit,
plot_image=self.plot_galaxy_fit_image,
plot_noise_map=self.plot_galaxy_fit_noise_map,
plot_model_image=self.plot_galaxy_fit_model_image,
plot_residual_map=self.plot_galaxy_fit_residual_map,
plot_chi_squared_map=self.plot_galaxy_fit_chi_squared_map,
include=self.include,
plotter=self.plotter,
)
示例13: visualize_stochastic_histogram
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def visualize_stochastic_histogram(
self, log_evidences, max_log_evidence, during_analysis
):
if log_evidences is None:
return
plotter = self.plotter.plotter_with_new_output(
path=self.plotter.output.path + "other/"
)
if self.plot_stochastic_histogram and not during_analysis:
bins = conf.instance.general.get(
"inversion", "stochastic_histogram_bins", int
)
(mu, sigma) = norm.fit(log_evidences)
n, bins, patches = plt.hist(x=log_evidences, bins=bins, density=1)
y = norm.pdf(bins, mu, sigma)
plt.plot(bins, y, "--")
plt.xlabel("log evidence")
plt.title("Stochastic Log Evidence Histogram")
plt.axvline(max_log_evidence, color="r")
plt.savefig(
f"{plotter.output.path}stochastic_histogram.png", bbox_inches="tight"
)
示例14: visualize_fit_in_fits
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def visualize_fit_in_fits(self, fit):
fits_plotter = self.plotter.plotter_with_new_output(
path=self.plotter.output.path + "fit_imaging/fits/", format="fits"
)
fit_imaging_plots.individuals(
fit=fit,
plot_image=True,
plot_noise_map=True,
plot_signal_to_noise_map=True,
plot_model_image=True,
plot_residual_map=True,
plot_normalized_residual_map=True,
plot_chi_squared_map=True,
plot_subtracted_images_of_planes=True,
plot_model_images_of_planes=True,
plot_plane_images_of_planes=True,
include=self.include,
plotter=fits_plotter,
)
if fit.inversion is not None:
fits_plotter = self.plotter.plotter_with_new_output(
path=self.plotter.output.path + "inversion/fits/", format="fits"
)
inversion_plots.individuals(
inversion=fit.inversion,
plot_reconstructed_image=True,
plot_interpolated_reconstruction=True,
plot_interpolated_errors=True,
include=self.include,
plotter=fits_plotter,
)
示例15: visualize_hyper_galaxy
# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import fit [as 别名]
def visualize_hyper_galaxy(self, fit, hyper_fit, galaxy_image, contribution_map_in):
hyper_plots.subplot_fit_hyper_galaxy(
fit=fit,
hyper_fit=hyper_fit,
galaxy_image=galaxy_image,
contribution_map_in=contribution_map_in,
include=self.include,
sub_plotter=self.sub_plotter,
)