/// <summary> /// All the input columns needed by an evaluator should be added here. /// The base class ipmlementation gets the score column, the label column (if exists) and the weight column (if exists). /// Override if additional columns are needed. /// </summary> protected virtual IEnumerable <KeyValuePair <RoleMappedSchema.ColumnRole, string> > GetInputColumnRolesCore(RoleMappedSchema schema) { // Get the score column information. var scoreInfo = EvaluateUtils.GetScoreColumnInfo(Host, schema.Schema, ScoreCol, nameof(ArgumentsBase.ScoreColumn), ScoreColumnKind); yield return(RoleMappedSchema.CreatePair(MetadataUtils.Const.ScoreValueKind.Score, scoreInfo.Name)); // Get the label column information. string lab = EvaluateUtils.GetColName(LabelCol, schema.Label, DefaultColumnNames.Label); yield return(RoleMappedSchema.CreatePair(RoleMappedSchema.ColumnRole.Label, lab)); var weight = EvaluateUtils.GetColName(WeightCol, schema.Weight, null); if (!string.IsNullOrEmpty(weight)) { yield return(RoleMappedSchema.CreatePair(RoleMappedSchema.ColumnRole.Weight, weight)); } }
/// <summary> /// Evaluates scored clustering data. /// </summary> /// <param name="data">The scored data.</param> /// <param name="score">The name of the score column in <paramref name="data"/>.</param> /// <param name="label">The name of the optional label column in <paramref name="data"/>.</param> /// <param name="features">The name of the optional feature column in <paramref name="data"/>.</param> /// <returns>The evaluation results.</returns> public Result Evaluate(IDataView data, string score, string label = null, string features = null) { Host.CheckValue(data, nameof(data)); Host.CheckNonEmpty(score, nameof(score)); var roles = new List <KeyValuePair <RoleMappedSchema.ColumnRole, string> >(); roles.Add(RoleMappedSchema.CreatePair(MetadataUtils.Const.ScoreValueKind.Score, score)); if (label != null) { roles.Add(RoleMappedSchema.ColumnRole.Label.Bind(label)); } if (features != null) { roles.Add(RoleMappedSchema.ColumnRole.Feature.Bind(features)); } var rolesMappedData = new RoleMappedData(data, opt: false, roles.ToArray()); var resultDict = Evaluate(rolesMappedData); Host.Assert(resultDict.ContainsKey(MetricKinds.OverallMetrics)); var overall = resultDict[MetricKinds.OverallMetrics]; Result result; using (var cursor = overall.GetRowCursor(i => true)) { var moved = cursor.MoveNext(); Host.Assert(moved); result = new Result(Host, cursor, _calculateDbi); moved = cursor.MoveNext(); Host.Assert(!moved); } return(result); }
protected static KeyValuePair<RoleMappedSchema.ColumnRole, string>[] LoadBaseInfo( ModelLoadContext ctx, out string suffix) { // *** Binary format *** // int: id of the suffix // int: the number of input column roles // for each input column: // int: id of the column role // int: id of the column name suffix = ctx.LoadString(); var count = ctx.Reader.ReadInt32(); Contracts.CheckDecode(count >= 0); var columns = new KeyValuePair<RoleMappedSchema.ColumnRole, string>[count]; for (int i = 0; i < count; i++) { var role = ctx.LoadNonEmptyString(); var name = ctx.LoadNonEmptyString(); columns[i] = RoleMappedSchema.CreatePair(role, name); } return columns; }
protected override IEnumerable <KeyValuePair <RoleMappedSchema.ColumnRole, string> > GetInputColumnRolesCore(RoleMappedSchema schema) { foreach (var col in base.GetInputColumnRolesCore(schema)) { if (!col.Key.Equals(RoleMappedSchema.ColumnRole.Label)) { yield return(col); } else if (schema.Schema.TryGetColumnIndex(col.Value, out int labelIndex)) { yield return(col); } } if (_calculateDbi) { string feat = EvaluateUtils.GetColName(_featureCol, schema.Feature, DefaultColumnNames.Features); if (!schema.Schema.TryGetColumnIndex(feat, out int featCol)) { throw Host.ExceptUserArg(nameof(Arguments.FeatureColumn), "Features column '{0}' not found", feat); } yield return(RoleMappedSchema.CreatePair(RoleMappedSchema.ColumnRole.Feature, feat)); } }