# XAI Experiment 5: Individual Conditional Expectation (ICE) Plot  [exam version]
# Requires: exam: none | lab: matplotlib
# ===========================================================================

# Dataset
X = [[5, 2], [6, 3], [7, 4]]

# Prediction model
def model(x1, x2):
    return 3.5 + 3*x1 + 4*x2

grid = [5, 6, 7]

ice = []

for row in X:
    predictions = []

    for value in grid:
        predictions.append(model(value, row[1]))

    ice.append(predictions)

# Print ICE table
print("X1\tSample1\tSample2\tSample3")

for j in range(len(grid)):
    print(grid[j], end="\t")

    for i in range(len(X)):
        print(ice[i][j], end="\t")

    print()

# Calculate PDP (average of ICE curves)
print("\nPDP Values:")

for j in range(len(grid)):
    avg = sum(ice[i][j] for i in range(len(X))) / len(X)
    print(grid[j], ":", avg)
