I have tried the below code snippet in a .NET console app and able to see the forecasted predictions.
var context = new MLContext();
DatabaseLoader loader = context.Data.CreateDatabaseLoader<TimeSeriesInput>();
Entities db = new Entities();
string query = "select cast([Date] as datetime) [Timestamp],cast(Energy as real) [Data] from _energy_hourly_for_ml";
var mldata = db.Database.SqlQuery<TimeSeriesInput>(query).AsEnumerable();
var data = context.Data.LoadFromEnumerable(mldata);
//_energy_hourly_for_ml : new table
var pipeline = context.Forecasting.ForecastBySsa(
nameof(TimeSeriesOutput.Forecast),
nameof(TimeSeriesInput.Data),
windowSize: 5,
seriesLength: 10,
trainSize: 100,
horizon: 4); //no of next set of output predictions
var model = pipeline.Fit(data);
var forecastingEngine = model.CreateTimeSeriesEngine<TimeSeriesInput, TimeSeriesOutput>(context);
var forecasts = forecastingEngine.Predict();
Now I want to save entire above code in database. What I want to do is:
fetch the above code from database
execute it dynamically
fetch the forecasted predictions as output from previous step execution
display it on the view
Let me know for any ref pointers on this please.
I am using c# AutoML to train a model for Regression and i cant see the Rsquared or MeanError for any of the algorithms
//loading train data through Text Loader
var trainData = loader.Load(_filePath);
Console.WriteLine("created train data");
var settings = new RegressionExperimentSettings
{
MaxExperimentTimeInSeconds = 10,
//OptimizingMetric = RegressionMetric.MeanAbsoluteError
};
var progress = new Progress<RunDetail<RegressionMetrics>>(p =>
{
if (p.ValidationMetrics != null)
{
Console.WriteLine($"Current Result - {p.TrainerName}, {p.ValidationMetrics.RSquared}, {p.ValidationMetrics.MeanAbsoluteError}");
}
});
var experiment = context.Auto().CreateRegressionExperiment(settings);
//find best model
var labelColumnInfo = new ColumnInformation()
{
LabelColumnName = "median_house_value"
};
var result = experiment.Execute(trainData, labelColumnInfo, progressHandler: progress);
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Best run:");
Console.WriteLine($"Trainer name - {result.BestRun.TrainerName}");
Console.WriteLine($"RSquared - {result.BestRun.ValidationMetrics.RSquared}");
Console.WriteLine($"MAE - {result.BestRun.ValidationMetrics.MeanAbsoluteError}");
Console.ReadLine();
When i run the console application the outputs i get are 0 -infinite or not a number
I've gotten similar results when my dataset has been too small.
AutoML is using 10 fold cross validation if I recall correctly. This can lead to the test data set being too small to get any usable metrics out of it.
So if your dataset is small, you could try with a bigger one and see if it gets better metrics, at least to rule out that case.
I use an e-commerce SOAP API, forgive me if it's too confusing to answer. I just want to know if I'm just making a stupid mistake before I write a ticket to API maintainers.
public void WriteXML()
{
var results = GetProductsFromApi().results.ToList();
using (var file = File.Create(#"products.xml"))
{
var list = new List<Product>();
var writer = new XmlSerializer(typeof(List<Product>));
foreach (var result in results)
{
var newProduct = new Product
{
Id = result.productId,
Index = result.productDisplayedCode,
Stock = result.productStocksData.productStocksQuantities[0].productSizesData[0].productSizeQuantity,
IsIgnored = false,
IsInDelivery = false
};
list.Add(newProduct);
}
writer.Serialize(file, list);
}
}
I made a request to the API and I want to store it in a list, so each result gets serialized into an XML later. The code above works if I set Stock to something like Stock = 1, - however if left as it is, the program quits with Unhandled exception: System.IndexOutOfRangeException.
What's weird though is that if I do something similar to the following before building the Product object:
Console.WriteLine(result.productStocksData.productStocksQuantities[0].productSizesData[0].productSizeQuantity);
...I am met with a correct API response.
I have no clue what's going on. I tried checking if the result is null before constructing Product, but it didn't help. The whole exception is so confusing to me I don't really know where to start looking.
Edit: Using Fildor's proposed code, I wrote this:
float? lol = result.productStocksData.productStocksQuantities.FirstOrDefault().productSizesData.FirstOrDefault()?.productSizeQuantity ?? null; //doesn't actually change anything if it's null or 0
if (lol.GetValueOrDefault() == 0) {
lol = 1;
};
var newProduct = new Product
{
Id = result.productId,
Index = result.productDisplayedCode,
Stock = (float)lol,
IsIgnored = false,
IsInDelivery = false
};
Console.WriteLine("Processed product has a stock of " + lol);
list.Add(newProduct);
It now results in System.NullReferenceException. It responds with actual stock size, and said error appears after.
I have the following code in ML.NET which reads historic football matches odds and results and the tries to predict result based on passed odds but the prediction is disappointing and every time it gives different prediction even if I use the exact same data.
public ResultPrediction Start()
{
var dbData = matchDetailsRepository.GetOdds(string.Empty);
if (dbData.Count == 0)
return null;
//Create ML Context with seed for repeteable/deterministic results
MLContext mlContext = new MLContext(seed: 0);
IDataView data = mlContext.Data.LoadFromEnumerable<FullTimeOddsData>(dbData.ToFullTimeOddsDataList());
var pipeline = mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: "Result")
.Append(mlContext.Transforms.Concatenate("Features", "HomeWinOdd", "DrawOdd", "AwayWinOdd"));
// Define StochasticDualCoordinateAscent regression algorithm estimator
var sdcaEstimator = pipeline.Append(mlContext.Regression.Trainers.Sdca(labelColumnName: "Label", featureColumnName: "Features"));
// Build machine learning model
TransformerChain<RegressionPredictionTransformer<LinearRegressionModelParameters>> trainedModel = sdcaEstimator.Fit(data);
// Create PredictionEngines
PredictionEngine<FullTimeOddsData, ResultPrediction> predictionEngine = mlContext.Model.CreatePredictionEngine<FullTimeOddsData, ResultPrediction>(trainedModel);
// Input Data
FullTimeOddsData inputData = new FullTimeOddsData
{
HomeWinOdd = 19F,
DrawOdd = 10F,
AwayWinOdd = 1.14F,
};
// Get Prediction
ResultPrediction prediction = predictionEngine.Predict(inputData);
return prediction;
}
public class ResultPrediction
{
[ColumnName("Score")]
public float Prediction;
}
public class FullTimeOddsData
{
public float HomeWinOdd;
public float DrawOdd;
public float AwayWinOdd;
public float Result;
}
What is the problem here which gives different prediction using the same data and what am I doing wrong to give wrong prediction. Based on the input data the prediction must be 1 or near 1
Sample data below:
HomeWinOdd,DrawOdd,AwayWinOdd,Result
2.2,3.5,2.5,2
2,3,2.9,2
2.05,3.4,2.95,2
2,3.4,2.9,2
2,3.6,2.65,3
2.1,3,2.8,3
2.3,3.4,2.55,3
2.4,3.3,2.4,3
2.3,3.3,2.45,3
2.35,3,2.35,3
2.45,3.4,2.4,3
2.4,3.3,2.4,3
1.9,3.3,3.5,1
1.8,3,3.5,1
1.85,3.4,3.5,1
1.41,4.1,4.7,1
1.75,3.1,3.6,1
1.6,3.5,4.5,1
1.61,3.6,4.2,1
Result = 1 means Home wins
Result = 2 means Away wins
Result = 3 means Draw
i need to give statistic about my publisher app
like how many subscribers are there?
i cant seen to get that information from the redis server
i already tried to find in the 'ServiceStack.Redis.RedisSubscription'
i found this:
var channel = ConfigurationManager.AppSettings["redis_channel"];
var _redisClient = new RedisClient("localhost", 6379);
var subscription = _redisClient.CreateSubscription();
//subscription.SubscribeToChannels(channel);
var subscription_count = (int)subscription.SubscriptionCount
but it returning 0 every time.
any ideas?
edit:
i found this http://redis.io/commands/client-list
but steel need some help on how to use it
thanks : )
i got it!
if anyone need that's i did:
var redis_ip = ConfigurationManager.AppSettings["redis_server_ip"];
var redis_port = ConfigurationManager.AppSettings["redis_server_port"];
int redis_port_int = 0;
if (!int.TryParse(redis_port, out redis_port_int))
{
redis_port_int = 6739;
}
RedisNativeClient rnClient = new RedisNativeClient(redis_ip, redis_port_int);
var clientlist_byte = rnClient.ClientList();
var clientlist_string = Encoding.UTF8.GetString(clientlist_byte);
var clientamount_double = clientlist_string.Split("\n".ToCharArray()).Length;
var clientlist_int = (clientamount_double/2) - 1;
return clientlist_int;
the '-1' is to remove my selt from the count,
the /2 it's because after the split i get a doubled amount