private static void UseModelWithSingleItem(MLContext mlContext, ITransformer model) { //PredictionEngine<SentimentData, SentimentPrediction> predictionFunction = model.CreatePredictionEngine<SentimentData, SentimentPrediction>(mlContext); PredictionEngine <TrabajoPlanificadoPropuestaData, TrabajoPlanificadoPrediction> predictionFunction = model.CreatePredictionEngine <TrabajoPlanificadoPropuestaData, TrabajoPlanificadoPrediction>(mlContext); TrabajoPlanificadoPropuestaData sampleStatement = new TrabajoPlanificadoPropuestaData(); var resultprediction = predictionFunction.Predict(sampleStatement); Console.WriteLine(); Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ==============="); Console.WriteLine(); //Console.WriteLine($"Sentiment: {sampleStatement.SentimentText} | Prediction: {(Convert.ToBoolean(resultprediction.Prediction) ? "Positive" : "Negative")} | Probability: {resultprediction.Probability} "); Console.WriteLine("=============== End of Predictions ==============="); Console.WriteLine(); }
public static TrainCatalogBase.TrainTestData LoadData(MLContext mlContext) { //IDataView dataView = mlContext.Data.LoadFromTextFile<SentimentData>(_dataPath, hasHeader: false); //TrainCatalogBase.TrainTestData splitDataView = mlContext.BinaryClassification.TrainTestSplit(dataView, testFraction: 0.2); var database = client.GetDatabase("Energy"); //var collectionTP = database.GetCollection<BsonDocument>("Resultado.TrabajosPlanificadosPropuestas"); var collection = database.GetCollection <TrabajoPlanificadoMongo>("TrabajoPlanificado"); var documents = collection.Find <TrabajoPlanificadoMongo>(new BsonDocument()).ToList(); var TPdata = new List <TrabajoPlanificadoPropuestaData>(); int vcount = 0; //TrabajoPlanificado foreach (var document in documents) { var rowSet = new List <TrabajoPlanificadoPropuestaData>(); var row = new TrabajoPlanificadoPropuestaData(); bool hasValorable = false; //Resultado.Propuestas foreach (var propuesta in document.Resultado.TrabajosPlanificadosPropuestas) { //Horas por Propuesta for (DateTime i = propuesta.FechaHoraInicio; i < propuesta.FechaHoraFin; i = i.AddHours(1)) { decimal value = 0; if (document.Resultado.PrevisionPreciosPorFechaHora.TryGetValue(i, out value)) { row.PrevisionPreciosPorFechaHora += (float)value; } else { row.PrevisionPreciosPorFechaHora += (float)value; } document.Resultado.CostesOperacionPorFechaHora.TryGetValue(i, out value); row.CostesOperacionPorFechaHora += (float)value; document.Resultado.PrevisionProduccionPorFechaHora.TryGetValue(i, out value); row.PrevisionProduccionPorFechaHora += (float)value; document.Resultado.RetribucionesPorFechaHora.TryGetValue(i, out value); row.RetribucionesPorFechaHora += (float)value; } row.Valorable = propuesta.Valorable; if (propuesta.Valorable) { hasValorable = true; vcount++; } rowSet.Add(row); } //Idea: Dont add propuestas that have time ranges out of the range of the measurements //Idea: Only add propuestas that have a valorable member in their result set. //Idea: because each instalation has different predictors available, train a different model per instalation if (hasValorable) { TPdata = TPdata.Concat(rowSet).ToList(); } } IDataView dataView = mlContext.Data.LoadFromEnumerable(TPdata); Console.WriteLine("PropuestaSets with valorable menbers: {0}", TPdata.Count()); Console.WriteLine("Propuestas of valorable label: {0}", vcount); TrainCatalogBase.TrainTestData splitDataView = mlContext.BinaryClassification.TrainTestSplit(dataView, testFraction: 0.25); return(splitDataView); }