DataOperationsCatalog.ShuffleRows Método
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Ordena las filas de input
.
public Microsoft.ML.IDataView ShuffleRows(Microsoft.ML.IDataView input, int? seed = default, int shufflePoolSize = 1000, bool shuffleSource = true);
member this.ShuffleRows : Microsoft.ML.IDataView * Nullable<int> * int * bool -> Microsoft.ML.IDataView
Public Function ShuffleRows (input As IDataView, Optional seed As Nullable(Of Integer) = Nothing, Optional shufflePoolSize As Integer = 1000, Optional shuffleSource As Boolean = true) As IDataView
- input
- IDataView
Los datos de entrada.
Inicialización aleatoria. Si no se especifica, el estado aleatorio se derivará en su lugar de MLContext.
- shufflePoolSize
- Int32
Número de filas que se van a contener en el grupo. Si se establece en 1, se desactivará el orden aleatorio del grupo y ShuffleRows(IDataView, Nullable<Int32>, Int32, Boolean) solo se realizará un orden aleatorio leyendo input
en un orden aleatorio.
- shuffleSource
- Boolean
Si false
es , la transformación no intentará leer input
en un orden aleatorio y solo usará la agrupación para ordenar aleatoriamente. Este parámetro no tiene ningún efecto si la CanShuffle propiedad de input
es false
.
using System;
using System.Collections.Generic;
using Microsoft.ML;
namespace Samples.Dynamic
{
public static class ShuffleRows
{
// Sample class showing how to shuffle rows in
// IDataView.
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.
var mlContext = new MLContext();
// Get a small dataset as an IEnumerable.
var enumerableOfData = GetSampleTemperatureData(5);
var data = mlContext.Data.LoadFromEnumerable(enumerableOfData);
// Before we apply a filter, examine all the records in the dataset.
Console.WriteLine($"Date\tTemperature");
foreach (var row in enumerableOfData)
{
Console.WriteLine($"{row.Date.ToString("d")}" +
$"\t{row.Temperature}");
}
Console.WriteLine();
// Expected output:
// Date Temperature
// 1/2/2012 36
// 1/3/2012 36
// 1/4/2012 34
// 1/5/2012 35
// 1/6/2012 35
// Shuffle the dataset.
var shuffledData = mlContext.Data.ShuffleRows(data, seed: 123);
// Look at the shuffled data and observe that the rows are in a
// randomized order.
var enumerable = mlContext.Data
.CreateEnumerable<SampleTemperatureData>(shuffledData,
reuseRowObject: true);
Console.WriteLine($"Date\tTemperature");
foreach (var row in enumerable)
{
Console.WriteLine($"{row.Date.ToString("d")}" +
$"\t{row.Temperature}");
}
// Expected output:
// Date Temperature
// 1/4/2012 34
// 1/2/2012 36
// 1/5/2012 35
// 1/3/2012 36
// 1/6/2012 35
}
private class SampleTemperatureData
{
public DateTime Date { get; set; }
public float Temperature { get; set; }
}
/// <summary>
/// Get a fake temperature dataset.
/// </summary>
/// <param name="exampleCount">The number of examples to return.</param>
/// <returns>An enumerable of <see cref="SampleTemperatureData"/>.</returns>
private static IEnumerable<SampleTemperatureData> GetSampleTemperatureData(
int exampleCount)
{
var rng = new Random(1234321);
var date = new DateTime(2012, 1, 1);
float temperature = 39.0f;
for (int i = 0; i < exampleCount; i++)
{
date = date.AddDays(1);
temperature += rng.Next(-5, 5);
yield return new SampleTemperatureData
{
Date = date,
Temperature =
temperature
};
}
}
}
}
ShuffleRows(IDataView, Nullable<Int32>, Int32, Boolean) ordenará aleatoriamente las filas de cualquier entrada IDataView mediante un enfoque de streaming. Para no cargar todo el conjunto de datos en memoria, se usará un grupo de shufflePoolSize
filas para seleccionar aleatoriamente las filas que se van a generar. El grupo se construye a partir de las primeras shufflePoolSize
filas de input
. Después, las filas se generarán aleatoriamente del grupo y se reemplazarán por la siguiente fila de input
hasta que se hayan producido todas las filas, lo que dará como resultado un nuevo IDataView tamaño igual input
que pero con las filas en un orden aleatorio. Si la CanShuffle propiedad de input
es true, también se leerá en el grupo en un orden aleatorio, ofreciendo dos orígenes de aleatoriedad.
Produto | Versións |
---|---|
ML.NET | 1.0.0, 1.1.0, 1.2.0, 1.3.1, 1.4.0, 1.5.0, 1.6.0, 1.7.0, 2.0.0, 3.0.0, 4.0.0, Preview |