dotnet / dotnet/machinelearning-samples

The prediction of taxiTripSample dont work

オープン
#545 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PowerShell
スター
4.7k
フォーク
2.7k
平均マージ
2日 22時間
マージ済み PR(30日)
1

説明

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;
}
}
}

```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

示されている Program.Main コードから始め、タクシー料金チュートリアルと test/data/taxi-fare-train.csv を比較し、予測前に使用されているパイプラインに注目してください。taxiTripSample の予測を再現し、完成した sample が 0 ではなく、期待される FareAmount 15.5 を生成することを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, machine-learning
領域
machine-learning
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。