pydecisions — A Python Library of management decision making techniques
In today’s world, we know the importance of taking logical decisions based on data. All major management and business decisions should be backed by data. Decades back, good managers rely on their intuition to take decisions (and some of them did very well too!) but this is no longer the case today. In-fact today, more often than not, managers needs to provide justification as to why such and such decisions were taken.
I have written this library to include some of the techniques employed in making management decisions (at-least some of the techniques which I use very often). This is primarily intended to be used by managers to make quick data backed assessments. The library includes some functions related to machine learning, statistics, linear programming, finance, decision trees, markov chain, etc.
The details as to how to use this library is mentioned below:
INSTALL:
pip install pydecisions
IMPORT:
import pydecisions as pyd
A COMPLETE EXAMPLE:
import pydecisions as pyd
a = pyd.evm(100,0.5,0.4,45)
print(a.results())
The following examples illustrates how to use this library.
EXAMPLES
1. Earned Value Management
Example:
a = pyd.evm(100,0.5,0.4,45)
print(a.results())
(where arg1 — Budget at Completion, arg2 — work planned to be completed at that point against the total work planned, arg3 — actual work completed at that point against the total work planned, arg4 — Actual Cost incurred till that point)
2. Financial functions
(a) Net Present Value
Example:
a = pyd.fin()
print(a.npv(.3,[-100,50,30,20,10]))
(where arg1 — rate, arg2 — yearly cash flows)
(b) Future Value
Example:
a = pyd.fin()
print(a.fv(0.10, 9, 300, 400))
(where arg1 — rate, arg2 — nos of years, arg3 — payment, arg4 — present value)
c) Present Value
Example:
a = pyd.fin()
print(a.pv(0.05, 10, 100, 30000))
(where arg1 — rate, arg2 — no of years, arg3-payment, arg4 — future value)
(d) Internal Rate of Return
Example:
a = pyd.fin()
print(a.irr([-100,30,90,75,20]))
(where arg1 — cash flows yearly)
3. Simple Linear Regression
Example:
a = pyd.slr()
print(a.results([1,2,3,4],[1.5,2.5,3.3,4.2],3))
(where arg1 — training X, arg2 — training Y and arg3 — test X)
4. Statistical tests
(a) T-test (mean of one group of scores)
Example:
a = pyd.statstest()
print(a.tt1([20,44,50,70,30],45))
(where arg1 — sample observations, arg2 — population mean)
(b) T-test (means of two independent samples of data)
Example:
a = pyd.statstest()
print(a.ttind([50,40,90,30,40], [60,40,20,10,70]))
(where arg1 — sample 1 observations, arg2 — sample 2 observations)
c) T-test (2 related samples of data).
Example:
a = pyd.statstest()
print(a.ttrel([55,20,23,12,12], [22,48,11,17,12]))
(where arg1 — sample 1 observations, arg2 — sample 2 observations)
5. Decision Analysis and Resolution
Example:
a = pyd.dar()
print(a.results([8,9],[7,6]))
(where arg1 — criteria scores for Alternative 1 and arg2 — criteria scores for Alternative 2)
6. Markov Chain
You need to import numpy in this example
i.e.
import pydecisions as pyd
import numpy as np
Example:
a = pyd.mc()
matrx = np.matrix([[0.7, 0.3],
[0.6, 0.4]])
I = np.matrix([[0.5, 0.5]])
print(a.results(matrx,I,3))
(where matrx — the transition matrix, I — the current state matrix, the third argument (3 in the above example) is for the number of iterations)
7. Bayes Rule
Example:
(For calculating P(A|B))
a = pyd.bayes()
print(a.results(0.6,0.4,0.2))
(where arg1 — P(A), arg2 — P(B), arg3 — P(B/A))
8. Linear Programming
Example:
Minimize: cost = -2*x[0] + 5*x[1], Subject to: -2*x[0] + 3*x[1] <= 7, 2*x[0] + 1*x[1] <= 5
x[1] >= -4 (where: -infinity <= x[0] <= infinity)
a = pyd.lp()
c = [-2, 5]
A = [[-2, 3], [2, 1]]
b = [7, 5]
lp_x0b = (None, None)
lp_x1b = (-4, None)
print(a.results(c,A,b,lp_x0b,lp_x1b))
9. Decision Trees: Regression
Example:
a = pyd.DTr()
x = [[1, 2],
[2, 2],
[3, 3],
[4, 5],
[7, 4]]
y = [3,4,5,8,11]
z = [[3,2]]
a.results(x,y,z)
(where arg1 — training x, arg2 — training y and arg3 — test x)
Tree Image will be generated in the folder.
10. Decision Trees: Classification
Example:
a = pyd.DTc()
x = [ [20, 15, 2],
[60, 25, 4],
[70, 35, 6],
[80, 40, 8],
[90, 45, 10]]
y = [‘c0’, ‘c1’, ‘c1’, ‘c0’, ‘c1’]
z = [[60, 30, 5]]
a.results(x,y,z)
(where arg1 — training x, arg2 — training y and arg3 — test x)
Tree Image will be generated in the folder.
Some of these functions are completely written from scratch and some functions are built on the top of the existing standard library functions.
DEPENDENCIES — numpy, scipy, sklearn and graphviz libraries
Hope this article was helpful to you. Thank you.