Skip to main content

Feature Selection

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

50 recorded job or prediction directories matched by module and scenario path. 44 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
FeatureSelectionClientDownloadBytesAsync, ExtractAsync, LogAsync, ResultAsync, SendAsync, StatusAsync
PreprocessingClientDownloadBytesAsync

Recorded operation examples​

OperationRecorded jobsResult recorded
GenericUnivariateSelect44
RFE32
RFECV32
SelectFdr44
SelectFpr44
SelectFromModel43
SelectFwe44
SelectKBest44
SelectPercentile32
SequentialFeatureSelector44
VarianceThreshold43
f_classif22
f_regression22
mutual_info_classif10
mutual_info_regression22
r_regression22

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.FeatureSelection.Run"

Full C# source​

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

Run(string datasetName, string selectionName, string impute, string preprocessing, string name)
using ParallelModel.Sdk.Authentication;
using ParallelModel.Sdk.Exceptions;
using ParallelModel.Sdk.ML.FeatureSelection.Models;
using ParallelModel.Sdk.ML.FeatureSelection.Models.Requests;
using ParallelModel.Sdk.UnitTests.Attributes;
using ParallelModel.Sdk.UnitTests.Cache;
using ParallelModel.Sdk.UnitTests.Helpers;
using static ParallelModel.Sdk.UnitTests.Helpers.MLFeatureSelectionHelper;

namespace ParallelModel.Sdk.UnitTests
{
[Collection("FeatureSelection")]
public sealed class FeatureSelection
{
private const string FileFormat = "csv";
private static readonly TimeSpan ApiTimeout = TimeSpan.FromSeconds(300);
private static readonly TimeSpan PollInterval = TimeSpan.FromSeconds(20);
private static readonly SharedSendThrottle SendThrottle = new(TimeSpan.FromSeconds(12));
private static readonly string[] Algorithms =
[
"VarianceThreshold", "chi2", "f_classif", "mutual_info_classif", "f_regression", "r_regression", "mutual_info_regression",
"GenericUnivariateSelect", "SelectKBest", "SelectPercentile", "SelectFpr", "SelectFdr", "SelectFwe", "SelectFromModel", "RFE", "RFECV", "SequentialFeatureSelector"
];

public static TheoryData<string, string, string, string, string> FeatureSelectionRequests =>
PreprocessingAttribute.GetRequests(typeof(FeatureSelection), nameof(Run), AlgorithmsFor);

private static string[] AlgorithmsFor(string dataset, string preprocessing) =>
Algorithms.Where(algorithm => algorithm switch
{
"chi2" => dataset == "LoadBreastCancer" && preprocessing != "StandardScaler",
"f_classif" or "mutual_info_classif" => dataset == "LoadBreastCancer",
"f_regression" or "r_regression" or "mutual_info_regression" => dataset == "LoadDiabetes",
_ => true
}).ToArray();

[Theory]
[MemberData(nameof(FeatureSelectionRequests))]
[Preprocessing("LoadDiabetes", "TrainTestSplit", "SimpleImputer", "StandardScaler")]
[Preprocessing("LoadBreastCancer", "TrainTestSplit", "SimpleImputer", "StandardScaler")]
public async Task Run(string datasetName, string selectionName, string impute, string preprocessing, string name)
{
// Step 1. Initialise client and output paths.
SharedEnvironmentHelper.LoadEnvIfAvailable();
CancellationToken token = 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");
ParallelModelClient client = new(new DefaultParallelModelAuthenticationOptions
{
Region = SharedEnvironmentHelper.Required("PARALLELMODEL_REGION"),
ClientId = SharedEnvironmentHelper.Required("PARALLELMODEL_CLIENT_ID"),
ClientSecret = SharedEnvironmentHelper.Required("PARALLELMODEL_CLIENT_SECRET"),
Timeout = ApiTimeout,
AutoRefreshToken = true,
RefreshBeforeExpiry = TimeSpan.FromMinutes(2),
RetryOnUnauthorized = true,
MaxRetries = 3
});
string runId = Guid.NewGuid().ToString("N");
string groupDirectory = Path.Combine(SharedEnvironmentHelper.OutputDirectory, "featureselection",
$"{datasetName}-{selectionName}-{impute}-{preprocessing}", name, runId);
string cacheDirectory = SharedEnvironmentHelper.CacheDirectory;

// Step 2. Resolve both transformed tables before submitting either job.
IReadOnlyList<TransformedTable> tables = await LoadTablesAsync(cacheDirectory, datasetName,
selectionName, impute, preprocessing, token);
List<PartitionInput> inputs = new();
bool isRegression = MLDatasetHelper.ResolveDatasetProfile(datasetName).IsRegression;
foreach (TransformedTable table in tables)
{
byte[] source = await client.PreprocessingClient.DownloadBytesAsync(modelId: modelId, jobId: table.JobId,
blobId: table.BlobId, computeSize: computeSize, inputEncryptionKey: encryptionKey,
timeout: ApiTimeout, cancellationToken: token);
inputs.Add(new(table.Partition, ReadHeader(source, table, isRegression)));
}
if (!inputs[0].Dataset.FeatureColumns.SequenceEqual(inputs[1].Dataset.FeatureColumns, StringComparer.Ordinal))
throw new InvalidOperationException($"Train/test feature columns differ for {datasetName}/{preprocessing}.");
List<FeatureSelectionCacheEntry> entries = new();
foreach (PartitionInput partitionInput in inputs)
{
string directory = Path.Combine(groupDirectory, partitionInput.Partition);
int sequence = 0;
string Next(string stage) => $"{++sequence:000}-{stage}";
async Task<T> RequestAsync<T>(string stage, Func<Task<T>> call, bool retry = true, bool saveJson = true)
{
DateTimeOffset deadline = DateTimeOffset.UtcNow.AddMinutes(2);
while (true)
{
T response;
try
{
response = await call();
}
catch (Exception exception) when (!token.IsCancellationRequested)
{
await SharedResponseHelper.SaveExceptionAsync(directory, Next(stage + "-error.txt"), exception, token);
bool transient = exception switch
{
ParallelModelApiException error => (int)error.StatusCode is 408 or 409 or 429 or >= 500 ||
((int)error.StatusCode == 404 && error.Detail?.Contains("job failed", StringComparison.OrdinalIgnoreCase) != true),
HttpRequestException or TimeoutException or TaskCanceledException => true,
_ => false
};
if (!retry || !transient || DateTimeOffset.UtcNow + PollInterval >= deadline)
throw;
await Task.Delay(PollInterval, token);
continue;
}
if (saveJson)
await SharedResponseHelper.SaveAsync(directory, Next(stage + ".json"), response, token);
return response;
}
}

// Step 3. Send one concrete SDK request for this partition.
await SendThrottle.WaitForSendSlotAsync(token);
ParallelModelFeatureSelectionSendResponseModel sent = await RequestAsync("send", () =>
SendFeatureSelectionAsync(name, partitionInput.Dataset, client, modelId, computeSize, encryptionKey,
Path.Combine(directory, Next("request.json")), token), retry: false);
if (sent.JobId == Guid.Empty)
throw new InvalidOperationException("Feature selection returned an empty job ID.");

async Task GetLogsAsync() =>
await RequestAsync("logs", () => client.FeatureSelectionClient.LogAsync(modelId: modelId,
jobId: sent.JobId, computeSize: computeSize, timeout: TimeSpan.FromSeconds(10),
cancellationToken: token), retry: false);

// Step 4. Poll until success or terminal failure.
DateTimeOffset deadline = DateTimeOffset.UtcNow.AddMinutes(6);
while (true)
{
ParallelModelFeatureSelectionStatusResponseModel status = await RequestAsync("status", () =>
client.FeatureSelectionClient.StatusAsync(modelId: modelId, jobId: sent.JobId,
computeSize: computeSize, timeout: ApiTimeout, cancellationToken: token));
string? failure = status switch
{
ParallelModelFeatureSelectionStatusResponseModel.Error error => $"Status error: {error.Detail}",
ParallelModelFeatureSelectionStatusResponseModel.Success response when response.Status?.ToLowerInvariant() is
"error" or "failed" or "cancelled" or "canceled" or "deadletter" or "dead-lettered"
or "deadlettered" or "dead_letter" or "dead-letter" =>
$"{response.Status}: {response.DeadLetterReason} {response.DeadLetterErrorDescription}",
ParallelModelFeatureSelectionStatusResponseModel.Success => null,
_ => "Unknown status response type."
};
if (failure is not null)
{
try
{
await GetLogsAsync();
}
catch (Exception) when (!token.IsCancellationRequested) { /* RequestAsync saved the log error. */ }
throw new InvalidOperationException($"{name}/{partitionInput.Partition} job {sent.JobId}: {failure}");
}
if (status is ParallelModelFeatureSelectionStatusResponseModel.Success success &&
success.Status?.ToLowerInvariant() is "success" or "succeeded" or "completed")
break;
if (DateTimeOffset.UtcNow >= deadline)
throw new TimeoutException($"Timed out waiting for feature selection job {sent.JobId}.");
await Task.Delay(PollInterval, token);
}

// Step 5. Retrieve logs once.
try
{
await GetLogsAsync();
}
catch (Exception exception) when (!token.IsCancellationRequested && (exception switch
{
ParallelModelApiException error => (int)error.StatusCode is 408 or 409 or 429 or >= 500 ||
((int)error.StatusCode == 404 && error.Detail?.Contains("job failed", StringComparison.OrdinalIgnoreCase) != true),
HttpRequestException or TimeoutException or TaskCanceledException => true,
_ => false
}))
{ /* Delayed logs are optional after a successful job. */
}

// Step 6. Retrieve the result.
ParallelModelFeatureSelectionResultResponseModel result = await RequestAsync("result", () =>
client.FeatureSelectionClient.ResultAsync(modelId: modelId, jobId: sent.JobId, computeSize: computeSize,
inputEncryptionKey: encryptionKey, timeout: ApiTimeout, cancellationToken: token));

// Step 7. Extract and download every declared artifact.
IReadOnlyList<string> paths = GetArtifactPaths(result);
if (paths.Count == 0)
throw new InvalidOperationException($"No artifacts declared for job {sent.JobId}.");
int artifactIndex = 0;
foreach (string path in paths)
{
ParallelModelFeatureSelectionExtractResponseModel extracted = await RequestAsync("extract", () =>
client.FeatureSelectionClient.ExtractAsync(modelId: modelId, jobId: sent.JobId, fileName: path,
computeSize: computeSize, inputEncryptionKey: encryptionKey, outputEncryptionKey: encryptionKey,
timeout: ApiTimeout, cancellationToken: token));
byte[] bytes = await RequestAsync("download", () =>
client.FeatureSelectionClient.DownloadBytesAsync(modelId: modelId, jobId: sent.JobId,
blobId: extracted.UploadedBlobId, computeSize: computeSize, inputEncryptionKey: encryptionKey,
timeout: ApiTimeout, cancellationToken: token), saveJson: false);
await SharedArtifactHelper.SaveAsync(directory, ++artifactIndex, path, bytes, token);
entries.Add(new(datasetName, selectionName, impute, preprocessing, name, partitionInput.Partition,
extracted.UploadedBlobId, path, partitionInput.Dataset.InputBlobId, sent.JobId, runId));
}
}

// Step 8. Publish both partitions together, preserving other cases.
await SharedCacheHelper.UpdateAsync<List<FeatureSelectionCacheEntry>>(cacheDirectory,
FeatureSelectionCacheEntry.FileName, current =>
{
current ??= new();
current.RemoveAll(entry => entry.Matches(datasetName, selectionName, impute, preprocessing, name));
current.AddRange(entries);
return current.OrderBy(entry => entry.Dataset, StringComparer.Ordinal)
.ThenBy(entry => entry.ModelSelection, StringComparer.Ordinal).ThenBy(entry => entry.Impute, StringComparer.Ordinal)
.ThenBy(entry => entry.Preprocessing, StringComparer.Ordinal).ThenBy(entry => entry.Algorithm, StringComparer.Ordinal)
.ThenBy(entry => entry.Partition, StringComparer.Ordinal).ThenBy(entry => entry.ArtifactPath, StringComparer.Ordinal).ToList();
}, token);
}

private static Task<ParallelModelFeatureSelectionSendResponseModel> SendFeatureSelectionAsync(
string algorithm, PreparedDataset dataset, ParallelModelClient client,
Guid modelId, string computeSize, string encryptionKey,
string requestLogName, CancellationToken token)
{
bool regression = dataset.IsRegression;
string scoreFunction = regression ? "f_regression" : "f_classif";
ParallelModelFeatureSelectionOutputModel parallelModelFeatureSelectionOutputModel = new()
{
Name = $"feature-selection-{algorithm}",
Description = $"scikit-learn {algorithm} integration-test output",
RecordType = "Generic",
AccessTier = "Hot",
Tags = ["feature-selection", algorithm.ToLowerInvariant(), "integration-test"]
};
switch (algorithm)
{
case "VarianceThreshold":
{
VarianceThresholdJobSendRequestModel varianceThresholdJobSendRequestModel = new VarianceThresholdJobSendRequestModel
{
Input = new VarianceThresholdJobSendRequestModel.VarianceThresholdInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "VarianceThreshold",
AlgorithmParams = new VarianceThresholdJobSendRequestModel.VarianceThresholdAlgorithmParamsModel
{
Threshold = 0.01,
},
Evaluation = new VarianceThresholdJobSendRequestModel.VarianceThresholdEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = null
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, varianceThresholdJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "chi2":
{
Chi2JobSendRequestModel chi2JobSendRequestModel = new Chi2JobSendRequestModel
{
Input = new Chi2JobSendRequestModel.Chi2InputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "chi2",
AlgorithmParams = new Chi2JobSendRequestModel.Chi2AlgorithmParamsModel
{
},
Evaluation = new Chi2JobSendRequestModel.Chi2EvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, chi2JobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "f_classif":
{
FClassifJobSendRequestModel fClassifJobSendRequestModel = new FClassifJobSendRequestModel
{
Input = new FClassifJobSendRequestModel.FClassifInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "f_classif",
AlgorithmParams = new FClassifJobSendRequestModel.FClassifAlgorithmParamsModel
{
},
Evaluation = new FClassifJobSendRequestModel.FClassifEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, fClassifJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "f_regression":
{
FRegressionJobSendRequestModel fRegressionJobSendRequestModel = new FRegressionJobSendRequestModel
{
Input = new FRegressionJobSendRequestModel.FRegressionInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "f_regression",
AlgorithmParams = new FRegressionJobSendRequestModel.FRegressionAlgorithmParamsModel
{
Center = true,
ForceFinite = true,
},
Evaluation = new FRegressionJobSendRequestModel.FRegressionEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, fRegressionJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "r_regression":
{
RRegressionJobSendRequestModel rRegressionJobSendRequestModel = new RRegressionJobSendRequestModel
{
Input = new RRegressionJobSendRequestModel.RRegressionInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "r_regression",
AlgorithmParams = new RRegressionJobSendRequestModel.RRegressionAlgorithmParamsModel
{
Center = true,
ForceFinite = true,
},
Evaluation = new RRegressionJobSendRequestModel.RRegressionEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, rRegressionJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "mutual_info_classif":
{
MutualInfoClassifJobSendRequestModel mutualInfoClassifJobSendRequestModel = new MutualInfoClassifJobSendRequestModel
{
Input = new MutualInfoClassifJobSendRequestModel.MutualInfoClassifInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "mutual_info_classif",
AlgorithmParams = new MutualInfoClassifJobSendRequestModel.MutualInfoClassifAlgorithmParamsModel
{
NNeighbors = 3,
RandomState = 42,
},
Evaluation = new MutualInfoClassifJobSendRequestModel.MutualInfoClassifEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, mutualInfoClassifJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "mutual_info_regression":
{
MutualInfoRegressionJobSendRequestModel mutualInfoRegressionJobSendRequestModel = new MutualInfoRegressionJobSendRequestModel
{
Input = new MutualInfoRegressionJobSendRequestModel.MutualInfoRegressionInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "mutual_info_regression",
AlgorithmParams = new MutualInfoRegressionJobSendRequestModel.MutualInfoRegressionAlgorithmParamsModel
{
NNeighbors = 3,
RandomState = 42,
},
Evaluation = new MutualInfoRegressionJobSendRequestModel.MutualInfoRegressionEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, mutualInfoRegressionJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "GenericUnivariateSelect":
{
GenericUnivariateSelectJobSendRequestModel genericUnivariateSelectJobSendRequestModel = new GenericUnivariateSelectJobSendRequestModel
{
Input = new GenericUnivariateSelectJobSendRequestModel.GenericUnivariateSelectInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "GenericUnivariateSelect",
AlgorithmParams = new GenericUnivariateSelectJobSendRequestModel.GenericUnivariateSelectAlgorithmParamsModel
{
ScoreFunc = scoreFunction,
Mode = "k_best",
Param = 3,
},
Evaluation = new GenericUnivariateSelectJobSendRequestModel.GenericUnivariateSelectEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, genericUnivariateSelectJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SelectKBest":
{
SelectKBestJobSendRequestModel selectKBestJobSendRequestModel = new SelectKBestJobSendRequestModel
{
Input = new SelectKBestJobSendRequestModel.SelectKBestInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SelectKBest",
AlgorithmParams = new SelectKBestJobSendRequestModel.SelectKBestAlgorithmParamsModel
{
ScoreFunc = scoreFunction,
K = 3,
},
Evaluation = new SelectKBestJobSendRequestModel.SelectKBestEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, selectKBestJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SelectPercentile":
{
SelectPercentileJobSendRequestModel selectPercentileJobSendRequestModel = new SelectPercentileJobSendRequestModel
{
Input = new SelectPercentileJobSendRequestModel.SelectPercentileInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SelectPercentile",
AlgorithmParams = new SelectPercentileJobSendRequestModel.SelectPercentileAlgorithmParamsModel
{
ScoreFunc = scoreFunction,
Percentile = 50,
},
Evaluation = new SelectPercentileJobSendRequestModel.SelectPercentileEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, selectPercentileJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SelectFpr":
{
SelectFprJobSendRequestModel selectFprJobSendRequestModel = new SelectFprJobSendRequestModel
{
Input = new SelectFprJobSendRequestModel.SelectFprInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SelectFpr",
AlgorithmParams = new SelectFprJobSendRequestModel.SelectFprAlgorithmParamsModel
{
ScoreFunc = scoreFunction,
Alpha = 0.05,
},
Evaluation = new SelectFprJobSendRequestModel.SelectFprEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, selectFprJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SelectFdr":
{
SelectFdrJobSendRequestModel selectFdrJobSendRequestModel = new SelectFdrJobSendRequestModel
{
Input = new SelectFdrJobSendRequestModel.SelectFdrInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SelectFdr",
AlgorithmParams = new SelectFdrJobSendRequestModel.SelectFdrAlgorithmParamsModel
{
ScoreFunc = scoreFunction,
Alpha = 0.2,
},
Evaluation = new SelectFdrJobSendRequestModel.SelectFdrEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, selectFdrJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SelectFwe":
{
SelectFweJobSendRequestModel selectFweJobSendRequestModel = new SelectFweJobSendRequestModel
{
Input = new SelectFweJobSendRequestModel.SelectFweInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SelectFwe",
AlgorithmParams = new SelectFweJobSendRequestModel.SelectFweAlgorithmParamsModel
{
ScoreFunc = scoreFunction,
Alpha = 0.05,
},
Evaluation = new SelectFweJobSendRequestModel.SelectFweEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, selectFweJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SelectFromModel":
{
SelectFromModelJobSendRequestModel selectFromModelJobSendRequestModel = new SelectFromModelJobSendRequestModel
{
Input = new SelectFromModelJobSendRequestModel.SelectFromModelInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SelectFromModel",
AlgorithmParams = new SelectFromModelJobSendRequestModel.SelectFromModelAlgorithmParamsModel
{
Estimator = new SelectFromModelJobSendRequestModel.SelectFromModelEstimatorModel
{
Type = regression ? "RandomForestRegressor" : "RandomForestClassifier",
Params = new SelectFromModelJobSendRequestModel.SelectFromModelEstimatorParamsModel
{
NEstimators = 30,
RandomState = 42
}
},
Threshold = "mean",
},
Evaluation = new SelectFromModelJobSendRequestModel.SelectFromModelEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, selectFromModelJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "RFE":
{
RFEJobSendRequestModel rfeJobSendRequestModel = new RFEJobSendRequestModel
{
Input = new RFEJobSendRequestModel.RFEInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "RFE",
AlgorithmParams = new RFEJobSendRequestModel.RFEAlgorithmParamsModel
{
Estimator = new RFEJobSendRequestModel.RFEEstimatorModel
{
Type = regression ? "Ridge" : "LogisticRegression",
Params = new RFEJobSendRequestModel.RFEEstimatorParamsModel
{
MaxIter = 250,
RandomState = 42
}
},
NFeaturesToSelect = 3,
Step = 1,
},
Evaluation = new RFEJobSendRequestModel.RFEEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, rfeJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "RFECV":
{
RFECVJobSendRequestModel rfecvJobSendRequestModel = new RFECVJobSendRequestModel
{
Input = new RFECVJobSendRequestModel.RFECVInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "RFECV",
AlgorithmParams = new RFECVJobSendRequestModel.RFECVAlgorithmParamsModel
{
Estimator = new RFECVJobSendRequestModel.RFECVEstimatorModel
{
Type = regression ? "Ridge" : "LogisticRegression",
Params = new RFECVJobSendRequestModel.RFECVEstimatorParamsModel
{
MaxIter = 250,
RandomState = 42
}
},
Cv = 3,
Scoring = regression ? "r2" : "accuracy",
Step = 1,
MinFeaturesToSelect = 2,
},
Evaluation = new RFECVJobSendRequestModel.RFECVEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, rfecvJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
case "SequentialFeatureSelector":
{
SequentialFeatureSelectorJobSendRequestModel sequentialFeatureSelectorJobSendRequestModel = new SequentialFeatureSelectorJobSendRequestModel
{
Input = new SequentialFeatureSelectorJobSendRequestModel.SequentialFeatureSelectorInputModel
{
InputBlobId = dataset.InputBlobId,
FileFormat = FileFormat,
DataType = "numeric_table",
FeatureColumns = dataset.FeatureColumns.ToList(),
AlgorithmType = "SequentialFeatureSelector",
AlgorithmParams = new SequentialFeatureSelectorJobSendRequestModel.SequentialFeatureSelectorAlgorithmParamsModel
{
Estimator = new SequentialFeatureSelectorJobSendRequestModel.SequentialFeatureSelectorEstimatorModel
{
Type = regression ? "Ridge" : "LogisticRegression",
Params = new SequentialFeatureSelectorJobSendRequestModel.SequentialFeatureSelectorEstimatorParamsModel
{
MaxIter = 250,
RandomState = 42
}
},
NFeaturesToSelect = 3,
Cv = 3,
Direction = "forward",
},
Evaluation = new SequentialFeatureSelectorJobSendRequestModel.SequentialFeatureSelectorEvaluationModel
{
TestSize = 0.2,
RandomState = 42,
Shuffle = true,
Stratify = false
},
GenerateGraphs = false,
TargetColumn = dataset.TargetColumn
},
RequestTimeoutSeconds = 300,
Output = parallelModelFeatureSelectionOutputModel
};
return SendTypedAsync(client, modelId, sequentialFeatureSelectorJobSendRequestModel,
computeSize, encryptionKey, requestLogName, token);
}
default:
throw new ArgumentOutOfRangeException(nameof(algorithm), algorithm,
"Unsupported Feature Selection request type.");
}
}

private static async Task<ParallelModelFeatureSelectionSendResponseModel> SendTypedAsync<TRequest>(
ParallelModelClient client, Guid modelId, TRequest request,
string computeSize, string encryptionKey, string requestLogName,
CancellationToken token)
where TRequest : class, IParallelModelFeatureSelectionSendRequest
{
await SharedResponseHelper.SaveAsync(Path.GetDirectoryName(requestLogName)!,
Path.GetFileName(requestLogName), request, token);
return await client.FeatureSelectionClient.SendAsync(
modelId: modelId, request: request,
computeSize: computeSize, inputEncryptionKey: encryptionKey,
outputEncryptionKey: encryptionKey, timeout: ApiTimeout,
cancellationToken: token);
}

}
}