コード例 #1
0
        private static void SetPredictedResultColumnName(MLModelConfig modelConfig, UserConnection userConnection,
                                                         IDataReader reader)
        {
            if (modelConfig.PredictedResultColumnName.IsNotNullOrEmpty())
            {
                return;
            }
            Guid predictedResultColumnUId = FindValue <Guid>(reader, "PredictedResultColumnUId", Guid.Empty);

            if (predictedResultColumnUId.IsNotEmpty())
            {
                modelConfig.PredictedResultColumnName =
                    FindEntityColumnValueName(userConnection, modelConfig.EntitySchemaId, predictedResultColumnUId);
                return;
            }
            if (modelConfig.TrainingTargetColumnName.IsNotNullOrEmpty())
            {
                modelConfig.PredictedResultColumnName = modelConfig.TrainingTargetColumnName;
                return;
            }

            //TODO #CRM-40303 Remove when PredictedResultColumnUId will be set for all known customer models
            ModelSchemaMetadata metadata = modelConfig.GetModelSchemaMetadata();
            string outputName            = metadata.Output?.Name;

            if (IsEntityColumnExists(userConnection.EntitySchemaManager, modelConfig.EntitySchemaId, outputName))
            {
                _log.Warn("Neither PredictedResultColumnUId nor TargetColumnUId is set. " +
                          $"Using metadata's output as PredictedResultColumn in model {modelConfig.Id}");
                modelConfig.PredictedResultColumnName = outputName;
            }
        }
コード例 #2
0
        /// <summary>
        /// Loads the model metadata captions. Sets enriched metadata to <see cref="MLModelConfig.MetaData"/> property.
        /// </summary>
        /// <param name="userConnection">The user connection.</param>
        /// <param name="model">Loaded model.</param>
        public void LoadModelMetadataCaptions(UserConnection userConnection, MLModelConfig model)
        {
            if (model.MetaData.IsNullOrEmpty())
            {
                return;
            }
            ModelSchemaMetadata metadata = model.GetModelSchemaMetadata();

            if (metadata.Inputs.IsNullOrEmpty() && metadata.Output == null)
            {
                return;
            }
            var modelSchema = userConnection.EntitySchemaManager.GetInstanceByName("MLModel");
            var modelEntity = modelSchema.CreateEntity(userConnection);

            modelEntity.PrimaryColumnValue = model.Id;
            if (!modelEntity.FetchFromDB(new[] { "MetaDataLcz" }, false))
            {
                return;
            }
            string serializedMetadataLcz = modelEntity.GetTypedColumnValue <string>("MetaDataLcz");

            if (serializedMetadataLcz.IsNullOrEmpty())
            {
                return;
            }
            ModelSchemaMetadata metaDataLcz;

            try {
                metaDataLcz = JsonConvert.DeserializeObject <ModelSchemaMetadata>(serializedMetadataLcz);
            } catch (Exception e) {
                _log.Warn($"Can't localize metadata for {model.Id}, because MetaDataLcz has incorrect format: " +
                          serializedMetadataLcz, e);
                return;
            }
            metadata.Inputs?.ForEach(input => {
                var inputLcz = metaDataLcz.Inputs.Find(schemaInput => schemaInput.Name == input.Name);
                if (inputLcz == null)
                {
                    return;
                }
                input.Caption = inputLcz.Caption;
            });
            if (metadata.Output != null)
            {
                metadata.Output.Caption = metaDataLcz.Output?.Caption;
            }
            model.MetaData = JsonConvert.SerializeObject(metadata, Formatting.Indented);
        }
コード例 #3
0
 private string GetMetadataOutputName()
 {
     return(_modelConfig.GetModelSchemaMetadata().Output?.Name);
 }