Skip to main content

Model Selection

Original integration-test class: ModelSelection in 2.ML.ModelSelection.cs. This is a direct SDK operation, not a PipelineClient workflow.

199 recorded job or prediction directories matched by module and scenario path. 195 have completed/success status and a saved result. These are API execution records, not confirmed xUnit pass counts. Partition jobs are counted separately.

Prerequisites​

Use the original SDK test project, its xUnit dependencies, helper classes and any upstream cache entries referenced in the source. See configuration.

Required environment variable names referenced in the source: PARALLELMODEL_MODEL_ID, PARALLELMODEL_COMPUTE_SIZE, PARALLELMODEL_ENCRYPTION_KEY_1, PARALLELMODEL_REGION, PARALLELMODEL_CLIENT_ID, PARALLELMODEL_CLIENT_SECRET.

SDK calls used​

ClientMethods in the source
ModelSelectionClientDownloadBytesAsync, ExtractAsync, LogAsync, ResultAsync, SendAsync, StatusAsync

Execution workflow​

  1. Initialise the client and output paths.
  2. Read the exact upstream dataset run and its saved result metadata.
  3. Send the original strongly typed request and save the SDK response.
  4. Poll status and save every response until the job reaches a terminal state.
  5. Retrieve logs once successfully, following the Dataset test pattern.
  6. Retrieve the result without projecting the response into a new model.
  7. Extract and download each returned artifact.
  8. Save one cache entry for this dataset/algorithm with all extracted artifacts.

Recorded operation examples​

OperationRecorded jobsResult recorded
CheckCv1010
CrossValPredict99
CrossValScore99
CrossValidate99
FixedThresholdClassifier22
GridSearchCV66
HalvingGridSearchCV66
HalvingRandomSearchCV66
KFold1010
LearningCurve99
LearningCurveDisplay99
LeaveOneOut22
LeavePOut20
ParameterGrid1010
ParameterSampler1010
PermutationTestScore99
RandomizedSearchCV66
RepeatedKFold109
RepeatedStratifiedKFold76
ShuffleSplit1010
StratifiedKFold77
StratifiedShuffleSplit77
TimeSeriesSplit1010
TrainTestSplit1010
TunedThresholdClassifierCV22
ValidationCurve66
ValidationCurveDisplay66

Run the original integration test​

This filter selects the class and its parameterized scenarios; it does not select only a single recorded job.

dotnet test --filter "FullyQualifiedName~ParallelModel.Sdk.UnitTests.ModelSelection.Run"

Full C# source​

The supplied test logic is preserved. The method signature is:

Run(string datasetName, string name)
using ParallelModel.Sdk.Authentication;
using ParallelModel.Sdk.Exceptions;
using ParallelModel.Sdk.ML.ModelSelection.Models;
using ParallelModel.Sdk.ML.ModelSelection.Models.Requests;
using ParallelModel.Sdk.UnitTests.Attributes;
using ParallelModel.Sdk.UnitTests.Cache;
using ParallelModel.Sdk.UnitTests.Helpers;
using ParallelModel.Sdk.UnitTests.Models;

namespace ParallelModel.Sdk.UnitTests;

/// <summary>Runs compatible model-selection operations against cached dataset blobs.</summary>
[Collection("ModelSelection")]
public sealed class ModelSelection
{
private static readonly SharedSendThrottle sendThrottle = new(TimeSpan.FromSeconds(12));
private static readonly TimeSpan ApiTimeout = TimeSpan.FromSeconds(300);

private static readonly string[] Algorithms =
{
"CheckCv",
"CrossValPredict",
"CrossValScore",
"CrossValidate",
"FixedThresholdClassifier",
"GridSearchCV",
"HalvingGridSearchCV",
"HalvingRandomSearchCV",
"KFold",
"LearningCurveDisplay",
"LearningCurve",
"LeaveOneOut",
"LeavePOut",
"ParameterGrid",
"ParameterSampler",
"PermutationTestScore",
"RandomizedSearchCV",
"RepeatedKFold",
"RepeatedStratifiedKFold",
"ShuffleSplit",
"StratifiedKFold",
"StratifiedShuffleSplit",
"TimeSeriesSplit",
"TrainTestSplit",
"TunedThresholdClassifierCV",
"ValidationCurveDisplay",
"ValidationCurve",
};

public static TheoryData<string, string> ModelSelectionRequests =>
DatasetAttribute.GetRequests(typeof(ModelSelection), nameof(Run), ModelSelectionAlgorithmsFor);

private static string[] ModelSelectionAlgorithmsFor(string datasetName) =>
Algorithms.Where(algorithm => MLDatasetHelper.IsCompatible(datasetName, algorithm)).ToArray();

[Theory]
[MemberData(nameof(ModelSelectionRequests))]
[Dataset("Fetch20Newsgroups")]
//[Dataset("Fetch20NewsgroupsVectorized")]
//[Dataset("FetchCaliforniaHousing")]
//[Dataset("FetchOpenml")]
[Dataset("LoadBreastCancer")]
[Dataset("LoadDiabetes")]
[Dataset("LoadIris")]
//[Dataset("LoadLinnerud")]
[Dataset("LoadWine")]
//[Dataset("MakeBiclusters")]
[Dataset("MakeBlobs")]
//[Dataset("MakeCheckerboard")]
[Dataset("MakeCircles")]
[Dataset("MakeClassification")]
[Dataset("MakeFriedman1")]
//[Dataset("MakeFriedman2")]
//[Dataset("MakeFriedman3")]
//[Dataset("MakeGaussianQuantiles")]
//[Dataset("MakeHastie102")]
//[Dataset("MakeLowRankMatrix")]
//[Dataset("MakeMoons")]
//[Dataset("MakeMultilabelClassification")]
[Dataset("MakeRegression")]
//[Dataset("MakeSCurve")]
//[Dataset("MakeSparseCodedSignal")]
//[Dataset("MakeSparseSpdMatrix")]
//[Dataset("MakeSparseUncorrelated")]
//[Dataset("MakeSpdMatrix")]
//[Dataset("MakeSwissRoll")]
public async Task Run(string datasetName, string name)
{
// 1. Initialise the client and output paths.
SharedEnvironmentHelper.LoadEnvIfAvailable();
CancellationToken cancellationToken = TestContext.Current.CancellationToken;
Guid modelId = SharedEnvironmentHelper.RequiredGuid("PARALLELMODEL_MODEL_ID");
string computeSize = SharedEnvironmentHelper.Required("PARALLELMODEL_COMPUTE_SIZE");
string encryptionKey = SharedEnvironmentHelper.Required("PARALLELMODEL_ENCRYPTION_KEY_1");
TimeSpan apiRequestTimeout = ApiTimeout;
TimeSpan pollingInterval = TimeSpan.FromSeconds(30);
ParallelModelClient parallelModelClient = new(new DefaultParallelModelAuthenticationOptions
{
Region = SharedEnvironmentHelper.Required("PARALLELMODEL_REGION"),
ClientId = SharedEnvironmentHelper.Required("PARALLELMODEL_CLIENT_ID"),
ClientSecret = SharedEnvironmentHelper.Required("PARALLELMODEL_CLIENT_SECRET"),
Timeout = TimeSpan.FromSeconds(90)
});

string outputRoot = SharedEnvironmentHelper.OutputDirectory;
string runId = Guid.NewGuid().ToString("N");
string outputDirectory = Path.Combine(outputRoot, "model-selection", datasetName, name, runId);
string cacheDirectory = SharedEnvironmentHelper.CacheDirectory;
Directory.CreateDirectory(Path.Combine(outputDirectory, "artifacts"));
int responseFileNumber = 0;

// 2. Read the exact upstream dataset run and its saved result metadata.
DatasetFixture dataset = await MLDatasetHelper.LoadDatasetAsync(datasetName, modelId, cacheDirectory,
cancellationToken);

// 3. Send the original strongly typed request and save the SDK response.
await sendThrottle.WaitForSendSlotAsync(cancellationToken);
string requestFileName = $"{++responseFileNumber:000}-request.json";
ParallelModelModelSelectionSendResponseModel sendResponse = await RequestAsync("send",
() => SendSelectionAsync(name, parallelModelClient, modelId, dataset, computeSize,
encryptionKey, cancellationToken, outputDirectory, requestFileName));
Guid jobId = sendResponse.JobId;

// 4. Poll status and save every response until the job reaches a terminal state.
DateTimeOffset statusDeadline = DateTimeOffset.UtcNow.AddMinutes(10);
for (int attempt = 1; ; attempt++)
{
ParallelModelModelSelectionStatusResponseModel statusResponse = await RequestAsync(
$"status-{attempt:000}", () => parallelModelClient.ModelSelectionClient.StatusAsync(
modelId, jobId, computeSize, apiRequestTimeout, cancellationToken));
if (statusResponse is not ParallelModelModelSelectionStatusResponseModel.Success status)
throw new InvalidOperationException($"Job {jobId} returned a status API error. See saved response.");
string? jobStatus = status.Status?.ToLowerInvariant();
if (jobStatus is "success" or "succeeded" or "completed")
break;
if (jobStatus is "error" or "failed" or "cancelled" or "canceled" or "deadletter" or
"dead-lettered" or "deadlettered" or "dead_letter" or "dead-letter")
{
try
{
await RequestAsync("logs", () => parallelModelClient.ModelSelectionClient.LogAsync(
modelId, jobId, computeSize, apiRequestTimeout, cancellationToken));
}
catch (Exception exception) when (!cancellationToken.IsCancellationRequested &&
exception is not OperationCanceledException)
{
// RequestAsync already saved the error; retain the terminal job failure.
}
throw new InvalidOperationException($"Job {jobId} ended with status '{status.Status}'. See saved response.");
}
if (DateTimeOffset.UtcNow >= statusDeadline)
throw new TimeoutException($"Status polling expired for job {jobId}.");
await Task.Delay(pollingInterval, cancellationToken);
}

// 5. Retrieve logs once successfully, following the Dataset test pattern.
try
{
await RequestAsync("logs", () => parallelModelClient.ModelSelectionClient.LogAsync(
modelId, jobId, computeSize, apiRequestTimeout, cancellationToken), maximumAttempts: 10);
}
catch (Exception exception) when (!cancellationToken.IsCancellationRequested && IsTransient(exception))
{
// Logs may be temporarily unavailable; the result can still be retrieved.
}

// 6. Retrieve the result without projecting the response into a new model.
ParallelModelModelSelectionResultResponseModel result = await RequestAsync("result",
() => parallelModelClient.ModelSelectionClient.ResultAsync(modelId, jobId, computeSize,
encryptionKey, timeout: apiRequestTimeout, cancellationToken: cancellationToken),
maximumAttempts: int.MaxValue, retryDeadline: DateTimeOffset.UtcNow.AddMinutes(5));

// 7. Extract and download each returned artifact.
IReadOnlyList<string>? returnedArtifactFiles = result.ArtifactFiles;
IReadOnlyList<string> artifactFiles = returnedArtifactFiles ?? Array.Empty<string>();
List<ModelSelectionArtifactCacheEntry> artifacts = new();
for (int index = 0; index < artifactFiles.Count; index++)
{
string artifactPath = artifactFiles[index];
ParallelModelModelSelectionExtractResponseModel extractResponse = await RequestAsync(
$"extract-{index + 1:000}", () => parallelModelClient.ModelSelectionClient.ExtractAsync(
modelId: modelId, jobId: jobId, fileName: artifactPath, computeSize: computeSize,
inputEncryptionKey: encryptionKey, outputEncryptionKey: encryptionKey,
timeout: apiRequestTimeout, cancellationToken: cancellationToken), maximumAttempts: 5);
Guid blobId = extractResponse.UploadedBlobId;
artifacts.Add(new ModelSelectionArtifactCacheEntry(artifactPath, blobId));
byte[] bytes = await RequestAsync($"download-{index + 1:000}",
() => parallelModelClient.ModelSelectionClient.DownloadBytesAsync(
modelId: modelId, jobId: jobId, blobId: blobId, computeSize: computeSize,
inputEncryptionKey: encryptionKey, timeout: apiRequestTimeout,
cancellationToken: cancellationToken), maximumAttempts: 5, saveJson: false);
await SharedArtifactHelper.SaveAsync(outputDirectory, index + 1, artifactPath, bytes, cancellationToken);
}

// 8. Save one cache entry for this dataset/algorithm with all extracted artifacts.
// Replace the existing cache group only after all downloads succeed.
ModelSelectionCacheEntry cacheEntry = new(datasetName, name, dataset.BlobId,
artifacts.OrderBy(artifact => artifact.ArtifactPath, StringComparer.Ordinal).ToList());
await SharedCacheHelper.UpdateAsync<List<ModelSelectionCacheEntry>>(
cacheDirectory, ModelSelectionCacheEntry.FileName, existingEntries =>
{
List<ModelSelectionCacheEntry> entries = existingEntries ?? new();
entries.RemoveAll(entry => string.Equals(entry.Dataset, datasetName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(entry.Algorithm, name, StringComparison.OrdinalIgnoreCase));
entries.Add(cacheEntry);
return entries.OrderBy(entry => entry.Dataset, StringComparer.Ordinal)
.ThenBy(entry => entry.Algorithm, StringComparer.Ordinal).ToList();
}, cancellationToken);

// Request execution stays local to Run. Storage helpers know nothing about jobs.
async Task<T> RequestAsync<T>(string stage, Func<Task<T>> request,
int maximumAttempts = 1, bool saveJson = true, DateTimeOffset? retryDeadline = null)
{
for (int attempt = 1; ; attempt++)
{
T response;
try
{
response = await request();
}
catch (Exception exception) when (!cancellationToken.IsCancellationRequested)
{
await SharedResponseHelper.SaveExceptionAsync(outputDirectory,
$"{++responseFileNumber:000}-{stage}-attempt-{attempt:000}-error.txt",
exception, cancellationToken);
if (attempt >= maximumAttempts || !IsTransient(exception) ||
(retryDeadline.HasValue && DateTimeOffset.UtcNow >= retryDeadline.Value))
throw;
await Task.Delay(pollingInterval, cancellationToken);
continue;
}

if (saveJson)
await SharedResponseHelper.SaveAsync(outputDirectory,
$"{++responseFileNumber:000}-{stage}.json", response, cancellationToken);
return response;
}
}

static bool IsTransient(Exception exception) => exception is ParallelModelApiException apiException
? (int)apiException.StatusCode is 404 or 408 or 409 or 429 or >= 500
: exception is System.Net.Http.HttpRequestException or TimeoutException or TaskCanceledException;
}

private static ParallelModelModelSelectionOutputModel CreateOutput(string algorithm) => new()
{
Name = $"model-selection-{algorithm}.zip",
Description = $"Integration test for {algorithm}",
RecordType = "Generic",
AccessTier = "Hot",
Tags = new List<string> { "model-selection", "integration-tests", algorithm }
};

private static async Task<ParallelModelModelSelectionSendResponseModel> SendSelectionAsync(
string name, ParallelModelClient client, Guid modelId, DatasetFixture dataset,
string computeSize, string encryptionKey, CancellationToken cancellationToken,
string outputDirectory, string requestFileName)
{
// All branch expressions preserve each algorithm's concrete generic type.
// Do NOT send a marker-interface-typed request: it can serialize as {}.
return name switch
{
"CheckCv" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new CheckCvJobSendRequestModel
{
Input = new CheckCvJobSendRequestModel.CheckCvInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "check_cv",
AlgorithmParams = new CheckCvJobSendRequestModel.CheckCvAlgorithmParamsModel
{
Cv = 3,
Classifier = dataset.Profile.IsClassification
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("check_cv"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"CrossValPredict" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new CrossValPredictJobSendRequestModel
{
Input = new CrossValPredictJobSendRequestModel.CrossValPredictInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "cross_val_predict",
AlgorithmParams = new CrossValPredictJobSendRequestModel.CrossValPredictAlgorithmParamsModel
{
Estimator = new CrossValPredictJobSendRequestModel.CrossValPredictAlgorithmParamsEstimatorModel
{
Type = (dataset.Profile.IsRegression ? "Ridge" : "LogisticRegression"),
Params = new CrossValPredictJobSendRequestModel.CrossValPredictAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
Method = "predict"
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("cross_val_predict"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"CrossValScore" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new CrossValScoreJobSendRequestModel
{
Input = new CrossValScoreJobSendRequestModel.CrossValScoreInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "cross_val_score",
AlgorithmParams = new CrossValScoreJobSendRequestModel.CrossValScoreAlgorithmParamsModel
{
Estimator = new CrossValScoreJobSendRequestModel.CrossValScoreAlgorithmParamsEstimatorModel
{
Type = (dataset.Profile.IsRegression ? "Ridge" : "LogisticRegression"),
Params = new CrossValScoreJobSendRequestModel.CrossValScoreAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("cross_val_score"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"CrossValidate" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new CrossValidateJobSendRequestModel
{
Input = new CrossValidateJobSendRequestModel.CrossValidateInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "cross_validate",
AlgorithmParams = new CrossValidateJobSendRequestModel.CrossValidateAlgorithmParamsModel
{
Estimator = new CrossValidateJobSendRequestModel.CrossValidateAlgorithmParamsEstimatorModel
{
Type = (dataset.Profile.IsRegression ? "Ridge" : "LogisticRegression"),
Params = new CrossValidateJobSendRequestModel.CrossValidateAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("cross_validate"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"FixedThresholdClassifier" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new FixedThresholdClassifierJobSendRequestModel
{
Input = new FixedThresholdClassifierJobSendRequestModel.FixedThresholdClassifierInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "FixedThresholdClassifier",
AlgorithmParams = new FixedThresholdClassifierJobSendRequestModel.FixedThresholdClassifierAlgorithmParamsModel
{
Estimator = new FixedThresholdClassifierJobSendRequestModel.FixedThresholdClassifierAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new FixedThresholdClassifierJobSendRequestModel.FixedThresholdClassifierAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
Threshold = 0.5,
ResponseMethod = "predict_proba"
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("FixedThresholdClassifier"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"GridSearchCV" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new GridSearchCVJobSendRequestModel
{
Input = new GridSearchCVJobSendRequestModel.GridSearchCVInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "GridSearchCV",
AlgorithmParams = new GridSearchCVJobSendRequestModel.GridSearchCVAlgorithmParamsModel
{
Estimator = new GridSearchCVJobSendRequestModel.GridSearchCVAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new GridSearchCVJobSendRequestModel.GridSearchCVAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
ParamGrid = new GridSearchCVJobSendRequestModel.GridSearchCVAlgorithmParamsParamGridModel
{
C = new List<double> { 0.1, 1.0, 10.0 }
}
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("GridSearchCV"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"HalvingGridSearchCV" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new HalvingGridSearchCVJobSendRequestModel
{
Input = new HalvingGridSearchCVJobSendRequestModel.HalvingGridSearchCVInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "HalvingGridSearchCV",
AlgorithmParams = new HalvingGridSearchCVJobSendRequestModel.HalvingGridSearchCVAlgorithmParamsModel
{
Estimator = new HalvingGridSearchCVJobSendRequestModel.HalvingGridSearchCVAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new HalvingGridSearchCVJobSendRequestModel.HalvingGridSearchCVAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
ParamGrid = new HalvingGridSearchCVJobSendRequestModel.HalvingGridSearchCVAlgorithmParamsParamGridModel
{
C = new List<double> { 0.1, 1.0, 10.0 }
}
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("HalvingGridSearchCV"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"HalvingRandomSearchCV" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new HalvingRandomSearchCVJobSendRequestModel
{
Input = new HalvingRandomSearchCVJobSendRequestModel.HalvingRandomSearchCVInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "HalvingRandomSearchCV",
AlgorithmParams = new HalvingRandomSearchCVJobSendRequestModel.HalvingRandomSearchCVAlgorithmParamsModel
{
Estimator = new HalvingRandomSearchCVJobSendRequestModel.HalvingRandomSearchCVAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new HalvingRandomSearchCVJobSendRequestModel.HalvingRandomSearchCVAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
ParamDistributions = new HalvingRandomSearchCVJobSendRequestModel.HalvingRandomSearchCVAlgorithmParamsParamDistributionsModel
{
C = new List<double> { 0.1, 1.0, 10.0 }
},
NIter = 2,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("HalvingRandomSearchCV"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"KFold" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new KFoldJobSendRequestModel
{
Input = new KFoldJobSendRequestModel.KFoldInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "KFold",
AlgorithmParams = new KFoldJobSendRequestModel.KFoldAlgorithmParamsModel
{
NSplits = 3,
Shuffle = true,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("KFold"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"LearningCurveDisplay" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new LearningCurveDisplayJobSendRequestModel
{
Input = new LearningCurveDisplayJobSendRequestModel.LearningCurveDisplayInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "LearningCurveDisplay",
AlgorithmParams = new LearningCurveDisplayJobSendRequestModel.LearningCurveDisplayAlgorithmParamsModel
{
Estimator = new LearningCurveDisplayJobSendRequestModel.LearningCurveDisplayAlgorithmParamsEstimatorModel
{
Type = (dataset.Profile.IsRegression ? "Ridge" : "LogisticRegression"),
Params = new LearningCurveDisplayJobSendRequestModel.LearningCurveDisplayAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
TrainSizes = new List<double> { 0.5, 0.75, 1.0 },
Shuffle = true,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("LearningCurveDisplay"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"LearningCurve" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new LearningCurveJobSendRequestModel
{
Input = new LearningCurveJobSendRequestModel.LearningCurveInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "learning_curve",
AlgorithmParams = new LearningCurveJobSendRequestModel.LearningCurveAlgorithmParamsModel
{
Estimator = new LearningCurveJobSendRequestModel.LearningCurveAlgorithmParamsEstimatorModel
{
Type = (dataset.Profile.IsRegression ? "Ridge" : "LogisticRegression"),
Params = new LearningCurveJobSendRequestModel.LearningCurveAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
TrainSizes = new List<double> { 0.5, 0.75, 1.0 },
Shuffle = true,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("learning_curve"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"LeaveOneOut" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new LeaveOneOutJobSendRequestModel
{
Input = new LeaveOneOutJobSendRequestModel.LeaveOneOutInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "LeaveOneOut",
AlgorithmParams = new LeaveOneOutJobSendRequestModel.LeaveOneOutAlgorithmParamsModel
{

},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("LeaveOneOut"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"LeavePOut" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new LeavePOutJobSendRequestModel
{
Input = new LeavePOutJobSendRequestModel.LeavePOutInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "LeavePOut",
AlgorithmParams = new LeavePOutJobSendRequestModel.LeavePOutAlgorithmParamsModel
{
P = 2
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("LeavePOut"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"ParameterGrid" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new ParameterGridJobSendRequestModel
{
Input = new ParameterGridJobSendRequestModel.ParameterGridInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "ParameterGrid",
AlgorithmParams = new ParameterGridJobSendRequestModel.ParameterGridAlgorithmParamsModel
{
ParamGrid = new ParameterGridJobSendRequestModel.ParameterGridAlgorithmParamsParamGridModel
{
C = new List<double> { 0.1, 1.0, 10.0 }
}
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("ParameterGrid"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"ParameterSampler" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new ParameterSamplerJobSendRequestModel
{
Input = new ParameterSamplerJobSendRequestModel.ParameterSamplerInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "ParameterSampler",
AlgorithmParams = new ParameterSamplerJobSendRequestModel.ParameterSamplerAlgorithmParamsModel
{
ParamDistributions = new ParameterSamplerJobSendRequestModel.ParameterSamplerAlgorithmParamsParamDistributionsModel
{
C = new List<double> { 0.1, 1.0, 10.0 }
},
NIter = 2,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("ParameterSampler"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"PermutationTestScore" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new PermutationTestScoreJobSendRequestModel
{
Input = new PermutationTestScoreJobSendRequestModel.PermutationTestScoreInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "permutation_test_score",
AlgorithmParams = new PermutationTestScoreJobSendRequestModel.PermutationTestScoreAlgorithmParamsModel
{
Estimator = new PermutationTestScoreJobSendRequestModel.PermutationTestScoreAlgorithmParamsEstimatorModel
{
Type = (dataset.Profile.IsRegression ? "Ridge" : "LogisticRegression"),
Params = new PermutationTestScoreJobSendRequestModel.PermutationTestScoreAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
NPermutations = 5,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("permutation_test_score"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"RandomizedSearchCV" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new RandomizedSearchCVJobSendRequestModel
{
Input = new RandomizedSearchCVJobSendRequestModel.RandomizedSearchCVInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "RandomizedSearchCV",
AlgorithmParams = new RandomizedSearchCVJobSendRequestModel.RandomizedSearchCVAlgorithmParamsModel
{
Estimator = new RandomizedSearchCVJobSendRequestModel.RandomizedSearchCVAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new RandomizedSearchCVJobSendRequestModel.RandomizedSearchCVAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
ParamDistributions = new RandomizedSearchCVJobSendRequestModel.RandomizedSearchCVAlgorithmParamsParamDistributionsModel
{
C = new List<double> { 0.1, 1.0, 10.0 }
},
NIter = 2,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("RandomizedSearchCV"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"RepeatedKFold" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new RepeatedKFoldJobSendRequestModel
{
Input = new RepeatedKFoldJobSendRequestModel.RepeatedKFoldInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "RepeatedKFold",
AlgorithmParams = new RepeatedKFoldJobSendRequestModel.RepeatedKFoldAlgorithmParamsModel
{
NSplits = 3,
NRepeats = 2,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("RepeatedKFold"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"RepeatedStratifiedKFold" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new RepeatedStratifiedKFoldJobSendRequestModel
{
Input = new RepeatedStratifiedKFoldJobSendRequestModel.RepeatedStratifiedKFoldInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "RepeatedStratifiedKFold",
AlgorithmParams = new RepeatedStratifiedKFoldJobSendRequestModel.RepeatedStratifiedKFoldAlgorithmParamsModel
{
NSplits = 3,
NRepeats = 2,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("RepeatedStratifiedKFold"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"ShuffleSplit" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new ShuffleSplitJobSendRequestModel
{
Input = new ShuffleSplitJobSendRequestModel.ShuffleSplitInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "ShuffleSplit",
AlgorithmParams = new ShuffleSplitJobSendRequestModel.ShuffleSplitAlgorithmParamsModel
{
NSplits = 3,
TestSize = 0.25,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("ShuffleSplit"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"StratifiedKFold" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new StratifiedKFoldJobSendRequestModel
{
Input = new StratifiedKFoldJobSendRequestModel.StratifiedKFoldInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "StratifiedKFold",
AlgorithmParams = new StratifiedKFoldJobSendRequestModel.StratifiedKFoldAlgorithmParamsModel
{
NSplits = 3,
Shuffle = true,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("StratifiedKFold"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"StratifiedShuffleSplit" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new StratifiedShuffleSplitJobSendRequestModel
{
Input = new StratifiedShuffleSplitJobSendRequestModel.StratifiedShuffleSplitInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "StratifiedShuffleSplit",
AlgorithmParams = new StratifiedShuffleSplitJobSendRequestModel.StratifiedShuffleSplitAlgorithmParamsModel
{
NSplits = 3,
TestSize = 0.25,
RandomState = 42
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("StratifiedShuffleSplit"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"TimeSeriesSplit" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new TimeSeriesSplitJobSendRequestModel
{
Input = new TimeSeriesSplitJobSendRequestModel.TimeSeriesSplitInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "TimeSeriesSplit",
AlgorithmParams = new TimeSeriesSplitJobSendRequestModel.TimeSeriesSplitAlgorithmParamsModel
{
NSplits = 3
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("TimeSeriesSplit"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"TrainTestSplit" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new TrainTestSplitJobSendRequestModel
{
Input = new TrainTestSplitJobSendRequestModel.TrainTestSplitInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "train_test_split",
AlgorithmParams = new TrainTestSplitJobSendRequestModel.TrainTestSplitAlgorithmParamsModel
{
TestSize = 0.25,
RandomState = 42,
Shuffle = true,
Stratify = dataset.Profile.IsClassification
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = new TrainTestSplitJobSendRequestModel.TrainTestSplitInputEvaluationModel
{
TestSize = 0.25,
RandomState = 42,
Shuffle = true,
Stratify = dataset.Profile.IsClassification
}
},
Output = CreateOutput("train_test_split"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"TunedThresholdClassifierCV" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new TunedThresholdClassifierCVJobSendRequestModel
{
Input = new TunedThresholdClassifierCVJobSendRequestModel.TunedThresholdClassifierCVInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "TunedThresholdClassifierCV",
AlgorithmParams = new TunedThresholdClassifierCVJobSendRequestModel.TunedThresholdClassifierCVAlgorithmParamsModel
{
Estimator = new TunedThresholdClassifierCVJobSendRequestModel.TunedThresholdClassifierCVAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new TunedThresholdClassifierCVJobSendRequestModel.TunedThresholdClassifierCVAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
Thresholds = 10,
StoreCvResults = false,
ResponseMethod = "predict_proba"
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("TunedThresholdClassifierCV"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"ValidationCurveDisplay" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new ValidationCurveDisplayJobSendRequestModel
{
Input = new ValidationCurveDisplayJobSendRequestModel.ValidationCurveDisplayInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "ValidationCurveDisplay",
AlgorithmParams = new ValidationCurveDisplayJobSendRequestModel.ValidationCurveDisplayAlgorithmParamsModel
{
Estimator = new ValidationCurveDisplayJobSendRequestModel.ValidationCurveDisplayAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new ValidationCurveDisplayJobSendRequestModel.ValidationCurveDisplayAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
ParamName = "C",
ParamRange = new List<double> { 0.1, 1.0, 10.0 }
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("ValidationCurveDisplay"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
"ValidationCurve" => await SendTypedAsync(client, outputDirectory, requestFileName,
modelId,
new ValidationCurveJobSendRequestModel
{
Input = new ValidationCurveJobSendRequestModel.ValidationCurveInputModel
{
InputBlobId = dataset.BlobId,
FeatureColumns = dataset.FeatureColumns.ToList(),
FileFormat = dataset.FileFormat,
AlgorithmType = "validation_curve",
AlgorithmParams = new ValidationCurveJobSendRequestModel.ValidationCurveAlgorithmParamsModel
{
Estimator = new ValidationCurveJobSendRequestModel.ValidationCurveAlgorithmParamsEstimatorModel
{
Type = "LogisticRegression",
Params = new ValidationCurveJobSendRequestModel.ValidationCurveAlgorithmParamsEstimatorModelParamsModel
{
MaxIter = 300
}
},
Cv = 3,
NJobs = 1,
ParamName = "C",
ParamRange = new List<double> { 0.1, 1.0, 10.0 }
},
TargetColumn = dataset.TargetColumn!,
GenerateGraphs = false,
Evaluation = null
},
Output = CreateOutput("validation_curve"),
RequestTimeoutSeconds = 300
},
computeSize, encryptionKey, encryptionKey, ApiTimeout, cancellationToken),
_ => throw new ArgumentOutOfRangeException(nameof(name), name, "Unsupported ModelSelection test")
};
}

private static async Task<ParallelModelModelSelectionSendResponseModel> SendTypedAsync<TRequest>(
ParallelModelClient client, string outputDirectory, string requestFileName, Guid modelId,
TRequest request, string size, string inputKey, string outputKey,
TimeSpan timeout, CancellationToken token)
where TRequest : class, IParallelModelModelSelectionSendRequest
{
await SharedResponseHelper.SaveAsync(outputDirectory, requestFileName, request, token);
return await client.ModelSelectionClient.SendAsync(
modelId, request, size, inputKey, outputKey, timeout, token);
}
}