Exemplo n.º 1
0
        /// <summary>
        /// Trigger a recommendation build for the given model.
        /// Note: unless configured otherwise the u2i (user to item/user based) recommendations are enabled too.
        /// </summary>
        /// <param name="modelId">the model id</param>
        /// <param name="buildDescription">a description for the build</param>
        /// <param name="operationLocationHeader">operation location header, can be used to cancel the build operation and to get status.</param>
        /// <returns>Unique indentifier of the build initiated.</returns>
        public long CreateFbtBuild(string modelId, string buildDescription, bool enableModelInsights, out string operationLocationHeader)
        {
            // only used if splitter strategy is set to RandomSplitter
            var randomSplitterParameters = new RandomSplitterParameters()
            {
                RandomSeed  = 0,
                TestPercent = 10
            };

            var parameters = new FbtBuildParameters()
            {
                MinimalScore             = 0,
                SimilarityFunction       = FbtSimilarityFunction.Lift,
                SupportThreshold         = 3,
                MaxItemSetSize           = 2,
                EnableModelingInsights   = enableModelInsights,
                SplitterStrategy         = SplitterStrategy.LastEventSplitter,
                RandomSplitterParameters = randomSplitterParameters,
            };

            var requestInfo = new BuildRequestInfo()
            {
                BuildType       = BuildType.Fbt,
                BuildParameters = new BuildParameters()
                {
                    Fbt = parameters,
                },
                Description = buildDescription
            };

            return(BuildModel(modelId, requestInfo, out operationLocationHeader));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Submit a model build, with passed build parameters.
        /// </summary>
        /// <param name="modelId">Unique identifier of the model</param>
        /// <param name="buildRequestInfo">Build parameters</param>
        /// <param name="operationLocationHeader">Build operation location</param>
        /// <returns>The build id.</returns>
        public long BuildModel(string modelId, BuildRequestInfo buildRequestInfo, out string operationLocationHeader)
        {
            string uri        = BaseUri + "/models/" + modelId + "/builds";
            var    response   = _httpClient.PostAsJsonAsync(uri, buildRequestInfo).Result;
            var    jsonString = response.Content.ReadAsStringAsync().Result;

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(String.Format("Error {0}: Failed to start build for model {1}, \n reason {2}",
                                                  response.StatusCode, modelId, ExtractErrorInfo(response)));
            }

            operationLocationHeader = response.Headers.GetValues("Operation-Location").FirstOrDefault();
            var buildModelResponse = JsonConvert.DeserializeObject <BuildModelResponse>(jsonString);

            return(buildModelResponse.BuildId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Trigger a recommendation build for the given model.
        /// Note: unless configured otherwise the u2i (user to item/user based) recommendations are enabled too.
        /// </summary>
        /// <param name="modelId">the model id</param>
        /// <param name="buildDescription">a description for the build</param>
        /// <param name="enableModelInsights"> true to enable modeling insights, selects "LastEventSplitter" as the splitting strategy by default. </param>
        /// <param name="operationLocationHeader">operation location header, can be used to cancel the build operation and to get status.</param>
        /// <returns>Unique indentifier of the build initiated.</returns>
        public long CreateRecommendationsBuild(string modelId,
                                               string buildDescription,
                                               bool enableModelInsights,
                                               out string operationLocationHeader)
        {
            // only used if splitter strategy is set to RandomSplitter
            var randomSplitterParameters = new RandomSplitterParameters()
            {
                RandomSeed  = 0,
                TestPercent = 10
            };

            var parameters = new RecommendationBuildParameters()
            {
                NumberOfModelIterations  = 10,
                NumberOfModelDimensions  = 20,
                ItemCutOffLowerBound     = 1,
                EnableModelingInsights   = enableModelInsights,
                SplitterStrategy         = SplitterStrategy.LastEventSplitter,
                RandomSplitterParameters = randomSplitterParameters,
                EnableU2I              = true,
                UseFeaturesInModel     = false,
                AllowColdItemPlacement = false,
            };

            var requestInfo = new BuildRequestInfo()
            {
                BuildType       = BuildType.Recommendation,
                BuildParameters = new BuildParameters()
                {
                    Recommendation = parameters
                },
                Description = buildDescription
            };

            return(BuildModel(modelId, requestInfo, out operationLocationHeader));
        }