DataOperationsCatalog.SkipRows(IDataView, Int64) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
跳过count
行。input
public Microsoft.ML.IDataView SkipRows (Microsoft.ML.IDataView input, long count);
member this.SkipRows : Microsoft.ML.IDataView * int64 -> Microsoft.ML.IDataView
Public Function SkipRows (input As IDataView, count As Long) As IDataView
参数
- input
- IDataView
输入数据。
- count
- Int64
要跳过的行数。
返回
示例
using System;
using System.Collections.Generic;
using Microsoft.ML;
namespace Samples.Dynamic
{
public static class SkipRows
{
// Sample class showing how to skip 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(10);
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
// 1/7/2012 39
// 1/8/2012 40
// 1/9/2012 35
// 1/10/2012 30
// 1/11/2012 29
// Skip the first 5 rows in the dataset
var filteredData = mlContext.Data.SkipRows(data, 5);
// Look at the filtered data and observe that the first 5 rows have been
// dropped
var enumerable = mlContext.Data
.CreateEnumerable<SampleTemperatureData>(filteredData,
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/7/2012 39
// 1/8/2012 40
// 1/9/2012 35
// 1/10/2012 30
// 1/11/2012 29
}
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
};
}
}
}
}
注解
跳过第一 count
行 input
,并返回包含所有其他行的行 IDataView 。