dotnet / dotnet/machinelearning-samples

The prediction of taxiTripSample dont work

Offen
#545 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
PowerShell
Sterne
4.7k
Forks
2.7k
Ø Merge
2 T. 22 Std.
Gemergte PRs (30 T.)
1

Beschreibung

https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/predict-prices

Goal:
Predict that you retrieve the value 15.5 based on the instruction

```
var taxiTripSample = new TaxiTrip()
{
VendorId = "VTS",
RateCode = "1",
PassengerCount = 1,
TripTime = 1140,
TripDistance = 3.75f,
PaymentType = "CRD",
FareAmount = 0 // To predict. Actual/Observed = 15.5
};

Problem:
When I do the prediction based on the data above, I get value 0 for the FareAmount after the prediction process.

What part am I missing from the source code?

Info:
*I have used the data from the link
https://github.com/dotnet/machinelearning/blob/master/test/data/taxi-fare-train.csv

Thank you!
```

```

//*****************************************************************************************
//* *
//* This is an auto-generated file by Microsoft ML.NET CLI (Command-Line Interface) tool. *
//* *
//*****************************************************************************************

using System;
using System.IO;
using System.Linq;
using Microsoft.ML;
using Machinelearning_test2ML.Model.DataModels;
using machinelearning_test2ML.ConsoleApp;

namespace Machinelearning_test2ML.ConsoleApp
{
class Program
{
//Machine Learning model to load and use for predictions
private const string MODEL_FILEPATH = @"MLModel.zip";

//Dataset to use for predictions
private const string DATA_FILEPATH = @"C:{ }";

static void Main(string[] args)
{
MLContext mlContext = new MLContext();

// Training code used by ML.NET CLI and AutoML to generate the model
//ModelBuilder.CreateModel();

ITransformer mlModel = mlContext.Model.Load(GetAbsolutePath(MODEL_FILEPATH), out DataViewSchema inputSchema);
var predEngine = mlContext.Model.CreatePredictionEngine(mlModel);

// Create sample data to do a single prediction with it
ModelInput sampleData = CreateSingleDataSample(mlContext, DATA_FILEPATH);

// Try a single prediction
ModelOutput predictionResult = predEngine.Predict(sampleData);

Console.WriteLine($"Single Prediction --> Actual value: {sampleData.Fare_amount} | Predicted value: {predictionResult.Score}");

//------------

IDataView dataView = mlContext.Data.LoadFromTextFile(DATA_FILEPATH, hasHeader: true, separatorChar: ',');
var pipeline = mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: "FareAmount");

var model = pipeline.Fit(dataView);

var predictionFunction = mlContext.Model.CreatePredictionEngine(model);

var taxiTripSample = new TaxiTrip()
{
VendorId = "VTS",
RateCode = "1",
PassengerCount = 1,
TripTime = 1140,
TripDistance = 3.75f,
PaymentType = "CRD",
FareAmount = 0 // To predict. Actual/Observed = 15.5
};

var prediction = predictionFunction.Predict(taxiTripSample);

//------------------

Console.WriteLine("=============== End of process, hit any key to finish ===============");
Console.ReadKey();
}

// Method to load single row of data to try a single prediction
// You can change this code and create your own sample data here (Hardcoded or from any source)
private static ModelInput CreateSingleDataSample(MLContext mlContext, string dataFilePath)
{
// Read dataset to get a single row for trying a prediction
IDataView dataView = mlContext.Data.LoadFromTextFile(
path: dataFilePath,
hasHeader: true,
separatorChar: '\t',
allowQuoting: true,
allowSparse: false);

// Here (ModelInput object) you could provide new test data, hardcoded or from the end-user application, instead of the row from the file.
ModelInput sampleForPrediction = mlContext.Data.CreateEnumerable(dataView, false)
.First();
return sampleForPrediction;
}

public static string GetAbsolutePath(string relativePath)
{
FileInfo _dataRoot = new FileInfo(typeof(Program).Assembly.Location);
string assemblyFolderPath = _dataRoot.Directory.FullName;

string fullPath = Path.Combine(assemblyFolderPath, relativePath);

return fullPath;
}
}
}

```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginnen Sie im gezeigten Program.Main-Code und vergleichen Sie das Taxi-Tarif-Tutorial mit test/data/taxi-fare-train.csv. Konzentrieren Sie sich dabei auf die vor der Vorhersage verwendete Pipeline. Reproduzieren Sie die Vorhersage von taxiTripSample und überprüfen Sie, dass das abgeschlossene Sample den erwarteten FareAmount von 15.5 statt 0 erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, machine-learning
Bereich
machine-learning
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.