Beispiel #1
0
 /// <summary>
 /// Starts the train session.
 /// </summary>
 /// <param name="ignoreMetricThreshold">if set to <c>true</c> ignore metric threshold on applying model
 /// instance.</param>
 /// <returns>
 /// New train session identifier.
 /// </returns>
 public Guid StartTrainSession(bool ignoreMetricThreshold = false)
 {
     try {
         Select trainingSelectQuery = BuildTrainingSelectQuery();
         var    modelValidator      = ClassFactory.Get <IMLModelValidator>();
         modelValidator.CheckColumns(trainingSelectQuery);
         modelValidator.CheckSqlQuery(trainingSelectQuery);
         string outputColumnName = GetMetadataOutputName() ?? DefaultOutputColumnAlias;
         ModelSchemaMetadata modelSchemaMetadata = _metadataGenerator.GenerateMetadata(trainingSelectQuery,
                                                                                       _modelConfig.MetaData, outputColumnName);
         MergeFitParams(modelSchemaMetadata, _modelConfig);
         Guid sessionId = _proxy.StartTrainSession(ServiceStackTextHelper.Serialize(modelSchemaMetadata),
                                                   _modelConfig.Id);
         SaveTrainSessionId(sessionId);
         InsertTrainSession(_modelConfig.Id, sessionId, TrainSessionState.DataTransferring,
                            ignoreMetricThreshold);
         return(sessionId);
     } catch (Exception ex) {
         _modelConfig.TrainSessionId = Guid.NewGuid();
         UpdateModelOnError(_modelConfig.Id, ex.Message);
         InsertTrainSession(_modelConfig.Id, _modelConfig.TrainSessionId, TrainSessionState.Error,
                            ignoreMetricThreshold, ex.Message);
         throw;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Sets human-readable localized captions and display values for feature weights.
        /// </summary>
        /// <param name="userConnection">The user connection.</param>
        /// <param name="features">The features.</param>
        /// <param name="modelId">The model identifier.</param>
        /// <param name="isPrediction"><c>true</c> if it's for prediction, false - for training.</param>
        public static void LocalizeFeatures(UserConnection userConnection, List <LocalizedFeatureWeight> features,
                                            Guid modelId, bool isPrediction)
        {
            IMLModelLoader loader = ClassFactory.Get <IMLModelLoader>();

            if (!loader.TryLoadModel(userConnection, modelId, out MLModelConfig model))
            {
                return;
            }
            loader.LoadModelMetadataCaptions(userConnection, model);
            var modelQueryBuilder = ClassFactory.Get <IMLModelQueryBuilder>(
                new ConstructorArgument("userConnection", userConnection));
            var query  = isPrediction ? model.BatchPredictionQuery : model.TrainingSetQuery;
            var select = modelQueryBuilder.BuildSelect(model.EntitySchemaId, query, model.ColumnExpressions);
            IMLMetadataGenerator metadataGenerator = ClassFactory.Get <IMLMetadataGenerator>();
            var metadata = metadataGenerator.GenerateMetadata(select, model.MetaData, fillColumnsInfo: true);
            var columnExpressionMapping = modelQueryBuilder.GetColumnExpressionMapping(model.EntitySchemaId,
                                                                                       query, model.ColumnExpressions);

            FillCaptions(userConnection, features, columnExpressionMapping, model.EntitySchemaId, metadata);
            FillDisplayValues(userConnection, features, columnExpressionMapping, model.EntitySchemaId, metadata);
        }