Currently shape of the predict_function output is not validated and anything that does not raise an error while
computing residuals passes silently through instantianting Explainer object, with incorrect results:
import numpy as np
import dalex as dx
from sklearn.ensemble import RandomForestRegressor
data = dx.datasets.load_fifa()
X = data.drop(columns=['nationality', 'value_eur'])
y = data['value_eur']
model = RandomForestRegressor()
model.fit(X, y)
def predict_function_return_2d(model, data):
n_rows = data.shape[0]
prediction = model.predict(data)
return prediction.reshape((n_rows, 1))
def predict_function_return_3d(model, data):
n_rows = data.shape[0]
prediction = model.predict(data)
return prediction.reshape((n_rows, 1, 1))
def predict_function_return_one_element_array(model, data):
return np.array(0.2)
exp_2d = dx.Explainer(model, X, y, verbose=True, model_type='regression', predict_function=predict_function_return_2d)
print(exp_2d.y_hat.shape)
print(exp_2d.residuals.shape)
exp_3d = dx.Explainer(model, X, y, verbose=True, model_type='regression', predict_function=predict_function_return_3d)
print(exp_3d.y_hat.shape)
print(exp_3d.residuals.shape)
exp_one = dx.Explainer(model, X, y, verbose=True, model_type='regression', predict_function=predict_function_return_one_element_array)
print(exp_one.y_hat.shape)
print(exp_one.residuals.shape)
Currently shape of the
predict_functionoutput is not validated and anything that does not raise an error whilecomputing residuals passes silently through instantianting Explainer object, with incorrect results: