Ejemplo n.º 1
0
        /// <summary>
        /// Run the prediction pipe. This will enumerate the <paramref name="examples"/> exactly once,
        /// cache all the examples (by reference) into its internal representation and then run
        /// the transformation pipe.
        /// </summary>
        /// <param name="examples">The examples to run the prediction on.</param>
        /// <param name="reuseRowObjects">If <c>true</c>, the engine will not allocate memory per output, and
        /// the returned <typeparamref name="TDst"/> objects will actually always be the same object. The user is
        /// expected to clone the values himself if needed.</param>
        /// <returns>The <see cref="IEnumerable{TDst}"/> that contains all the pipeline results.</returns>
        public IEnumerable <TDst> Predict(IEnumerable <TSrc> examples, bool reuseRowObjects)
        {
            Contracts.CheckValue(examples, nameof(examples));

            _pipeEngine.Reset();
            _srcDataView.SetData(examples);
            return(_pipeEngine.RunPipe(reuseRowObjects));
        }
        /// <summary>
        /// Convert an <see cref="IDataView"/> into a strongly-typed <see cref="IEnumerable{TRow}"/>.
        /// </summary>
        /// <typeparam name="TRow">The user-defined item type.</typeparam>
        /// <param name="data">The underlying data view.</param>
        /// <param name="reuseRowObject">Whether to return the same object on every row, or allocate a new one per row.</param>
        /// <param name="ignoreMissingColumns">Whether to ignore the case when a requested column is not present in the data view.</param>
        /// <param name="schemaDefinition">Optional user-provided schema definition. If it is not present, the schema is inferred from the definition of T.</param>
        /// <returns>The <see cref="IEnumerable{TRow}"/> that holds the data in <paramref name="data"/>. It can be enumerated multiple times.</returns>
        /// <example>
        /// <format type="text/markdown">
        /// <![CDATA[
        /// [!code-csharp[CreateEnumerable](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs)]
        /// ]]>
        /// </format>
        /// </example>
        public IEnumerable<TRow> CreateEnumerable<TRow>(IDataView data, bool reuseRowObject,
            bool ignoreMissingColumns = false, SchemaDefinition schemaDefinition = null)
            where TRow : class, new()
        {
            _env.CheckValue(data, nameof(data));
            _env.CheckValueOrNull(schemaDefinition);

            var engine = new PipeEngine<TRow>(_env, data, ignoreMissingColumns, schemaDefinition);
            return engine.RunPipe(reuseRowObject);
        }