public ModelData CreateModel(string userId, string name, int supportThreshhold, int maxItemSetSize) { // Create a new model var model = new ModelData() { PartitionKey = userId, RowKey = name, MaxItemSetSize = maxItemSetSize, SupportThreshhold = supportThreshhold, Status = "No Training Data" }; // insert the entity and return it if successfull return tableClient.InsertEntity(ModelTableName, model) ? model : null; }
public bool UpdateModel(ModelData model) { // insert the entity and return it if successfull return tableClient.UpdateEntity(ModelTableName, model); }
public void TrainModel(ModelData model) { // How the model will be identified in Cloud ML var modelIdentifier = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 24);//userId + "-" + modelName; // HACK: temporary workaround issue of webservices failing after 12 hours by extending lease time to 1 year // The fix will be to have a seperate scoring experiment string dataReadUrl = modelProvider.GetTemporaryDataFileReadUrl(model.DataFileBlobName, TimeSpan.FromHours(9000)); // Run the training experiment var request = new BatchRequest() { GlobalParameters = new Dictionary <string, string>() }; request.GlobalParameters["URL"] = dataReadUrl; request.GlobalParameters["MaxItemSetSize"] = model.MaxItemSetSize.ToString(); request.GlobalParameters["SupportThreshhold"] = model.SupportThreshhold.ToString(); request.GlobalParameters["NumberofSets"] = "1"; var trainingJobId = trainingEndpoint.SubmitBatch(request).Result; UpdateModelStatus("Training the Model", m => m.ExperimentId = trainingJobId); // wait for it to finish var currentStatus = WaitForCompletion(trainingJobId); // if it failed stop if (currentStatus.StatusCode != BatchScoreStatusCode.Finished) { UpdateModelStatus("Error Building Training Model: " + currentStatus.StatusCode + currentStatus.Details); return; } var trainedModel = currentStatus.Results["TrainedModel"]; UpdateModelStatus("Training the Model"); // if this is a new endpoint then just retrain it Endpoint scoringEndpoint; if (model.WebServiceGroupId != null && model.WebServiceGroupId.Length == 24) { scoringEndpoint = new Endpoint() { ApiLocation = model.ScoringUrl, PrimaryKey = model.ScoringAccessKey, WorkspaceId = scoringWebService.WorkspaceId, WebServiceId = scoringWebService.Id, Name = model.WebServiceGroupId }; } else { // Create the scoring endpoint var epCreate = new EndpointCreate() { Description = "", MaxConcurrentCalls = 10, ThrottleLevel = ThrottleLevel.High }; scoringEndpoint = scoringWebService.CreateEndpoint(modelIdentifier, epCreate, scoringWorkspaceEndpointToken).Result; if (scoringEndpoint == null) { UpdateModelStatus("Error Creating Scoring Endpoint"); return; } } // configure it to use the trained model if (!scoringEndpoint.UpdateResource(new ResourceLocations() { Resources = new [] { new EndpointResource() { Name = "FBT Model", Location = trainedModel } } }).Result) { UpdateModelStatus("Error Configuring Scoring Endpoint"); return; } // test the scoring service ValidateScoringEndpoint(scoringEndpoint.ApiLocation, scoringEndpoint.PrimaryKey); // All Done UpdateModelStatus("Ready", m => m.ScoringUrl = scoringEndpoint.ApiLocation, m => m.WebServiceGroupId = modelIdentifier, m => m.ScoringAccessKey = scoringEndpoint.PrimaryKey, m => m.TrainingInvalidated = false, m => m.IsTraining = false, m => m.TrainingEndTime = DateTimeOffset.Now); }
private Model GetModelFromData(ModelData model) { return new Model() { Name = model.RowKey, Status = model.Status, MaxItemsSetSize = model.MaxItemSetSize, MinumumOccurrences = model.SupportThreshhold, ReadyForScoring = !string.IsNullOrEmpty(model.ScoringUrl), HasData = !string.IsNullOrEmpty(model.DataFileBlobName), NeedsTraining = model.TrainingInvalidated, IsTraining = model.IsTraining, DataUploadTime = model.DataUploadTime, TrainingStartTime = model.TrainingStartTime, TrainingEndTime = model.TrainingEndTime }; }
public bool UpdateModel(ModelData model) { // insert the entity and return it if successfull return(tableClient.UpdateEntity(ModelTableName, model)); }