black_box_functionality.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:fairml 作者: adebayoj 项目源码 文件源码
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
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号