scipy stats.rv_continuous () | python



scipy.stats.rv_continuous() — it is a class of continuous random variables intended for subclasses. It is a base class for constructing a specific distribution from continuous random variables. This class cannot be directly used as a distribution.

Parameters:
moment: [int] moment calculation to use: 0 for pdf, 1 for ppf. Default = 1
a: [float] Lower bound for distribution. Default is -ve infinity.
b: [float] Upper bound for distribution. Default is + ve infinity.
xtol: [float] tolerance for fixed point calculation for ppf
name: [str] Name of the instance. Used to construct the default eg for distributions
badvalue: [object] Default is np.nan. Value in a result arrays that indicates a value that for which some argument restriction is violated.
logname: [str] Used as part of theFirst line of the docstring.
extradoc: [str] Used as the last part of the docstring
shapes: [str] Shape of the distribution.

Return : Continuous Random Variable Distribution.

Code # 1: Using the “rv_continuous class”.

def sample ( self , size = 1 , random_state = None ):

 

  " ""

Return sample from PDF - probability distribution function.

call - rv_continuous class.

 

"" "

  

  return self ._ rv.rvs (size = size, random_state = random_state) 

Code # 2: Generating a Gaussian distribution from rv_continuous.

< p> from scipy.stats import rv_continuous

import numpy as np

 

class gaussian_gen (rv_continuous):

& # 39; & # 39; & # 39; Gaussian distribution & # 39; & # 39; & # 39;

def _ pdf ( self , x):

  return np.exp ( - x * * 2 / 2. ) / np.sqrt ( 2.0 * np.pi)

 

gaussian = gaussian_gen (name = ` gaussian` )

  

x = 2.0

gaussian._pdf (x)

Output:

 0.05399096651318806