zhaoxinyu
9 months ago
3 changed files with 102 additions and 15 deletions
@ -0,0 +1,78 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.ML; |
|||
using SettleAccount.Domain.BQ; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|||
{ |
|||
public class ML_MNG |
|||
{ |
|||
private readonly INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> _canRepository; |
|||
private readonly INormalEfCoreRepository<PUB_SA_DETAIL, Guid> _saRepository; |
|||
public ML_MNG( |
|||
INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> canRepository, |
|||
INormalEfCoreRepository<PUB_SA_DETAIL, Guid> saRepository |
|||
) |
|||
{ |
|||
_canRepository = canRepository; |
|||
_saRepository = saRepository; |
|||
} |
|||
//public async Task Load(string p_load)
|
|||
//{
|
|||
// var mlContext = new MLContext();
|
|||
// mlContext.Regression.Trainers.OnlineGradientDescent
|
|||
// var trainer = mlContext.Regression.Trainers.FastTreeTweedie(labelColumnName: "Label", featureColumnName: "Features");
|
|||
// var trainingPipeline = mlContext.Transforms.Concatenate(outputColumnName: "NumFeatures", nameof(ProductData.year), nameof(ProductData.month), nameof(ProductData.units), nameof(ProductData.avg), nameof(ProductData.count),
|
|||
// nameof(ProductData.max), nameof(ProductData.min), nameof(ProductData.prev))
|
|||
// .Append(mlContext.Transforms.Categorical.OneHotEncoding(outputColumnName: "CatFeatures", inputColumnName: nameof(ProductData.productId)))
|
|||
// .Append(mlContext.Transforms.Concatenate(outputColumnName: "Features", "NumFeatures", "CatFeatures"))
|
|||
// .Append(mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: nameof(ProductData.next)))
|
|||
// .Append(trainer);
|
|||
// var crossValidationResults = mlContext.Regression.CrossValidate(data: trainingDataView, estimator: trainingPipeline, numberOfFolds: 6, labelColumnName: "Label");
|
|||
// //ConsoleHelper.PrintRegressionFoldsAverageMetrics(trainer.ToString(), crossValidationResults);
|
|||
// var model = trainingPipeline.Fit(trainingDataView);
|
|||
//}
|
|||
|
|||
//public Task LoadSampleAsync(string name) {
|
|||
|
|||
// //// MLContext mlContext = new MLContext();
|
|||
// ////var mlContext = new MLContext(seed: 0);
|
|||
// ////IDataView data1View = mlContext.Data.LoadFromTextFile<ModelInput>(_data1Path, separatorChar: ',', hasHeader: false);
|
|||
// ////IDataView data2View = mlContext.Data.LoadFromTextFile<ModelInput>(_data2Path, separatorChar: ',', hasHeader: false);
|
|||
// //var ls=_canRepository.ToList();
|
|||
// //var mlContext = new MLContext(seed: 0);
|
|||
|
|||
// //// Load data
|
|||
// //IDataView data = mlContext.Data.lo
|
|||
|
|||
|
|||
// // LoadFromTextFile<HouseData>("house-prices.csv", hasHeader: true, separatorChar: ',');
|
|||
|
|||
// //// Define pipeline
|
|||
|
|||
|
|||
|
|||
// //var pipeline = mlContext.Transforms.Concatenate("Features", new[] { "Size" })
|
|||
// // .Append(mlContext.Regression.Trainers.LbfgsPoissonRegression());
|
|||
|
|||
// //// Train model
|
|||
// //var model = pipeline.Fit(data);
|
|||
|
|||
// //// Make prediction
|
|||
// //var predictionEngine = mlContext.Model.CreatePredictionEngine<HouseData, Prediction>(model);
|
|||
// //var house = new HouseData() { Size = 1500 };
|
|||
// //var prediction = predictionEngine.Predict(house);
|
|||
|
|||
// //Console.WriteLine($"Predicted price for a house with size {house.Size}: {prediction.Price}");
|
|||
|
|||
|
|||
//}
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue