主要内容

matlab.production_server.client.PipelineClient

Namespace: matlab.production_server

Python client for machine learning pipelines deployed to MATLAB Production Server

Description

The matlab.production_server.client.PipelineClient class creates a connection object that encapsulates the connection between the Python® client and a LearningPipeline (Statistics and Machine Learning Toolbox) object deployed to a MATLAB® Production Server™ instance. Once the connection is created, you can use the get, learn, and run methods to interact with the deployed LearningPipeline object.

Construction

with PipelineClient(archive,host,port) as client creates a client connection between the Python client and the specified archive, which is an archive already deployed to MATLAB Production Server running on host:port.

Input Arguments

expand all

Archive deployed to MATLAB Production Server, specified as a string that indicates the base file name of the deployed archive, without a path or file extension. This argument sets the archive property of the client object.

Data Types: string

Host name or address of your MATLAB Production Server instance, specified as a string containing the IPv4 or IPv6 address or as localhost.

Data Types: string

Port number on which the MATLAB Production Server instance is running, specified as an integer between 1 and 65535.

Data Types: int

Output Arguments

expand all

Object encapsulating the connection between the client and the MATLAB Production Server instance on which the pipeline is hosted, specified as a PipelineClient object.

Methods

Public Methods

get

get(client,operation)

get(client,operation,url)

Apply an indexing operation to the deployed pipeline, optionally storing the result at a URL.

Input Arguments

  • client – The client for the pipeline to index, specified as a PipelineClient object

  • operation – Indexing operation, specified as a Python string using MATLAB syntax

  • url – Location to store the result, specified as a Python string

learn

client.learn(nargout, input0,...inputN)

Evaluate all the nodes in the pipeline associated with client by passing the inputs through the pipeline in the specified order. The function learns, or initializes, any data-dependent parameters (learnables) in the components of the pipeline. For components in the pipeline without data-dependent parameters, or for components that have already been learned, using learn is equivalent to using the run object function. This method is the client equivalent of the learn (Statistics and Machine Learning Toolbox) function for pipelines.

You can use the returned pipeline for inference with new data by using run.

Input Arguments

  • nargout – Number of output arguments, specified as an integer.

  • input0,...inputN – Inputs for the deployed pipeline, specified as Python strings. You can pass a MAT or CSV file as a URL string.

run

client.run(nargout, input0,...inputN)

Evaluate all the nodes in the associated pipeline that are required to return the outputs. The function ignores nodes that are not required to return the outputs. The function returns the pipeline's outputs. This method is the client equivalent of the run (Statistics and Machine Learning Toolbox) function for pipelines.

Input Arguments

  • nargout – Number of output arguments, specified as an integer.

  • input0,...inputN – Inputs for the pipeline, specified as Python strings. You can pass a MAT or CSV file as a URL string.

Properties

expand all

This property is read-only.

Host on which MATLAB Production Server is running, returned as a string containing the address or as "localhost".

This property is read-only.

Port number on which MATLAB Production Server is running, returned as an integer between 1 and 65535.

Example: 9910

This property is read-only.

Name of the archive that contains the pipeline, returned as a string.

This property is read-only.

Name of the network endpoint used to access the pipeline, returned as a string of form <host>:<port>/<archive>.

Examples

collapse all

Initialize the client and train the pipeline. Specify "localhost" for the host, the port number 9910, and the "CarOrigin" archive. The Python client requires the use of the with...as syntax for initialization, so you must call the learn method inside the with block. The client.learn method returns the outputs of the pipeline's learn (Statistics and Machine Learning Toolbox) function and trains the deployed pipeline.

import matlab
from production_server import PipelineClient

with PipelineClient("localhost", 9910, "CarOrigin") as client:
   output = client.learn(1, "file:/input/data/carData.csv", response)

Initialize the client object and run the pipeline. Specify "localhost" for the host, the port number 9910, and the "CarOrigin" archive. The Python client requires the use of the with...as syntax for initialization, so you must call the run method inside the with block. The client.run method returns the outputs of the trained pipeline's run (Statistics and Machine Learning Toolbox) method.

import matlab
from production_server import PipelineClient

with PipelineClient("localhost", 9910, "CarOrigin") as client:
   output = client.run(1, carData, response)

Initialize the client object, and then use the get method to get its attributes. You can have Python return the indexed data if there is a valid representation of that data in Python, or you can use the optional third input argument to specify a location for storing the data.

Get the first 10 support vectors from the trained model.

with PipelineClient("localhost", 9910, "CarOrigin") as client:
    v = get(client,"Components.SVM.TrainedModel.SupportVectors(1:10)")

Get the first 10 support vectors from the trained model, storing them in a URL rather than returning them to Python.

with PipelineClient("localhost", 9910, "CarOrigin") as client:
    get(client,"Components.SVM.TrainedModel.SupportVectors(1:10)", 
        "file:/data/storage/vectors.txt")

Retrieve data for the entire pipeline, and store the data in a MAT file. The index operation is the name of the pipeline.

with PipelineClient("localhost", 9910, "CarOrigin") as client:
    get(client, "CarOrigin", "file:/data/storage/CarPipe.mat")

More About

expand all

See Also

(Statistics and Machine Learning Toolbox) | (Statistics and Machine Learning Toolbox)

Topics