PcaCatalog.RandomizedPca Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Перегрузки
RandomizedPca(AnomalyDetectionCatalog+AnomalyDetectionTrainers, RandomizedPcaTrainer+Options) |
Создавайте RandomizedPcaTrainer с помощью дополнительных параметров, которые обучают модель приблизительного анализа основных компонентов (PCA) с помощью алгоритма распаковки случайных значений (SVD). |
RandomizedPca(AnomalyDetectionCatalog+AnomalyDetectionTrainers, String, String, Int32, Int32, Boolean, Nullable<Int32>) |
Создание RandomizedPcaTrainer, которое обучает модель приблизительного анализа основных компонентов (PCA) с помощью алгоритма распаковки случайных значений (SVD). |
RandomizedPca(AnomalyDetectionCatalog+AnomalyDetectionTrainers, RandomizedPcaTrainer+Options)
- Исходный код:
- PCACatalog.cs
- Исходный код:
- PCACatalog.cs
- Исходный код:
- PCACatalog.cs
Создавайте RandomizedPcaTrainer с помощью дополнительных параметров, которые обучают модель приблизительного анализа основных компонентов (PCA) с помощью алгоритма распаковки случайных значений (SVD).
public static Microsoft.ML.Trainers.RandomizedPcaTrainer RandomizedPca(this Microsoft.ML.AnomalyDetectionCatalog.AnomalyDetectionTrainers catalog, Microsoft.ML.Trainers.RandomizedPcaTrainer.Options options);
static member RandomizedPca : Microsoft.ML.AnomalyDetectionCatalog.AnomalyDetectionTrainers * Microsoft.ML.Trainers.RandomizedPcaTrainer.Options -> Microsoft.ML.Trainers.RandomizedPcaTrainer
<Extension()>
Public Function RandomizedPca (catalog As AnomalyDetectionCatalog.AnomalyDetectionTrainers, options As RandomizedPcaTrainer.Options) As RandomizedPcaTrainer
Параметры
Объект средства обучения каталога обнаружения аномалий.
- options
- RandomizedPcaTrainer.Options
Дополнительные параметры алгоритма.
Возвращаемое значение
Примеры
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;
namespace Samples.Dynamic.Trainers.AnomalyDetection
{
public static class RandomizedPcaSampleWithOptions
{
public static void Example()
{
// Create a new context for ML.NET operations. It can be used for
// exception tracking and logging, as a catalog of available operations
// and as the source of randomness. Setting the seed to a fixed number
// in this example to make outputs deterministic.
var mlContext = new MLContext(seed: 0);
// Training data.
var samples = new List<DataPoint>()
{
new DataPoint(){ Features = new float[3] {0, 2, 1} },
new DataPoint(){ Features = new float[3] {0, 2, 3} },
new DataPoint(){ Features = new float[3] {0, 2, 4} },
new DataPoint(){ Features = new float[3] {0, 2, 1} },
new DataPoint(){ Features = new float[3] {0, 2, 2} },
new DataPoint(){ Features = new float[3] {0, 2, 3} },
new DataPoint(){ Features = new float[3] {0, 2, 4} },
new DataPoint(){ Features = new float[3] {1, 0, 0} }
};
// Convert the List<DataPoint> to IDataView, a consumable format to
// ML.NET functions.
var data = mlContext.Data.LoadFromEnumerable(samples);
var options = new Microsoft.ML.Trainers.RandomizedPcaTrainer.Options()
{
FeatureColumnName = nameof(DataPoint.Features),
Rank = 1,
Seed = 10,
};
// Create an anomaly detector. Its underlying algorithm is randomized
// PCA.
var pipeline = mlContext.AnomalyDetection.Trainers.RandomizedPca(
options);
// Train the anomaly detector.
var model = pipeline.Fit(data);
// Apply the trained model on the training data.
var transformed = model.Transform(data);
// Read ML.NET predictions into IEnumerable<Result>.
var results = mlContext.Data.CreateEnumerable<Result>(transformed,
reuseRowObject: false).ToList();
// Let's go through all predictions.
for (int i = 0; i < samples.Count; ++i)
{
// The i-th example's prediction result.
var result = results[i];
// The i-th example's feature vector in text format.
var featuresInText = string.Join(',', samples[i].Features);
if (result.PredictedLabel)
// The i-th sample is predicted as an outlier.
Console.WriteLine("The {0}-th example with features [{1}] is" +
"an outlier with a score of being outlier {2}", i,
featuresInText, result.Score);
else
// The i-th sample is predicted as an inlier.
Console.WriteLine("The {0}-th example with features [{1}] is" +
"an inlier with a score of being outlier {2}",
i, featuresInText, result.Score);
}
// Lines printed out should be
// The 0 - th example with features[0, 2, 1] is an inlier with a score of being outlier 0.2264826
// The 1 - th example with features[0, 2, 3] is an inlier with a score of being outlier 0.1739471
// The 2 - th example with features[0, 2, 4] is an inlier with a score of being outlier 0.05711612
// The 3 - th example with features[0, 2, 1] is an inlier with a score of being outlier 0.2264826
// The 4 - th example with features[0, 2, 2] is an inlier with a score of being outlier 0.3868995
// The 5 - th example with features[0, 2, 3] is an inlier with a score of being outlier 0.1739471
// The 6 - th example with features[0, 2, 4] is an inlier with a score of being outlier 0.05711612
// The 7 - th example with features[1, 0, 0] is an outlier with a score of being outlier 0.6260795
}
// Example with 3 feature values. A training data set is a collection of
// such examples.
private class DataPoint
{
[VectorType(3)]
public float[] Features { get; set; }
}
// Class used to capture prediction of DataPoint.
private class Result
{
// Outlier gets true while inlier has false.
public bool PredictedLabel { get; set; }
// Inlier gets smaller score. Score is between 0 and 1.
public float Score { get; set; }
}
}
}
Комментарии
По умолчанию пороговое значение, используемое для определения метки точки данных на основе прогнозируемой оценки, равно 0,5. Оценки варьируются от 0 до 1. Точка данных с прогнозируемой оценкой выше 0,5 считается выбросом. Используется для ChangeModelThreshold<TModel>(AnomalyPredictionTransformer<TModel>, Single) изменения этого порогового значения.
Применяется к
RandomizedPca(AnomalyDetectionCatalog+AnomalyDetectionTrainers, String, String, Int32, Int32, Boolean, Nullable<Int32>)
- Исходный код:
- PCACatalog.cs
- Исходный код:
- PCACatalog.cs
- Исходный код:
- PCACatalog.cs
Создание RandomizedPcaTrainer, которое обучает модель приблизительного анализа основных компонентов (PCA) с помощью алгоритма распаковки случайных значений (SVD).
public static Microsoft.ML.Trainers.RandomizedPcaTrainer RandomizedPca(this Microsoft.ML.AnomalyDetectionCatalog.AnomalyDetectionTrainers catalog, string featureColumnName = "Features", string exampleWeightColumnName = default, int rank = 20, int oversampling = 20, bool ensureZeroMean = true, int? seed = default);
static member RandomizedPca : Microsoft.ML.AnomalyDetectionCatalog.AnomalyDetectionTrainers * string * string * int * int * bool * Nullable<int> -> Microsoft.ML.Trainers.RandomizedPcaTrainer
<Extension()>
Public Function RandomizedPca (catalog As AnomalyDetectionCatalog.AnomalyDetectionTrainers, Optional featureColumnName As String = "Features", Optional exampleWeightColumnName As String = Nothing, Optional rank As Integer = 20, Optional oversampling As Integer = 20, Optional ensureZeroMean As Boolean = true, Optional seed As Nullable(Of Integer) = Nothing) As RandomizedPcaTrainer
Параметры
Объект средства обучения каталога обнаружения аномалий.
- featureColumnName
- String
Имя столбца компонента. Данные столбца должны быть вектором известного Singleразмера .
- exampleWeightColumnName
- String
Имя примера столбца веса (необязательно). Чтобы использовать столбец веса, данные столбца должны иметь тип Single.
- rank
- Int32
Количество компонентов в PCA.
- oversampling
- Int32
Параметр oversampling для случайного обучения PCA.
- ensureZeroMean
- Boolean
Если этот параметр включен, то центрирование данных равно нулю среднего.
Возвращаемое значение
Примеры
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;
namespace Samples.Dynamic.Trainers.AnomalyDetection
{
public static class RandomizedPcaSample
{
public static void Example()
{
// Create a new context for ML.NET operations. It can be used for except
// ion tracking and logging, as a catalog of available operations and as
// the source of randomness. Setting the seed to a fixed number in this
// example to make outputs deterministic.
var mlContext = new MLContext(seed: 0);
// Training data.
var samples = new List<DataPoint>()
{
new DataPoint(){ Features = new float[3] {0, 2, 1} },
new DataPoint(){ Features = new float[3] {0, 2, 1} },
new DataPoint(){ Features = new float[3] {0, 2, 1} },
new DataPoint(){ Features = new float[3] {0, 1, 2} },
new DataPoint(){ Features = new float[3] {0, 2, 1} },
new DataPoint(){ Features = new float[3] {2, 0, 0} }
};
// Convert the List<DataPoint> to IDataView, a consumable format to
// ML.NET functions.
var data = mlContext.Data.LoadFromEnumerable(samples);
// Create an anomaly detector. Its underlying algorithm is randomized
// PCA.
var pipeline = mlContext.AnomalyDetection.Trainers.RandomizedPca(
featureColumnName: nameof(DataPoint.Features), rank: 1,
ensureZeroMean: false);
// Train the anomaly detector.
var model = pipeline.Fit(data);
// Apply the trained model on the training data.
var transformed = model.Transform(data);
// Read ML.NET predictions into IEnumerable<Result>.
var results = mlContext.Data.CreateEnumerable<Result>(transformed,
reuseRowObject: false).ToList();
// Let's go through all predictions.
for (int i = 0; i < samples.Count; ++i)
{
// The i-th example's prediction result.
var result = results[i];
// The i-th example's feature vector in text format.
var featuresInText = string.Join(',', samples[i].Features);
if (result.PredictedLabel)
// The i-th sample is predicted as an outlier.
Console.WriteLine("The {0}-th example with features [{1}] is " +
"an outlier with a score of being inlier {2}", i,
featuresInText, result.Score);
else
// The i-th sample is predicted as an inlier.
Console.WriteLine("The {0}-th example with features [{1}] is " +
"an inlier with a score of being inlier {2}", i,
featuresInText, result.Score);
}
// Lines printed out should be
// The 0 - th example with features[0, 2, 1] is an inlier with a score of being outlier 0.1101028
// The 1 - th example with features[0, 2, 1] is an inlier with a score of being outlier 0.1101028
// The 2 - th example with features[0, 2, 1] is an inlier with a score of being outlier 0.1101028
// The 3 - th example with features[0, 1, 2] is an outlier with a score of being outlier 0.5082728
// The 4 - th example with features[0, 2, 1] is an inlier with a score of being outlier 0.1101028
// The 5 - th example with features[2, 0, 0] is an outlier with a score of being outlier 1
}
// Example with 3 feature values. A training data set is a collection of
// such examples.
private class DataPoint
{
[VectorType(3)]
public float[] Features { get; set; }
}
// Class used to capture prediction of DataPoint.
private class Result
{
// Outlier gets true while inlier has false.
public bool PredictedLabel { get; set; }
// Inlier gets smaller score. Score is between 0 and 1.
public float Score { get; set; }
}
}
}
Комментарии
По умолчанию пороговое значение, используемое для определения метки точки данных на основе прогнозируемой оценки, равно 0,5. Оценки варьируются от 0 до 1. Точка данных с прогнозируемой оценкой выше 0,5 считается выбросом. Используется для ChangeModelThreshold<TModel>(AnomalyPredictionTransformer<TModel>, Single) изменения этого порогового значения.