protected override ITransformer TrainModel(IDataView dataView) { //数字键类型列 IEstimator <ITransformer> estimator = Context.Transforms.Conversion.MapValueToKey(LabelField, nameof(GitHubIssue.Area)); var fields = new[] { nameof(GitHubIssue.Title), nameof(GitHubIssue.Description) }; var features = new List <string>(); //特征列 foreach (var field in fields) { var featureField = $"{field}Featurized"; estimator = estimator.Append(Context.Transforms.Text.FeaturizeText(featureField, field)); features.Add(featureField); } //合并特征列 estimator = estimator.Append(Context.Transforms.Concatenate(FeaturesField, features.ToArray())); //缓存数据视图 estimator = estimator.AppendCacheCheckpoint(Context); //添加训练算法 estimator = estimator .Append(Context.MulticlassClassification.Trainers.SdcaMaximumEntropy()) .Append(Context.Transforms.Conversion.MapKeyToValue(PredictedLabelField)); Console.WriteLine("=============== Create and Train the Model ==============="); var model = estimator.Fit(dataView); Console.WriteLine("=============== End of training ==============="); return(model); }
private IEstimator <ITransformer> SetUpLearningModel() { // transform your data IEstimator <ITransformer> pipeLine = dotNetMachineLearningContext.Transforms.Conversion.MapValueToKey("Label"); pipeLine = pipeLine.Append(dotNetMachineLearningContext.Transforms.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); pipeLine = pipeLine.AppendCacheCheckpoint(dotNetMachineLearningContext); //// add a learner //// Add a learning algorithm to the pipeline. e.g.(What type of iris is this?) //// Assign numeric values to text in the "Label" column, //// because only numbers can be processed during model training. pipeLine = pipeLine.Append(dotNetMachineLearningContext.MulticlassClassification.Trainers.SdcaMaximumEntropy(labelColumnName: "Label", featureColumnName: "Features")); //// Convert the Label back into original text (after converting to number in step 3) pipeLine = pipeLine.Append(dotNetMachineLearningContext.Transforms.Conversion.MapKeyToValue("PredictedLabel")); return(pipeLine); }
private IEstimator <ITransformer> SetUpLearningModel() { // transform your data IEstimator <ITransformer> pipeLine = dotNetMachineLearningContext.Transforms.Conversion.MapValueToKey("WeekDay"); pipeLine = pipeLine.Append(dotNetMachineLearningContext.Transforms.Concatenate("Features", "Temp", "RH")); // add a learner pipeLine = pipeLine.AppendCacheCheckpoint(dotNetMachineLearningContext); // Add a learning algorithm to the pipeline. // Assign numeric values to text in the labeled column, // because only numbers can be processed during model training. pipeLine = pipeLine.Append(dotNetMachineLearningContext.MulticlassClassification.Trainers.SdcaMaximumEntropy(labelColumnName: "WeekDay", featureColumnName: "Features")); // Convert the Label back into original text (after converting to number in step 3) pipeLine = pipeLine.Append(dotNetMachineLearningContext.Transforms.Conversion.MapKeyToValue( outputColumnName: "PredictedLabel", inputColumnName: "WeekDay")); return(pipeLine); }