static async Task Main(string[] args) { PredictionModel <CustData, ClusterPrediction> model = await Train(); var prediction = model.Predict(TestCustData.PredictionObj); Console.WriteLine($"Cluster: {prediction.PredictedCustId}"); Console.WriteLine($"Distances: {string.Join(" ", prediction.Distancessdfsd)}"); Console.ReadLine(); }
public static IEnumerable <(ArticleContentData, ArticleContentPrediction)> Predict(PredictionModel <ArticleContentData, ArticleContentPrediction> model, IEnumerable <ArticleContentData> dataSet) { List <ArticleContentData> result = new List <ArticleContentData>(); var predictions = model.Predict(dataSet); var response = dataSet.Zip(predictions, (data, prediction) => (data, prediction)); return(response); }
private void ValidateExamplesLightGBM(PredictionModel <SentimentData, SentimentPrediction> model) { var sentiments = GetTestData(); var predictions = model.Predict(sentiments); Assert.Equal(2, predictions.Count()); Assert.True(predictions.ElementAt(0).Sentiment); Assert.True(predictions.ElementAt(1).Sentiment); }
static void Main(string[] args) { PredictionModel <TaxiTrip, TaxiTripFarePrediction> model = Train().Result; Evaluate(model); var prediction = model.Predict(TestTrips.Trip1); Console.WriteLine("Predicted fare: {0}, actual fare: 29.5", prediction.fare_amount); }
public async Task <bool> Predicate(UsageOfLightBulbModel usageOfLightBulbModel) { // PredictionModel<UsageOfLightBulbModel, UsageOfLightBulbPredictionModel> model = await Train(); UsageOfLightBulbPredictionModel prediction = model.Predict(usageOfLightBulbModel); Console.WriteLine("Predicted fare: {0}, actual fare: 29.5", prediction.IsOn); var result = (prediction.IsOn > 0.5) ? true : false; return(result); }
public IEnumerable <(SentimentData sentiment, SentimentPrediction prediction)> Predict(IEnumerable <SentimentData> sentiments) { IEnumerable <SentimentPrediction> predictions = _model.Predict(sentiments); IEnumerable <(SentimentData sentiment, SentimentPrediction prediction)> sentimentsAndPredictions = sentiments .Zip(predictions, (sentiment, prediction) => (sentiment, prediction)) .ToList(); return(sentimentsAndPredictions); }
static async Task Main(string[] args) { PredictionModel <TaxiTrip, TaxiTripFarePrediction> model = await Train(); Evaluate(model); TaxiTripFarePrediction prediction = model.Predict(TestTrips.Trip1); Console.WriteLine("Predicted fare: {0}, actual fare: 29.5", prediction.FareAmount); }
public static void Execute() { Console.WriteLine("Executing Iris Experiment"); if (File.Exists(modelPath)) { Console.WriteLine("Using existing model"); model = PredictionModel.ReadAsync <IrisData, IrisPrediction>(modelPath).Result; } else { Console.WriteLine("Creating new model"); // STEP 2: Create a pipeline and load your data var pipeline = new LearningPipeline(); // If working in Visual Studio, make sure the 'Copy to Output Directory' // property of iris-data.txt is set to 'Copy always' pipeline.Add(new TextLoader <IrisData>(dataPath, separator: ",")); // STEP 3: Transform your data // Assign numeric values to text in the "Label" column, because only // numbers can be processed during model training pipeline.Add(new Dictionarizer("Label")); // Puts all features into a vector pipeline.Add(new ColumnConcatenator("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); // STEP 4: Add learner // Add a learning algorithm to the pipeline. // This is a classification scenario (What type of iris is this?) pipeline.Add(new StochasticDualCoordinateAscentClassifier()); // Convert the Label back into original text (after converting to number in step 3) pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "PredictedLabel" }); // STEP 5: Train your model based on the data set model = pipeline.Train <IrisData, IrisPrediction>(); model.WriteAsync(modelPath); } // STEP 6: Use your model to make a prediction // You can change these numbers to test different predictions var prediction = model.Predict(new IrisData() { SepalLength = 3.3f, SepalWidth = 1.6f, PetalLength = 1.7f, PetalWidth = 1.7f, }); Console.WriteLine($"Predicted flower type is: {prediction.PredictedLabels}"); Console.ReadLine(); }
public string Predict(SubjectData subjectData) { if (model == null) { Train(); } var prediction = model.Predict(subjectData); return(prediction.PredictedLabels); }
public static async Task BC() { PredictionModel <FoodBinaryClass, FPrediction> model = Train(); await model.WriteAsync(_modelPath); var prediction = model.Predict(binaryTest.meal); System.Diagnostics.Debug.WriteLine($"Decision: {prediction.Prediction}"); System.Diagnostics.Debug.WriteLine($"Probability: {prediction.Probability}"); System.Diagnostics.Debug.WriteLine($"Score: {prediction.Score}"); }
public static async Task <string> PredictAsync(GitHubIssue issue) { if (_model == null) { _model = await PredictionModel.ReadAsync <GitHubIssue, GitHubIssuePrediction>(ModelPath); } var prediction = _model.Predict(issue); return(prediction.Area); }
private static void Main(string[] args) { PredictionModel <IrisData, ClusterPrediction> model = Train(); model.WriteAsync(_modelPath); var prediction = model.Predict(TestIrisData.Setosa); Console.WriteLine($"Cluster: {prediction.PredictedClusterId}"); Console.WriteLine($"Distances: {string.Join(" ", prediction.Distances)}"); }
public static PredictionModel <DatosSentimiento, PrediccSentimiento> EntrenayPredice() { //Recoleccion de Datos var pipeline = new LearningPipeline(); pipeline.Add(new TextLoader <DatosSentimiento>(_rutaDatosEntrenamiento, useHeader: false, separator: "tab")); pipeline.Add(new TextFeaturizer("Features", "Texto")); pipeline.Add(new FastTreeBinaryClassifier() { NumLeaves = 5, NumTrees = 5, MinDocumentsInLeafs = 2 }); //Aprediz de arbol de decision (Regresión); //Entrenamiento PredictionModel <DatosSentimiento, PrediccSentimiento> modelo = pipeline.Train <DatosSentimiento, PrediccSentimiento>(); IEnumerable <DatosSentimiento> sentimientos = new[] { new DatosSentimiento { Texto = "This movie was very boring", Etiqueta = 0 }, new DatosSentimiento { Texto = "The movie does not have a great story to tell.", //Texto="The movie did not get my attention", Etiqueta = 0 }, new DatosSentimiento { //Texto="A super exciting and entertaining movie", Texto = "It was a very exciting from the start", Etiqueta = 1 } }; var predicciones = modelo.Predict(sentimientos); Console.WriteLine(); Console.WriteLine("Predicción de sentimientos"); Console.WriteLine("---------------------------"); var sentimientosYpredicciones = sentimientos.Zip(predicciones, (sent, predict) => (sent, predict)); foreach (var item in sentimientosYpredicciones) { Console.WriteLine($"Sentimiento: {item.sent.Texto} | Predicción: {(item.predict.Etiqueta ? "Positivo: )": "Negativo: (")}"); } Console.WriteLine(); //Evaluación del Modelo return(modelo); }
public static async Task Main(float userBMI, float userWC) { // Use the trained model to classify the user based on their details var prediction = TrainedModel.Predict(new WeightData() { BMI = userBMI, WC = userWC }); category = prediction.PredictedLabels; }
public static void Predict(PredictionModel <DiabetesData, DiabetesPrediction> model) { var lines = File.ReadAllLines(_testDataPath); List <DiabetesData> lstData = new List <DiabetesData>(); foreach (var line in lines) { string[] words = line.Split(','); foreach (var word in words) { List <DiabetesData> data = new List <DiabetesData>(); DiabetesData diabData = new DiabetesData(); //num_preg,glucose_conc,diastolic_bp,thickness,insulin,bmi,diab_pred,age,skin,diabetes // Stuck here how to proceed as I tried to assign it I get paragraphs of errors and exceptions diabData.num_preg = Convert.ToSingle(words[0]); diabData.glucose_conc = Convert.ToSingle(words[1]); diabData.diastolic_bp = Convert.ToSingle(words[2]); diabData.thickness = Convert.ToSingle(words[3]); diabData.insulin = Convert.ToSingle(words[4]); diabData.bmi = Convert.ToSingle(words[5]); diabData.diab_pred = Convert.ToSingle(words[6]); diabData.age = Convert.ToSingle(words[7]); diabData.diabetes = Convert.ToInt32(words[8]) == 1; if (new Random().Next() % 50 == 0) { lstData.Add(diabData); } } } IEnumerable <DiabetesPrediction> predictions = model.Predict(lstData); Console.WriteLine(); Console.WriteLine(" Predictions"); Console.WriteLine("---------------------"); var sentimentsAndPredictions = lstData.Zip(predictions, (diabetes, prediction) => (diabetes, prediction)); int total = sentimentsAndPredictions.Count(); int rightCount = 0, wrongCount = 0; foreach (var item in sentimentsAndPredictions) { if (item.diabetes.diabetes == item.prediction.diabetes) { Console.WriteLine($"Data: {item.diabetes.diabetes} ------ Prediction: {item.prediction.diabetes}"); } } Console.WriteLine(); }
static async Task Main(string[] args) { Console.WriteLine(Environment.CurrentDirectory); PredictionModel <NodeObject, NodePrediction> model = await Train(); //Evaluate(model); NodePrediction prediction = model.Predict(TestNode.Node1); Console.WriteLine("Predicted Node ID: {0}", prediction.NodeIdCounter); Console.ReadKey(); }
public static async Task <string> PredictAsync(GitHubIssue issue, ILogger logger, double threshold) { PredictionModel <GitHubIssue, GitHubIssuePrediction> model = await PredictionModel.ReadAsync <GitHubIssue, GitHubIssuePrediction>(ModelPath); GitHubIssuePrediction prediction = model.Predict(issue); float[] probabilities = prediction.Probabilities; float maxProbability = probabilities.Max(); logger.LogInformation($"# {maxProbability.ToString()} {prediction.Area} for #{issue.ID} {issue.Title}"); return(maxProbability > threshold ? prediction.Area : null); }
private static void Predict(PredictionModel <AgeRange, AgeRangePrediction> model, string name, float age, string gender) { var input = new AgeRange { Age = age, Name = name, Gender = gender }; var pred = model.Predict(input); Console.WriteLine($"Predicted label for Name {name}, Age {age}, Gender {gender}; is {pred.PredictedLabel}"); }
public static PredictionModel <SentimentData, SentimentPrediction> TrainAndPredict() { var pipeline = new LearningPipeline(); pipeline.Add(new TextLoader <SentimentData>(_dataPath, useHeader: false, separator: "tab")); pipeline.Add(new TextFeaturizer("Features", "SentimentText")); pipeline.Add(new FastTreeBinaryClassifier() { NumLeaves = 5, NumTrees = 5, MinDocumentsInLeafs = 2 }); IEnumerable <SentimentData> sentiments = new[] { new SentimentData { SentimentText = "Contoso's 11 is a wonderful experience", Sentiment = 0 }, new SentimentData { SentimentText = "The acting in this movie is very bad", Sentiment = 0 }, new SentimentData { SentimentText = "Joe versus the Volcano Coffee Company is a great film.", Sentiment = 0 } }; PredictionModel <SentimentData, SentimentPrediction> model = pipeline.Train <SentimentData, SentimentPrediction>(); IEnumerable <SentimentPrediction> _predictions = model.Predict(sentiments); Console.WriteLine(); Console.WriteLine("Sentiment Predictions"); Console.WriteLine("---------------------"); var sentimentsAndPredictions = sentiments.Zip(_predictions, (sentiment, prediction) => (sentiment, prediction)); foreach (var item in sentimentsAndPredictions) { Console.WriteLine($"Sentiment: {item.sentiment.SentimentText} | Prediction: {(item.prediction.Sentiment ? "Positive" : "Negative")}"); } Console.WriteLine(); return(model); }
static async Task Main(string[] args) { PredictionModel <IrisData, ClusterPrediction> model = Train(); await model.WriteAsync(_modelPath); var prediction = model.Predict(TestIrisData.Setosa); Console.WriteLine($"Cluster: {prediction.PredictedClusterId}"); Console.WriteLine($"Distances: {string.Join(" ", prediction.Distances)}"); Console.Write("press any key to close..."); Console.ReadKey(); }
public static void Predict(PredictionModel <SentimentData, SentimentPrediction> model, IMongoDatabase db) { // Adds some comments to test the trained model's predictions. // <Snippet18> IEnumerable <SentimentData> sentiments = new[] { new SentimentData { text = "Very bad service and low quality of coffee too. Waiting for so long even tried to rush them already." }, new SentimentData { text = "This place is amazing!! I had the classic cheese burger with fries. Hands down the best burger I have ever had" }, new SentimentData { text = "If I could give zero stars I would. Terribly overpriced. Dried over cooked barramundi with no seasoning or flavor at all" }, new SentimentData { text = "Small menu but the food is quite good. It's fast and easy, one of the better options around the area. We had the seafood laksa and seafood Pad Kee Mao" } }; // </Snippet18> // Use the model to predict the positive // or negative sentiment of the comment data. // <Snippet19> IEnumerable <SentimentPrediction> predictions = model.Predict(sentiments); // </Snippet19> // <Snippet20> Console.WriteLine(); Console.WriteLine("Sentiment Predictions"); Console.WriteLine("---------------------"); // </Snippet20> // Builds pairs of (sentiment, prediction) // <Snippet21> var sentimentsAndPredictions = sentiments.Zip(predictions, (sentiment, prediction) => (sentiment, prediction)); // </Snippet21> // <Snippet22> foreach (var item in sentimentsAndPredictions) { Console.WriteLine($"Sentiment: {item.sentiment.text} | Prediction: {(item.prediction.sentiment ? "Positive" : "Negative")}"); } Console.WriteLine(); // </Snippet22> }
public void Predict() { List <ManifestDataTraining> records = ReadInputData(); var res = model.Predict(records); foreach (var item in res) { records.First(x => x.PassengerId == item.PassengerId).Survived = item.Survived; } WriteResult(records); }
private static void Evaluate(PredictionModel <TaxiTrip, TaxiTripFarePrediction> model) { var textData = new TextLoader <TaxiTrip>(TestDataPath, useHeader: true, separator: ","); var evaluator = new RegressionEvaluator(); RegressionMetrics matrics = evaluator.Evaluate(model, textData); Console.WriteLine("Rms=" + matrics.Rms); Console.WriteLine("RSquared=" + matrics.RSquared); TaxiTripFarePrediction prediction01 = model.Predict(TestTrips.Trip1); Console.WriteLine("Predict fare : {0}, actual fare : 29.5", prediction01.fare_amount); }
public static async Task <string> PredictAsync(GitHubIssue issue, ILogger logger) { PredictionModel <GitHubIssue, GitHubIssuePrediction> model = await PredictionModel.ReadAsync <GitHubIssue, GitHubIssuePrediction>(ModelPath); GitHubIssuePrediction prediction = model.Predict(issue); float[] probabilities = prediction.Probabilities; float maxProbability = probabilities.Max(); logger.LogInformation($"Label {prediction.Area} for {issue.ID} is predicted with confidence {maxProbability.ToString()}"); return(maxProbability > 0.8 ? prediction.Area : null); }
public static void Predict(PredictionModel <PokerHandData, PokerHandPrediction> model) { var test1 = new PokerHandData { S1 = 1, C1 = 2, S2 = 1, C2 = 3, S3 = 3, C3 = 4, S4 = 4, C4 = 5, S5 = 2, C5 = 6 }; var test2 = new PokerHandData { S1 = 4, C1 = 5, S2 = 1, C2 = 5, S3 = 3, C3 = 5, S4 = 2, C4 = 12, S5 = 4, C5 = 7 }; test1.Init(); test2.Init(); IEnumerable <PokerHandData> pokerHands = new[] { test1, test2 }; IEnumerable <PokerHandPrediction> predictions = model.Predict(pokerHands); Console.WriteLine(); Console.WriteLine("PokerHand Predictions"); Console.WriteLine("---------------------"); var pokerHandsAndPredictions = pokerHands.Zip(predictions, (pokerHand, prediction) => (pokerHand, prediction)); foreach (var(pokerHand, prediction) in pokerHandsAndPredictions) { Console.WriteLine($"PokerHand: {ShowHand(pokerHand)} | Prediction: { GetPower(prediction.PredictedPower)}"); } Console.WriteLine(); }
static void Main(string[] args) { var pipeline = new LearningPipeline(); var loader = new TextLoader(dataPath).CreateFrom <SentimentData>(useHeader: true, '\t'); pipeline.Add(loader); pipeline.Add(new TextFeaturizer("Features", "SentimentText") { StopWordsRemover = new PredefinedStopWordsRemover(), KeepPunctuations = false, TextCase = TextNormalizerTransformCaseNormalizationMode.Lower, VectorNormalizer = TextTransformTextNormKind.L2 }); pipeline.Add(new StochasticDualCoordinateAscentBinaryClassifier() { NumThreads = 8, Shuffle = true, NormalizeFeatures = NormalizeOption.Yes }); PredictionModel <SentimentData, SentimentPrediction> model = pipeline.Train <SentimentData, SentimentPrediction>(); IEnumerable <SentimentData> sentiments = new[] { new SentimentData { SentimentText = "I hated the movie." }, new SentimentData { SentimentText = "The movie was entertaining the whole time, i really enjoyed it." } }; IEnumerable <SentimentPrediction> predictions = model.Predict(sentiments); foreach (var item in predictions) { Console.WriteLine($"Prediction: {(item.Sentiment ? "Positive" : "Negative")}"); } var evulatorTrained = new BinaryClassificationEvaluator(); BinaryClassificationMetrics metricsTrained = evulatorTrained.Evaluate(model, loader); Console.WriteLine("ACCURACY OF MODEL ON TRAINED DATA: " + metricsTrained.Accuracy); model.WriteAsync(trainedModelPath); Console.Read(); }
private static PredictionModel <NodeData, ClusterPrediction> TrainTheModel() { Console.WriteLine(); Console.WriteLine("Starting Machine Learning..."); PredictionModel <NodeData, ClusterPrediction> model = Train(); model.WriteAsync(_modelPath).Wait(); var prediction = model.Predict(TestNodeData.RandomNode); Console.WriteLine($"Cluster: {prediction.PredictedClusterId}"); Console.WriteLine($"Distances: {string.Join(" ", prediction.Distances)}"); Console.WriteLine("<<<<< Machine Learning Complete! >>>>>"); return(model); }
private static void VisualizeTenPredictionsForTheModel( PredictionModel <WineQualitySample, WineQualityPrediction> model, string testDataLocation) { var testData = new WineQualityCsvReader().GetWineQualitySamplesFromCsv(testDataLocation).ToList(); for (int i = 0; i < 10; i++) { var prediction = model.Predict(testData[i]); Console.WriteLine($"-------------------------------------------------"); Console.WriteLine($"Predicted : {prediction.PredictedLabel}"); Console.WriteLine($"Actual: {testData[i].Label}"); Console.WriteLine($"-------------------------------------------------"); } }
public static void Predict(IEnumerable <SentimentData> sentiments, PredictionModel <SentimentData, SentimentPrediction> model) { IEnumerable <SentimentPrediction> predictions = model.Predict(sentiments); Console.WriteLine(); Console.WriteLine("Sentiment Predictions"); Console.WriteLine("---------------------"); var sentimentsAndPredictions = sentiments.Zip(predictions, (sentiment, prediction) => (sentiment, prediction)); foreach (var item in sentimentsAndPredictions) { Console.WriteLine($"Sentiment: {item.sentiment.SentimentText} | Prediction: {(item.prediction.Sentiment ? "Positive" : "Negative")}"); } Console.WriteLine(); }
private static void VisualizeTenPredictionsForTheModel( PredictionModel <BikeSharingDemandSample, BikeSharingDemandPrediction> model, string testDataLocation) { var testData = new BikeSharingDemandsCsvReader().GetDataFromCsv(testDataLocation).ToList(); for (int i = 0; i < 10; i++) { var prediction = model.Predict(testData[i]); Console.WriteLine($"-------------------------------------------------"); Console.WriteLine($"Predicted : {prediction.PredictedCount}"); Console.WriteLine($"Actual: {testData[i].Count}"); Console.WriteLine($"-------------------------------------------------"); } }