Example #1
0
        /// <summary>
        /// Initializing a new instance of <see cref="MatrixFactorizationTrainer"/>.
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="matrixColumnIndexColumnName">The name of the column hosting the matrix's column IDs.</param>
        /// <param name="matrixRowIndexColumnName">The name of the column hosting the matrix's row IDs.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        /// <param name="context">The <see cref="TrainerEstimatorContext"/> for additional input data to training.</param>
        public MatrixFactorizationTrainer(IHostEnvironment env,
                                          string matrixColumnIndexColumnName,
                                          string matrixRowIndexColumnName,
                                          string labelColumn = DefaultColumnNames.Label,
                                          TrainerEstimatorContext context     = null,
                                          Action <Arguments> advancedSettings = null)
            : base(env, LoadNameValue)
        {
            var args = new Arguments();

            advancedSettings?.Invoke(args);

            _lambda  = args.Lambda;
            _k       = args.K;
            _iter    = args.NumIterations;
            _eta     = args.Eta;
            _threads = args.NumThreads ?? Environment.ProcessorCount;
            _quiet   = args.Quiet;
            _doNmf   = args.NonNegative;

            Info     = new TrainerInfo(normalization: false, caching: false);
            _context = context;

            LabelName             = labelColumn;
            MatrixColumnIndexName = matrixColumnIndexColumnName;
            MatrixRowIndexName    = matrixRowIndexColumnName;
        }
Example #2
0
        /// <summary>
        /// Initializing a new instance of <see cref="FieldAwareFactorizationMachineTrainer"/>.
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="featureColumns">The name of  column hosting the features.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        /// <param name="weights">The name of the optional weights' column.</param>
        /// <param name="context">The <see cref="TrainerEstimatorContext"/> for additional input data to training.</param>
        public FieldAwareFactorizationMachineTrainer(IHostEnvironment env,
                                                     string[] featureColumns,
                                                     string labelColumn = DefaultColumnNames.Label,
                                                     string weights     = null,
                                                     TrainerEstimatorContext context     = null,
                                                     Action <Arguments> advancedSettings = null)
            : base(env, LoadName)
        {
            var args = new Arguments();

            advancedSettings?.Invoke(args);

            Initialize(env, args);
            Info = new TrainerInfo(supportValid: true, supportIncrementalTrain: true);

            Context = context;

            FeatureColumns = new SchemaShape.Column[featureColumns.Length];

            for (int i = 0; i < featureColumns.Length; i++)
            {
                FeatureColumns[i] = new SchemaShape.Column(featureColumns[i], SchemaShape.Column.VectorKind.Vector, NumberType.R4, false);
            }

            LabelColumn  = new SchemaShape.Column(labelColumn, SchemaShape.Column.VectorKind.Scalar, BoolType.Instance, false);
            WeightColumn = weights != null ? new SchemaShape.Column(weights, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false) : null;
        }
Example #3
0
        /// <summary>
        /// Initializing a new instance of <see cref="MatrixFactorizationTrainer"/>.
        /// </summary>
        /// <param name="env">The private instance of <see cref="IHostEnvironment"/>.</param>
        /// <param name="labelColumn">The name of the label column.</param>
        /// <param name="matrixColumnIndexColumnName">The name of the column hosting the matrix's column IDs.</param>
        /// <param name="matrixRowIndexColumnName">The name of the column hosting the matrix's row IDs.</param>
        /// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
        /// <param name="context">The <see cref="TrainerEstimatorContext"/> for additional input data to training.</param>
        public MatrixFactorizationTrainer(IHostEnvironment env, string labelColumn, string matrixColumnIndexColumnName, string matrixRowIndexColumnName,
                                          TrainerEstimatorContext context = null, Action <Arguments> advancedSettings = null)
            : base(env, LoadNameValue)
        {
            var args = new Arguments();

            advancedSettings?.Invoke(args);

            _lambda  = args.Lambda;
            _k       = args.K;
            _iter    = args.NumIterations;
            _eta     = args.Eta;
            _threads = args.NumThreads ?? Environment.ProcessorCount;
            _quiet   = args.Quiet;
            _doNmf   = args.NonNegative;

            Info    = new TrainerInfo(normalization: false, caching: false);
            Context = context;

            LabelColumn             = new SchemaShape.Column(labelColumn, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false);
            MatrixColumnIndexColumn = new SchemaShape.Column(matrixColumnIndexColumnName, SchemaShape.Column.VectorKind.Scalar, NumberType.U4, true);
            MatrixRowIndexColumn    = new SchemaShape.Column(matrixRowIndexColumnName, SchemaShape.Column.VectorKind.Scalar, NumberType.U4, true);
        }