main

2022/02/11

statsmodels (a good stats package)

 In [1]: import numpy as np

In [2]: import statsmodels.api as sm

In [3]: import statsmodels.formula.api as smf

# Load data
In [4]: dat = sm.datasets.get_rdataset("Guerry", "HistData").data

# Fit regression model (using the natural log of one of the regressors)
In [5]: results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()

# Inspect the results
In [6]: print(results.summary())

matplotlib plot settings

method 1 

import matplotlib

matplotlib.rc('xtick', labelsize=20)

matplotlib.rc('ytick', labelsize=20)

matplotlib.rc('font',family='sans-serif', size=12)


 

method 2

import matplotlib.pyplot as plt

 

SMALL_SIZE = 8

MEDIUM_SIZE = 10

BIGGER_SIZE = 12

 

plt.rc('font', size=SMALL_SIZE)          # controls default text sizes

plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title

plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels

plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels

plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels

plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize

plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title

 

method 3

matplotlib.rc('xtick', labelsize=20)

matplotlib.rc('ytick', labelsize=20)

matplotlib.rc('font', size=20)

matplotlib.rc('axes', titlesize=20)

matplotlib.rc('axes', labelsize=20)

matplotlib.rc('legend', fontsize=20)

matplotlib.rc('figure', titlesize=20)

 


method 4

#size=25

size=15

params = {'legend.fontsize': 'large',

          'figure.figsize': (20,8),

          'axes.labelsize': size,

          'axes.titlesize': size,

          'xtick.labelsize': size*0.75,

          'ytick.labelsize': size*0.75,

          'axes.titlepad': 25}

plt.rcParams.update(params)

 

2022/02/09

beta-PERT Monte Carlo Simulation

 Here, we are running Beta-PERT Monte Carlo simulation.


from scipy import stats as stats

from scipy.stats import beta as beta

from scipy.stats import rv_continuous


import matplotlib.pylab as plt


class Beta_PERT(rv_continuous):

    def _shape(self, minimum, mode, maximum, lamb):

        alpha = 1+lamb*(mode-minimum)/(maximum-minimum)

        beta = 1+lamb*(maximum-mode)/(maximum-minimum)

        return [alpha,beta]

    

    def _cdf(self,x, minimum, mode, maximum, lamb):

        s_alpha, s_beta = self._shape(minimum, mode, maximum, lamb)

        z = (x-minimum)/(maximum-minimum)

        cdf = beta.cdf(z,s_alpha,s_beta)

        return cdf

    

pert = Beta_PERT(name="pert")


rv_1 = pert(0.02,0.05,0.2,4)

rv_2 = pert(1,5,20,4)


N = 5000


freq = rv_1.rvs(N)

loss = rv_2.rvs(N)


ALE = freq*loss





How to Supercharge Your Python Classes with Class Methods

  How to Supercharge Your Python Classes with Class Methods | by Siavash Yasini | May, 2024 | Towards Data Science As we just mentioned, a c...