Я пытаюсь реализовать ML , и вот пример:
- 3 значения переменных
- одно значение результата в зависимости от других значений
Тестовые данные вводятся одинаково, поэтому они должны возвращать одинаковые значения
Всегда возвращает 0 для countConnectors.CountConnectors
Я что-то забыл?
Код:
public class Balcony
{
public float A { get; set; }
public float L { get; set; }
public float HB { get; set; }
public float CountConnectors { get; set; }
}
public class PredictionConnectors
{
[ColumnName("Count")]
public float CountConnectors { get; set; }
}
static void Main(string[] args)
{
MLContext mlContext = new MLContext();
Balcony[] balconyData = {
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
new Balcony() { A = 500F, L = 180F, HB = 20F, CountConnectors = 10F },
};
IDataView trainingData = mlContext.Data.LoadFromEnumerable(balconyData);
var pipeline = mlContext.Transforms.Concatenate("Features", "A", "L", "HB")
.Append(mlContext.Regression.Trainers.Sdca(labelColumnName: "CountConnectors", maximumNumberOfIterations: 100));
var model = pipeline.Fit(trainingData);
var balcony = new Balcony() { A = 500F, L = 180F, HB = 20F };
var countConnectors = mlContext.Model.CreatePredictionEngine<Balcony, PredictionConnectors>(model).Predict(balcony);
Console.WriteLine($"Predicted A: {balcony.A}, L: {balcony.L}, HB: {balcony.HB} connectors= {countConnectors.CountConnectors} szt.");
}