After solving all the questions in the exam save your notebook with the name username.ipynb and submit it to: https://www.dropbox.com/request/ppnwCHBo3G2eVo1tJPdY
In [11]:
def bn_model(data, k):
'''
data: training data as a list of lists
[[x_1, x_2, ..., X_n, A, B]
[x_1, x_2, ..., X_n, A, B]
:
[x_1, x_2, ..., X_n, A, B]
]
k: Laplace's smoothing parameter
returns:
It must return the model as a dictionary with the following form:
For example:
{ 'A' : 0.1,
('B', 'A', 0) : 0.4
('B', 'A', 1) : 0.7
('x1', 'B', 0) : 0.3,
('x1', 'B', 1) : 0.1,
('x2', 'B', 0) : 0.2,
('x2', 'B', 1) : 0.6,
}
In this case the entry for 'A' means that P(A = 1) = 0.4 and therefore P(A = 0) = 0.6.
In the same way, the entry for ('x1', 'B', 1) indicates that P(X_1 = 1 | B = 1) = 0.1 and
therefore P(X_1 = 0 | B = 1) = 0.9.
'''
return {}
In [ ]:
def p1(model, X):
'''
model: a dictionary with the model probabilities.
X: a list with x_i values [x_1, x_2, ... , x_n]
Returns: the probability P(B = 1 | x_1, x_2, ... , x_n)
'''
return 0
In [12]:
def p2(model, X):
'''
model: a dictionary with the model probabilities.
X: a list with x_i values [x_1, x_2, ... , x_n]
Returns: the probability P(A = 1 | x_1, x_2, ... , x_n)
'''
return 0
In [13]:
def p3(model, x_1, x_n):
'''
model: a dictionary with the model probabilities.
x_1, x_n: x values
Returns: the probability P(A = 1 | x_1, x_n)
'''
return 0