def verify_black_box_function(predict_method, number_of_features,
number_of_data_points=10):
# check estimator variable is a callable.
if not six.callable(predict_method):
raise Exception("Please pass in a callable.")
# now generate test data to verify that estimator is working
covariance = np.eye(number_of_features)
mean = np.zeros(number_of_features)
data = np.random.multivariate_normal(mean, covariance,
number_of_data_points)
try:
output = predict_method(data)
# check to make sure that the estimator returns a numpy
# array
if type(output).__module__ != 'numpy':
raise ValueError("Output of predict function is not "
"a numpy array")
if output.shape[0] != number_of_data_points:
raise Exception("Predict does not return an output "
"for every data point.")
except:
print("Unexpected error: ", sys.exc_info()[0])
return True
评论列表
文章目录