private protected PredictedLabelScorerBase(ScorerArgumentsBase args, IHostEnvironment env, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema, string registrationName, string scoreColKind, string scoreColName, Func <DataViewType, bool> outputTypeMatches, Func <DataViewType, ISchemaBoundRowMapper, DataViewType> getPredColType, string predictedLabelColumnName = DefaultColumnNames.PredictedLabel) : base(env, data, registrationName, Contracts.CheckRef(mapper, nameof(mapper)).Bindable) { Host.CheckValue(args, nameof(args)); Host.CheckNonEmpty(scoreColKind, nameof(scoreColKind)); Host.CheckNonEmpty(scoreColName, nameof(scoreColName)); Host.CheckValue(outputTypeMatches, nameof(outputTypeMatches)); Host.CheckValue(getPredColType, nameof(getPredColType)); var rowMapper = mapper as ISchemaBoundRowMapper; Host.CheckParam(rowMapper != null, nameof(mapper), "mapper should implement " + nameof(ISchemaBoundRowMapper)); int scoreColIndex; if (!mapper.OutputSchema.TryGetColumnIndex(scoreColName, out scoreColIndex)) { throw Host.ExceptParam(nameof(scoreColName), "mapper does not contain a column '{0}'", scoreColName); } var scoreType = mapper.OutputSchema[scoreColIndex].Type; Host.Check(outputTypeMatches(scoreType), "Unexpected predictor output type"); var predColType = getPredColType(scoreType, rowMapper); Bindings = BindingsImpl.Create(data.Schema, rowMapper, args.Suffix, scoreColKind, scoreColIndex, predColType, predictedLabelColumnName); OutputSchema = Bindings.AsSchema; }
internal static bool GetTypesForWrapping(ISchemaBoundMapper mapper, DataViewType labelNameType, string metaKind, out DataViewType scoreType) { Contracts.AssertValue(mapper); Contracts.AssertValue(labelNameType); scoreType = null; ISchemaBoundRowMapper rowMapper = mapper as ISchemaBoundRowMapper; if (rowMapper == null) { return(false); // We could cover this case, but it is of no practical worth as far as I see, so I decline to do so. } var outSchema = mapper.OutputSchema; int scoreIdx; var scoreCol = outSchema.GetColumnOrNull(AnnotationUtils.Const.ScoreValueKind.Score); if (!outSchema.TryGetColumnIndex(AnnotationUtils.Const.ScoreValueKind.Score, out scoreIdx)) { return(false); // The mapper doesn't even publish a score column to attach the metadata to. } if (outSchema[scoreIdx].Annotations.Schema.GetColumnOrNull(metaKind)?.Type != null) { return(false); // The mapper publishes a score column, and already produces its own metakind. } scoreType = outSchema[scoreIdx].Type; return(true); }
/// <summary> /// This is a utility method used to determine whether <see cref="LabelNameBindableMapper"/> /// can or should be used to wrap <paramref name="mapper"/>. This will not throw, since the /// desired behavior in the event that it cannot be wrapped, is to just back off to the original /// "unwrapped" bound mapper. /// </summary> /// <param name="mapper">The mapper we are seeing if we can wrap</param> /// <param name="labelNameType">The type of the label names from the metadata (either /// originating from the key value metadata of the training label column, or deserialized /// from the model of a bindable mapper)</param> /// <returns>Whether we can call <see cref="LabelNameBindableMapper.CreateBound{T}"/> with /// this mapper and expect it to succeed</returns> public static bool CanWrap(ISchemaBoundMapper mapper, ColumnType labelNameType) { Contracts.AssertValue(mapper); Contracts.AssertValue(labelNameType); ISchemaBoundRowMapper rowMapper = mapper as ISchemaBoundRowMapper; if (rowMapper == null) { return(false); // We could cover this case, but it is of no practical worth as far as I see, so I decline to do so. } ISchema outSchema = mapper.Schema; int scoreIdx; if (!outSchema.TryGetColumnIndex(MetadataUtils.Const.ScoreValueKind.Score, out scoreIdx)) { return(false); // The mapper doesn't even publish a score column to attach the metadata to. } if (outSchema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, scoreIdx) != null) { return(false); // The mapper publishes a score column, and already produces its own slot names. } var scoreType = outSchema.GetColumnType(scoreIdx); // Check that the type is vector, and is of compatible size with the score output. return(labelNameType.IsVector && labelNameType.VectorSize == scoreType.VectorSize); }
/// <summary> /// This is a utility method used to determine whether <see cref="LabelNameBindableMapper"/> /// can or should be used to wrap <paramref name="mapper"/>. This will not throw, since the /// desired behavior in the event that it cannot be wrapped, is to just back off to the original /// "unwrapped" bound mapper. /// </summary> /// <param name="mapper">The mapper we are seeing if we can wrap</param> /// <param name="labelNameType">The type of the label names from the metadata (either /// originating from the key value metadata of the training label column, or deserialized /// from the model of a bindable mapper)</param> /// <returns>Whether we can call <see cref="LabelNameBindableMapper.CreateBound{T}"/> with /// this mapper and expect it to succeed</returns> internal static bool CanWrap(ISchemaBoundMapper mapper, DataViewType labelNameType) { Contracts.AssertValue(mapper); Contracts.AssertValue(labelNameType); ISchemaBoundRowMapper rowMapper = mapper as ISchemaBoundRowMapper; if (rowMapper == null) { return(false); // We could cover this case, but it is of no practical worth as far as I see, so I decline to do so. } var outSchema = mapper.OutputSchema; int scoreIdx; var scoreCol = outSchema.GetColumnOrNull(AnnotationUtils.Const.ScoreValueKind.Score); if (!outSchema.TryGetColumnIndex(AnnotationUtils.Const.ScoreValueKind.Score, out scoreIdx)) { return(false); // The mapper doesn't even publish a score column to attach the metadata to. } if (outSchema[scoreIdx].Annotations.Schema.GetColumnOrNull(AnnotationUtils.Kinds.SlotNames)?.Type != null) { return(false); // The mapper publishes a score column, and already produces its own slot names. } var scoreType = outSchema[scoreIdx].Type; // Check that the type is vector, and is of compatible size with the score output. return(labelNameType is VectorType vectorType && vectorType.Size == scoreType.GetVectorSize() && vectorType.ItemType == TextDataViewType.Instance); }
internal static ISchemaBoundMapper WrapCore <T>(IHostEnvironment env, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { Contracts.AssertValue(env); env.AssertValue(mapper); env.AssertValue(trainSchema); env.Assert(mapper is ISchemaBoundRowMapper); // Key values from the training schema label, will map to slot names of the score output. var type = trainSchema.Label.Value.Annotations.Schema.GetColumnOrNull(AnnotationUtils.Kinds.KeyValues)?.Type; env.AssertValue(type); env.Assert(type is VectorDataViewType); // Wrap the fetching of the metadata as a simple getter. ValueGetter <VBuffer <T> > getter = (ref VBuffer <T> value) => { trainSchema.Label.Value.GetKeyValues(ref value); }; var resultMapper = mapper; if (CanWrapTrainingLabels(resultMapper, type)) { resultMapper = LabelNameBindableMapper.CreateBound <T>(env, (ISchemaBoundRowMapper)resultMapper, type as VectorDataViewType, getter, AnnotationUtils.Kinds.TrainingLabelValues, CanWrapTrainingLabels); } if (CanWrapSlotNames(resultMapper, type)) { resultMapper = LabelNameBindableMapper.CreateBound <T>(env, (ISchemaBoundRowMapper)resultMapper, type as VectorDataViewType, getter, AnnotationUtils.Kinds.SlotNames, CanWrapSlotNames); } return(resultMapper); }
/// <summary> /// Gets a cached prediction engine or creates a new one if not cached /// </summary> private BatchPredictionEngine <SarUsageEvent, SarScoreResult> GetOrCreateBatchPredictionEngine( IList <SarUsageEvent> usageItems, SarScoringArguments sarScoringArguments) { var arguments = new RecommenderScorerTransform.Arguments { // round the recommendations count to optimize engine cache recommendationCount = GetRoundedNumberOfResults(sarScoringArguments.RecommendationCount), includeHistory = sarScoringArguments.IncludeHistory }; // create a data column mapping var dataColumnMapping = new Dictionary <RoleMappedSchema.ColumnRole, string> { { new RoleMappedSchema.ColumnRole("Item"), "Item" }, { new RoleMappedSchema.ColumnRole("User"), "user" } }; string weightColumn = null; if (sarScoringArguments.ReferenceDate.HasValue) { // rounding the reference date to the beginning of next day to optimize engine cache DateTime referenceDate = sarScoringArguments.ReferenceDate.Value.Date + TimeSpan.FromDays(1); arguments.referenceDate = referenceDate.ToString("s"); if (sarScoringArguments.Decay.HasValue) { arguments.decay = sarScoringArguments.Decay.Value.TotalDays; } dataColumnMapping.Add(new RoleMappedSchema.ColumnRole("Date"), "date"); weightColumn = "weight"; } // create an engine cache key string cacheKey = $"{arguments.recommendationCount}|{arguments.includeHistory}|{arguments.referenceDate}|{arguments.decay}"; _tracer.TraceVerbose("Trying to find the engine in the cache"); var engine = _enginesCache.Get(cacheKey) as BatchPredictionEngine <SarUsageEvent, SarScoreResult>; if (engine == null) { _tracer.TraceInformation("Engine is not cached - creating a new engine"); IDataView pipeline = _environment.CreateDataView(usageItems, _usageDataSchema); RoleMappedData usageDataMappedData = _environment.CreateExamples(pipeline, null, weight: weightColumn, custom: dataColumnMapping); ISchemaBindableMapper mapper = RecommenderScorerTransform.Create(_environment, arguments, _recommender); ISchemaBoundMapper boundMapper = mapper.Bind(_environment, usageDataMappedData.Schema); IDataScorerTransform scorer = RecommenderScorerTransform.Create( _environment, arguments, pipeline, boundMapper, null); engine = _environment.CreateBatchPredictionEngine <SarUsageEvent, SarScoreResult>(scorer, false, _usageDataSchema); bool result = _enginesCache.Add(cacheKey, engine, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromDays(1) }); _tracer.TraceVerbose($"Addition of engine to the cache resulted with '{result}'"); } return(engine); }
/// <summary> /// This is a utility method used to determine whether <see cref="LabelNameBindableMapper"/> /// can or should be used to wrap <paramref name="mapper"/>. This will not throw, since the /// desired behavior in the event that it cannot be wrapped, is to just back off to the original /// "unwrapped" bound mapper. /// </summary> /// <param name="mapper">The mapper we are seeing if we can wrap</param> /// <param name="labelNameType">The type of the label names from the metadata (either /// originating from the key value metadata of the training label column, or deserialized /// from the model of a bindable mapper)</param> /// <returns>Whether we can call <see cref="LabelNameBindableMapper.CreateBound{T}"/> with /// this mapper and expect it to succeed</returns> internal static bool CanWrapSlotNames(ISchemaBoundMapper mapper, DataViewType labelNameType) { if (GetTypesForWrapping(mapper, labelNameType, AnnotationUtils.Kinds.SlotNames, out var scoreType)) { // Check that the type is vector, and is of compatible size with the score output. return(labelNameType is VectorDataViewType vectorType && vectorType.Size == scoreType.GetVectorSize() && vectorType.ItemType == TextDataViewType.Instance); } return(false); }
/// <summary> /// Determine the default scorer for a schema bound mapper. This looks for text-valued ScoreColumnKind /// metadata on the first column of the mapper. If that text is found and maps to a scorer loadable class, /// that component is used. Otherwise, the GenericScorer is used. /// </summary> /// <param name="environment">The host environment.</param>. /// <param name="mapper">The schema bound mapper to get the default scorer.</param>. /// <param name="suffix">An optional suffix to append to the default column names.</param> public static TScorerFactory GetScorerComponent( IHostEnvironment environment, ISchemaBoundMapper mapper, string suffix = null) { Contracts.CheckValue(environment, nameof(environment)); Contracts.AssertValue(mapper); ComponentCatalog.LoadableClassInfo info = null; ReadOnlyMemory <char> scoreKind = default; if (mapper.OutputSchema.Count > 0 && mapper.OutputSchema.TryGetMetadata(TextType.Instance, MetadataUtils.Kinds.ScoreColumnKind, 0, ref scoreKind) && !scoreKind.IsEmpty) { var loadName = scoreKind.ToString(); info = environment.ComponentCatalog.GetLoadableClassInfo <SignatureDataScorer>(loadName); if (info == null || !typeof(IDataScorerTransform).IsAssignableFrom(info.Type)) { info = null; } } Func <IHostEnvironment, IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> factoryFunc; if (info == null) { factoryFunc = (env, data, innerMapper, trainSchema) => new GenericScorer( env, new GenericScorer.Arguments() { Suffix = suffix }, data, innerMapper, trainSchema); } else { factoryFunc = (env, data, innerMapper, trainSchema) => { object args = info.CreateArguments(); if (args is ScorerArgumentsBase scorerArgs) { scorerArgs.Suffix = suffix; } return((IDataScorerTransform)info.CreateInstance( env, args, new object[] { data, innerMapper, trainSchema })); }; } return(ComponentFactoryUtils.CreateFromFunction(factoryFunc)); }
/// <summary> /// The <see cref="SignatureDataScorer"/> entry point for creating a <see cref="GenericScorer"/>. /// </summary> public GenericScorer(IHostEnvironment env, ScorerArgumentsBase args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) : base(env, data, RegistrationName, Contracts.CheckRef(mapper, nameof(mapper)).Bindable) { Host.CheckValue(args, nameof(args)); Host.AssertValue(data, "data"); Host.AssertValue(mapper, "mapper"); var rowMapper = mapper as ISchemaBoundRowMapper; Host.CheckParam(rowMapper != null, nameof(mapper), "mapper should implement ISchemaBoundRowMapper"); _bindings = Bindings.Create(data.Schema, rowMapper, args.Suffix); }
protected ScorerBindingsBase(Schema input, ISchemaBoundMapper mapper, string suffix, bool user, params string[] namesDerived) : base(input, user, GetOutputNames(mapper, suffix, namesDerived)) { Contracts.AssertValue(mapper); Contracts.AssertValueOrNull(suffix); Contracts.AssertValue(namesDerived); Mapper = mapper; DerivedColumnCount = namesDerived.Length; Suffix = suffix ?? ""; int c; var max = input.GetMaxMetadataKind(out c, MetadataUtils.Kinds.ScoreColumnSetId); _crtScoreSet = checked(max + 1); _getScoreColumnSetId = GetScoreColumnSetId; }
/// <summary> /// Determines the scorer subcomponent (if the given one is null or empty), and creates the schema bound mapper. /// </summary> private static SubComponent <IDataScorerTransform, SignatureDataScorer> GetScorerComponentAndMapper( IPredictor predictor, SubComponent <IDataScorerTransform, SignatureDataScorer> scorer, RoleMappedSchema schema, IHostEnvironment env, out ISchemaBoundMapper mapper) { Contracts.AssertValue(env); var bindable = GetSchemaBindableMapper(env, predictor, scorer); env.AssertValue(bindable); mapper = bindable.Bind(env, schema); if (scorer.IsGood()) { return(scorer); } return(GetScorerComponent(mapper)); }
private static string[] GetOutputNames(ISchemaBoundMapper mapper, string suffix, string[] namesDerived) { Contracts.AssertValue(mapper); Contracts.AssertValueOrNull(suffix); Contracts.AssertValue(namesDerived); var schema = mapper.OutputSchema; int count = namesDerived.Length + schema.ColumnCount; var res = new string[count]; int dst = 0; for (int i = 0; i < namesDerived.Length; i++) res[dst++] = namesDerived[i] + suffix; for (int i = 0; i < schema.ColumnCount; i++) res[dst++] = schema.GetColumnName(i) + suffix; Contracts.Assert(dst == count); return res; }
/// <summary> /// Determines the scorer component factory (if the given one is null or empty), and creates the schema bound mapper. /// </summary> private static TScorerFactory GetScorerComponentAndMapper( IPredictor predictor, TScorerFactory scorerFactory, RoleMappedSchema schema, IHostEnvironment env, IComponentFactory<IPredictor, ISchemaBindableMapper> mapperFactory, out ISchemaBoundMapper mapper) { Contracts.AssertValue(env); var bindable = GetSchemaBindableMapper(env, predictor, mapperFactory, scorerFactory as ICommandLineComponentFactory); env.AssertValue(bindable); mapper = bindable.Bind(env, schema); if (scorerFactory != null) return scorerFactory; return GetScorerComponent(mapper); }
private static ISchemaBoundMapper WrapCore <T>(IHostEnvironment env, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { Contracts.AssertValue(env); env.AssertValue(mapper); env.AssertValue(trainSchema); env.Assert(mapper is ISchemaBoundRowMapper); env.Assert(trainSchema.Label.HasValue); var labelColumn = trainSchema.Label.Value; // Key values from the training schema label, will map to slot names of the score output. var type = labelColumn.Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.KeyValues)?.Type as VectorType; env.AssertValue(type); // Wrap the fetching of the metadata as a simple getter. ValueGetter <VBuffer <T> > getter = (ref VBuffer <T> value) => labelColumn.Metadata.GetValue(MetadataUtils.Kinds.KeyValues, ref value); return(MultiClassClassifierScorer.LabelNameBindableMapper.CreateBound <T>(env, (ISchemaBoundRowMapper)mapper, type, getter, MetadataUtils.Kinds.TrainingLabelValues, CanWrap)); }
public static ISchemaBoundMapper WrapCore <T>(IHostEnvironment env, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { Contracts.AssertValue(env); env.AssertValue(mapper); env.AssertValue(trainSchema); env.Assert(mapper is ISchemaBoundRowMapper); // Key values from the training schema label, will map to slot names of the score output. var type = trainSchema.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.KeyValues, trainSchema.Label.Index); env.AssertValue(type); env.Assert(type.IsVector); // Wrap the fetching of the metadata as a simple getter. ValueGetter <VBuffer <T> > getter = (ref VBuffer <T> value) => { trainSchema.Schema.GetMetadata(MetadataUtils.Kinds.KeyValues, trainSchema.Label.Index, ref value); }; return(LabelNameBindableMapper.CreateBound <T>(env, (ISchemaBoundRowMapper)mapper, type.AsVector, getter, MetadataUtils.Kinds.SlotNames, CanWrap)); }
/// <summary> /// This is a utility method used to determine whether <see cref="MultiClassClassifierScorer.LabelNameBindableMapper"/> /// can or should be used to wrap <paramref name="mapper"/>. This will not throw, since the /// desired behavior in the event that it cannot be wrapped, is to just back off to the original /// "unwrapped" bound mapper. /// </summary> /// <param name="mapper">The mapper we are seeing if we can wrap</param> /// <param name="labelNameType">The type of the label names from the metadata (either /// originating from the key value metadata of the training label column, or deserialized /// from the model of a bindable mapper)</param> /// <returns>Whether we can call <see cref="MultiClassClassifierScorer.LabelNameBindableMapper.CreateBound{T}"/> with /// this mapper and expect it to succeed</returns> private static bool CanWrap(ISchemaBoundMapper mapper, ColumnType labelNameType) { Contracts.AssertValue(mapper); Contracts.AssertValue(labelNameType); ISchemaBoundRowMapper rowMapper = mapper as ISchemaBoundRowMapper; if (rowMapper == null) { return(false); // We could cover this case, but it is of no practical worth as far as I see, so I decline to do so. } int scoreIdx; if (!mapper.OutputSchema.TryGetColumnIndex(MetadataUtils.Const.ScoreValueKind.Score, out scoreIdx)) { return(false); // The mapper doesn't even publish a score column to attach the metadata to. } if (mapper.OutputSchema[scoreIdx].Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.TrainingLabelValues)?.Type != null) { return(false); // The mapper publishes a score column, and already produces its own slot names. } return(labelNameType is VectorType vectorType && vectorType.Size == 2); }
/// <summary> /// This function performs a number of checks on the inputs and, if appropriate and possible, will produce /// a mapper with slots names on the output score column properly mapped. If this is not possible for any /// reason, it will just return the input bound mapper. /// </summary> private static ISchemaBoundMapper WrapIfNeeded(IHostEnvironment env, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(mapper, nameof(mapper)); env.CheckValueOrNull(trainSchema); // The idea is that we will take the key values from the train schema label, and present // them as slot name metadata. But there are a number of conditions for this to actually // happen, so we test those here. If these are not if (trainSchema?.Label == null) { return(mapper); // We don't even have a label identified in a training schema. } var keyType = trainSchema.Label.Value.Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.KeyValues)?.Type as VectorType; if (keyType == null || !CanWrap(mapper, keyType)) { return(mapper); } // Great!! All checks pass. return(Utils.MarshalInvoke(WrapCore <int>, keyType.ItemType.RawType, env, mapper, trainSchema)); }
internal BinaryClassifierScorer(IHostEnvironment env, Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) : base(args, env, data, WrapIfNeeded(env, mapper, trainSchema), trainSchema, RegistrationName, MetadataUtils.Const.ScoreColumnKind.BinaryClassification, Contracts.CheckRef(args, nameof(args)).ThresholdColumn, OutputTypeMatches, GetPredColType) { Contracts.CheckValue(args, nameof(args)); Contracts.CheckValue(data, nameof(data)); Contracts.CheckValue(mapper, nameof(mapper)); _threshold = args.Threshold; }
public static IDataScorerTransform Create(IHostEnvironment env, Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { return(new GenericScorer(env, args, data, mapper, trainSchema)); }
// Factory method for SignatureDataScorer. private static IDataScorerTransform Create(IHostEnvironment env, Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(data, nameof(data)); env.CheckValue(mapper, nameof(mapper)); if (args.Top < 0) { throw env.Except($"Number of top contribution must be non negative"); } if (args.Bottom < 0) { throw env.Except($"Number of bottom contribution must be non negative"); } var contributionMapper = mapper as RowMapper; env.CheckParam(mapper != null, nameof(mapper), "Unexpected mapper"); var scorer = ScoreUtils.GetScorerComponent(env, contributionMapper); var scoredPipe = scorer.CreateComponent(env, data, contributionMapper, trainSchema); return(scoredPipe); }
private LabelNameBindableMapper(IHostEnvironment env, ISchemaBoundMapper mapper, VectorType type, Delegate getter, string metadataKind, Func <ISchemaBoundMapper, ColumnType, bool> canWrap) : this(env, mapper.Bindable, type, getter, metadataKind, canWrap) { }
public MultiClassClassifierScorer(IHostEnvironment env, Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) : base(args, env, data, WrapIfNeeded(env, mapper, trainSchema), trainSchema, RegistrationName, MetadataUtils.Const.ScoreColumnKind.MultiClassClassification, MetadataUtils.Const.ScoreValueKind.Score, OutputTypeMatches, GetPredColType) { }
/// <summary> /// Determine the default scorer for a schema bound mapper. This looks for text-valued ScoreColumnKind /// metadata on the first column of the mapper. If that text is found and maps to a scorer loadable class, /// that component is used. Otherwise, the GenericScorer is used. /// </summary> public static SubComponent <IDataScorerTransform, SignatureDataScorer> GetScorerComponent(ISchemaBoundMapper mapper) { Contracts.AssertValue(mapper); string loadName = null; DvText scoreKind = default; if (mapper.OutputSchema.ColumnCount > 0 && mapper.OutputSchema.TryGetMetadata(TextType.Instance, MetadataUtils.Kinds.ScoreColumnKind, 0, ref scoreKind) && scoreKind.HasChars) { loadName = scoreKind.ToString(); var info = ComponentCatalog.GetLoadableClassInfo <SignatureDataScorer>(loadName); if (info == null || !typeof(IDataScorerTransform).IsAssignableFrom(info.Type)) { loadName = null; } } if (loadName == null) { loadName = GenericScorer.LoadName; } return(new SubComponent <IDataScorerTransform, SignatureDataScorer>(loadName)); }
public ClusteringScorer(IHostEnvironment env, Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) : base(args, env, data, mapper, trainSchema, RegistrationName, MetadataUtils.Const.ScoreColumnKind.Clustering, MetadataUtils.Const.ScoreValueKind.Score, OutputTypeMatches, GetPredColType) { }
// Factory method for SignatureDataScorer. private static IDataScorerTransform Create(IHostEnvironment env, TreeEnsembleFeaturizerBindableMapper.Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) { return(new GenericScorer(env, args, data, mapper, trainSchema)); }
internal MulticlassClassificationScorer(IHostEnvironment env, Arguments args, IDataView data, ISchemaBoundMapper mapper, RoleMappedSchema trainSchema) : base(args, env, data, WrapIfNeeded(env, mapper, trainSchema), trainSchema, RegistrationName, AnnotationUtils.Const.ScoreColumnKind.MulticlassClassification, args.ScoreColumnName, OutputTypeMatches, GetPredColType, args.PredictedLabelColumnName) { }