How to predict multiple labels with ML.NET using regression task?

前端 未结 1 1093
无人共我
无人共我 2021-01-20 17:31

I\'m very new to machine learning and I\'ve stumbled upon the following problem. Considering an official NYC Taxi fare amount prediction tutorial, let\'s say I\'d like to pr

相关标签:
1条回答
  • 2021-01-20 18:31

    Probably it's not working, because Fit() only returns "Label" and "Score"

    Look here: here

    Your Score from "TripTime" is overwritten by "FareAmount".

    I guess, you have to build two models.

    edited: you can try this. Copy "Score" to the right place.

    public class TripFarePrediction // this class is used to store prediction result
    {
        [ColumnName("fareAmount")]
        public float FareAmount { get; set; }
    
        [ColumnName("tripTime")]
        public float TripTime { get; set; }
    }
    
    
    private static ITransformer Train(MLContext mlContext, string trainDataPath)
    {
        IDataView dataView = _textLoader.Read(trainDataPath);
        var pipelineForTripTime = mlContext.Transforms.CopyColumns("Label", "TripTime")
        .Append(mlContext.Transforms.Categorical.OneHotEncoding("VendorId"))
        .Append(mlContext.Transforms.Categorical.OneHotEncoding("RateCode"))
        .Append(mlContext.Transforms.Categorical.OneHotEncoding("PaymentType"))
        .Append(mlContext.Transforms.Concatenate("Features", "VendorId", "RateCode", "PassengerCount", "TripDistance", "PaymentType"))
        .Append(mlContext.Regression.Trainers.FastTree())
        .Append(mlContext.Transforms.CopyColumns(outputcolumn: "tripTime", inputcolumn: "Score"));
    
        var pipelineForFareAmount = mlContext.Transforms.CopyColumns("Label", "FareAmount")
        .Append(mlContext.Transforms.Categorical.OneHotEncoding("VendorId"))
        .Append(mlContext.Transforms.Categorical.OneHotEncoding("RateCode"))
        .Append(mlContext.Transforms.Categorical.OneHotEncoding("PaymentType"))
        .Append(mlContext.Transforms.Concatenate("Features", "VendorId", "RateCode", "PassengerCount", "TripDistance", "PaymentType"))
        .Append(mlContext.Regression.Trainers.FastTree())
        .Append(mlContext.Transforms.CopyColumns(outputcolumn: "fareAmount", inputcolumn: "Score"));
    
    
    
        var model = pipelineForTripTime.Append(pipelineForFareAmount).Fit(dataView);
        SaveModelAsFile(mlContext, model);
        return model;
    }
    
    0 讨论(0)
提交回复
热议问题