I was trying to use ML.NET to do some simple linear regression test using a small dataset (760 items) but when I am calling Fit() to get a transformer it throws an eror "Column 'Time' has values of DateTime, which is not the same as earlier observed type of Single. "
as if the function confused the type of each column in the csv?
the code
public class PriceData
{
[ColumnName("Time")]
[LoadColumn(0)]
public DateTime Time;
[ColumnName("ClosePrice")]
[LoadColumn(1)]
public float ClosePrice;
}
public class DemandPrediction
{
[ColumnName("Score")]
public float ApproximationScore;
}
static string URL = "https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=USD-BTC&tickInterval=day";
public static void Main(string[] args)
{
try
{
List<PriceData> priceData = new List<PriceData>();
DownloadData(URL,ref priceData);
var context = new MLContext();
var data = context.Data.LoadFromTextFile<PriceData>("data.csv",hasHeader:false,separatorChar:',');
var pipeline = context.Transforms.Concatenate(outputColumnName:"PriceData",
nameof(PriceData.Time),
nameof(PriceData.ClosePrice)
).AppendCacheCheckpoint(context);
var trainerType = context.Regression.Trainers.OnlineGradientDescent(lossFunction: new TweedieLoss());
var fullPipeline = pipeline.Append(trainerType);
var model = pipeline.Fit(data);
var predictions = model.Transform(data);
var metrics = context.Regression.Evaluate(
data: predictions,
labelColumnName: "ClosePrice",
scoreColumnName: "Score");
var sample = new PriceData { Time =Convert.ToDateTime("7/6/2020 12:00:00 AM"), ClosePrice = 9273.18f };
// create a prediction engine
var engine = context.Model.CreatePredictionEngine<PriceData, DemandPrediction>(model);
// make the prediction
var prediction = engine.Predict(sample);
Console.ReadKey();
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
}```