Skip to content

Commit 14b1f61

Browse files
author
Montana Low
committed
use bytea directly for pl/python rather than hex/text conversion
1 parent 958cfba commit 14b1f61

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scikit_train_and_predict.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ INSERT INTO scikit_train_data (value, weight) SELECT generate_series(1, 500), 5.
2626

2727

2828
CREATE OR REPLACE FUNCTION scikit_learn_train_example()
29-
RETURNS TEXT
29+
RETURNS BYTEA
3030
AS $$
3131
from sklearn.ensemble import RandomForestClassifier
3232
import pickle
@@ -45,18 +45,18 @@ AS $$
4545
rfc = RandomForestClassifier()
4646
rfc.fit(X, y)
4747

48-
return pickle.dumps(rfc).hex()
48+
return pickle.dumps(rfc)
4949

5050
$$ LANGUAGE plpython3u;
5151

5252
;
5353

54-
CREATE OR REPLACE FUNCTION scikit_learn_predict_example(model TEXT, value INT)
54+
CREATE OR REPLACE FUNCTION scikit_learn_predict_example(model BYTEA, value INT)
5555
RETURNS DOUBLE PRECISION
5656
AS $$
5757
import pickle
5858

59-
m = pickle.loads(bytes.fromhex(model))
59+
m = pickle.loads(model)
6060

6161
r = m.predict([[value,]])
6262
return r[0]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy