fmcquillan99 commented on pull request #560: URL: https://github.com/apache/madlib/pull/560#issuecomment-796321033
(1) ``` # import database connector psycopg2 and create connection cursor import psycopg2 as p2 conn = p2.connect('postgresql://gpadmin@localhost:8000/madlib') cur = conn.cursor() # import Dill and define functions import dill # custom loss def __squared_error(y_true, y_pred): import tensorflow.keras.backend as K return K.square(y_pred - y_true) pb_squared_error=dill.dumps(squared_error) # custom metric def _rmse(y_true, y_pred): import tensorflow.keras.backend as K return K.sqrt(K.mean(K.square(y_pred - y_true), axis=-1)) pb_rmse=dill.dumps(rmse) # call load function cur.execute("DROP TABLE IF EXISTS madlib.custom_function_table") cur.execute("SELECT madlib.load_custom_function('custom_function_table', %s,'__squared_error', 'squared error')", [p2.Binary(pb_squared_error)]) cur.execute("SELECT madlib.load_custom_function('custom_function_table', %s,'_rmse', 'root mean square error')", [p2.Binary(pb_rmse)]) conn.commit() ``` ``` SELECT madlib.load_top_k_accuracy_function('custom_function_table', 2); SELECT madlib.load_top_k_accuracy_function('custom_function_table', 3); SELECT madlib.load_top_k_accuracy_function('custom_function_table', 5); ``` ``` SELECT id, name, description FROM madlib.custom_function_table ORDER BY id; id | name | description ----+-----------------+------------------------ 1 | __squared_error | squared error 2 | _rmse | root mean square error 3 | top_2_accuracy | returns top_2_accuracy 4 | top_3_accuracy | returns top_3_accuracy 5 | top_5_accuracy | returns top_5_accuracy (5 rows) ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org