/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using System;
using Amazon.Runtime;
using Amazon.MachineLearning.Model;
using System.Collections.Generic;
namespace Amazon.MachineLearning.Util
{
///
/// A simplified client that just does realtime predictions.
///
public partial class RealtimePredictor : IDisposable
{
///
/// Constructs a RealtimePredictor which construct a client using configured defaults.
///
///
/// The endpoint URL will be determined my making a service call to retrieve it.
///
/// The MachineLearning model to predict against.
public RealtimePredictor(string modelId)
{
this.client = new AmazonMachineLearningClient();
this.shouldDispose = true;
this.ModelId = modelId;
}
///
/// The realtime prediction endpoint for the given MLModel.
///
public string Endpoint
{
get
{
if (null == this.endpoint)
this.endpoint = client.GetMLModel(ModelId).EndpointInfo.EndpointUrl;
return this.endpoint;
}
}
///
/// Generates a prediction for an observation.
///
/// Data to generate a prediction for.
/// A prediction for the observation, as returned by MachineLearning.
///
/// An error on the server occurred when trying to process a request.
///
///
/// An error on the client occurred. Typically, the cause is an invalid input value.
///
///
/// The subscriber exceeded the maximum number of operations. This exception can occur
/// when listing objects such as DataSource
.
///
///
/// The exception is thrown when a predict request is made to an unmounted MLModel
.
///
///
/// A specified resource cannot be located.
///
public Prediction Predict(Dictionary record)
{
return client.Predict(new PredictRequest {
MLModelId = ModelId,
PredictEndpoint = Endpoint,
Record = record
}).Prediction;
}
}
}