MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / Pred

Function Pred

go/codegen/tensorflow/codegen.go:304–348  ·  view source on GitHub ↗

Pred generates a Python program for predict using a TensorFlow model.

(predStmt *ir.PredictStmt, session *pb.Session)

Source from the content-addressed store, hash-verified

302
303// Pred generates a Python program for predict using a TensorFlow model.
304func Pred(predStmt *ir.PredictStmt, session *pb.Session) (string, error) {
305 modelParams, featureColumnsCode, fieldDescs, err := restoreModel(predStmt.TrainStmt)
306 if err != nil {
307 return "", err
308 }
309 trainLabelFM := predStmt.TrainStmt.Label.GetFieldDesc()[0]
310 predLabelFM := &ir.FieldDesc{
311 Name: predStmt.ResultColumn,
312 DType: trainLabelFM.DType,
313 Delimiter: trainLabelFM.Delimiter,
314 Format: trainLabelFM.Format,
315 Shape: trainLabelFM.Shape,
316 IsSparse: trainLabelFM.IsSparse,
317 Vocabulary: trainLabelFM.Vocabulary,
318 MaxID: trainLabelFM.MaxID,
319 }
320
321 filler := predFiller{
322 DataSource: session.DbConnStr,
323 Select: predStmt.Select,
324 ResultTable: predStmt.ResultTable,
325 Estimator: predStmt.TrainStmt.Estimator,
326 FieldDescs: fieldDescs,
327 FeatureColumnCode: fmt.Sprintf("{%s}", strings.Join(featureColumnsCode, ",\n")),
328 TrainLabelMeta: trainLabelFM,
329 PredLabelMeta: predLabelFM,
330 ModelParams: modelParams,
331 Save: "model_save",
332 HDFSNameNodeAddr: session.HdfsNamenodeAddr,
333 HiveLocation: session.HiveLocation,
334 HDFSUser: session.HdfsUser,
335 HDFSPass: session.HdfsPass,
336 }
337 var program bytes.Buffer
338 var predTemplate = template.Must(template.New("Pred").Funcs(template.FuncMap{
339 "intArrayToJSONString": ir.MarshalToJSONString,
340 "attrToPythonValue": ir.AttrToPythonValue,
341 "DTypeToString": ir.DTypeToString,
342 }).Parse(tfPredTemplateText))
343 if err := predTemplate.Execute(&program, filler); err != nil {
344 return "", err
345 }
346
347 return program.String(), nil
348}
349
350// Explain generates a Python program to explain a trained model.
351func Explain(stmt *ir.ExplainStmt, session *pb.Session) (string, error) {

Callers 3

ExecutePredictMethod · 0.92
TestPredictCodegenFunction · 0.92
TestTrainCodegenFunction · 0.70

Calls 4

restoreModelFunction · 0.85
GetFieldDescMethod · 0.65
ParseMethod · 0.65
StringMethod · 0.45

Tested by 2

TestPredictCodegenFunction · 0.74
TestTrainCodegenFunction · 0.56