Esempio n. 1
0
        private List <ChartTransaction> ComputeForecast(int id, int forecastMonths = 12)
        {
            List <ChartTransaction> transactions = new List <ChartTransaction>();

            Brand  currentBrand = Hardware.FirstOrDefault(x => x.ConfigId == id).Brand;
            string currentModel = Hardware.FirstOrDefault(x => x.ConfigId == id).Model;

            TimeSeriesPrediction prediction = new TimeSeriesPrediction(Transactions, currentBrand, currentModel);

            prediction.GenerateFutureForecast(forecastMonths);

            DateTime today = DateTime.Today;

            foreach (Phone p in prediction.PhoneCollection.Phones)
            {
                DateTime currentDate    = p.Date;
                var      datetime       = DateTimeSpan.CompareDates(currentDate, today);
                int      yearDifference = datetime.Years;

                if (yearDifference <= 2)
                {
                    this.AddTransactionToRecord(id, new ChartTransaction {
                        Date = p.Date, Price = p.Forecast.Value
                    });
                    transactions.Add(new ChartTransaction
                    {
                        Date  = p.Date,
                        Price = p.Forecast.Value
                    });
                }
            }

            return(transactions);
        }
        private List <int> AutogenerateMissingDataIfPossible(List <int> selectedPhoneIds, int months = 3)
        {
            List <int> eligibleIds = selectedPhoneIds;

            DateTime today        = DateTime.Today;
            int      currentMonth = DateTime.Today.Month;
            int      currentYear  = DateTime.Today.Year;

            foreach (int id in selectedPhoneIds)
            {
                Brand  selectedBrand = Hardware.FirstOrDefault(x => x.ConfigId == id).Brand;
                string selectedModel = Hardware.FirstOrDefault(x => x.ConfigId == id).Model;

                DateTime latestDate      = Phones.Where(x => x.Brand == selectedBrand && x.Model == selectedModel).Max(x => x.Date);
                var      datetime        = DateTimeSpan.CompareDates(latestDate, today);
                int      monthDifference = datetime.Years * 12 + datetime.Months;

                // Remove id if latest date cannot be found or the gap is too big
                if (latestDate == null || monthDifference > 3)
                {
                    eligibleIds.RemoveAll(x => x == id);
                    Errors.Add($"{selectedBrand} {selectedModel} - Data for the last {monthDifference} months is unavailable.");
                    Errors = Errors.Distinct().ToList();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"Generating data");

                    TimeSeriesPrediction prediction = new TimeSeriesPrediction(Phones, selectedBrand, selectedModel);
                    prediction.GenerateFutureForecast(monthDifference);
                }
            }

            return(new List <int>());
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Welcome to world of data science and machine learning using Microsoft .Net!!! ****");

            #region EDA

            Console.WriteLine("Performing Exploratory Data Analysis\n");

            var exploratoryDataAnalysis = new ExploratoryDataAnalysis();
            exploratoryDataAnalysis.Analyze();

            Console.WriteLine("Exploratory Data Completed\n");

            #endregion

            #region Time Series Prediction

            Console.WriteLine("\nPress any key to start Time Series Prediction\n");
            Console.ReadKey();

            var timeSeriesPrediction = new TimeSeriesPrediction();
            timeSeriesPrediction.Forecast();

            Console.WriteLine("Time Series Prediction Completed\n");

            #endregion

            Console.WriteLine("******* END *********");
            Console.ReadLine();
        }
Esempio n. 4
0
        // GET: Items
        public async Task <IActionResult> Index()
        {
            List <Item>          items    = _phoneContext.Items.ToList();
            TimeSeriesPrediction forecast = new TimeSeriesPrediction(items, Timeframe.Monthly);

            forecast.GenerateFutureForecast(12);
            return(View(await _phoneContext.Items.ToListAsync()));
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                //Setting global device
                Logging.OnWriteLog += Logging_OnWriteLog;


                //XOR Example
                XORExample.LoadData();
                XORExample.BuildModel();
                XORExample.Train();

                //Housing regression example
                HousingRegression.LoadData();
                HousingRegression.BuildModel();
                HousingRegression.Train();

                //MNIST Classification example
                MNISTClassifier.LoadData();
                MNISTClassifier.BuildModel();
                MNISTClassifier.Train();

                //LSTM Time series example
                TimeSeriesPrediction.LoadData();
                TimeSeriesPrediction.BuildModel();
                TimeSeriesPrediction.Train();

                //Multi variate time series prediction
                MiltiVariateTimeSeriesPrediction.LoadData();
                MiltiVariateTimeSeriesPrediction.BuildModel();
                MiltiVariateTimeSeriesPrediction.Train();

                //Cifar - 10 Classification example
                //Cifar10Classification.LoadData();
                //Cifar10Classification.BuildModel();
                //Cifar10Classification.Train();

                //Image classification example
                Console.WriteLine("ResNet50 Prediction: " + ImageClassification.ImagenetTest(SiaNet.Common.ImageNetModel.ResNet50)[0].Name);
                //Console.WriteLine("Cifar 10 Prediction: " + ImageClassification.Cifar10Test(SiaNet.Common.Cifar10Model.ResNet110)[0].Name);

                //Object Detection
                ObjectDetection.PascalDetection();
                //ObjectDetection.GroceryDetection();
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
        private List <ChartTransaction> ComputeForecast(int id, int forecastMonths = 12)
        {
            var asd = ContainsEnoughData(SelectedItems);

            // A ChartTransaction object contains date of purchase and price.
            List <ChartTransaction> transactions = new List <ChartTransaction>();

            // Find brand and model based on passed id
            Brand  selectedBrand = Hardware.FirstOrDefault(m => m.ConfigId == id).Brand;
            string selectedModel = Hardware.FirstOrDefault(m => m.ConfigId == id).Model;

            // Generates time series forecast.
            // RemoveUnforecastableIds method already checks if there are enough transactions to compute.
            TimeSeriesPrediction prediction = new TimeSeriesPrediction(Phones, selectedBrand, selectedModel);

            prediction.GenerateFutureForecast(forecastMonths);

            DateTime today = DateTime.Today;

            // Itterate through all objects
            foreach (Phone p in prediction.PhoneCollection.Phones)
            {
                DateTime currentDate    = p.Date;
                var      datetime       = DateTimeSpan.CompareDates(currentDate, today);
                int      yearDifference = datetime.Years;

                // Forecast is generated using ALL data
                // Chart only displays data from the last 2 years + the forecast
                if (yearDifference <= 2)
                {
                    // Adds to the List<Dict<int, ChartTrans>> so calculations can be done
                    // In order to find the best/worst future price
                    this.AddTransactionToRecord(id, new ChartTransaction {
                        Date = p.Date, Price = p.Forecast.Value
                    });
                    // Records their date and price.
                    transactions.Add(new ChartTransaction
                    {
                        Date  = p.Date,
                        Price = p.Forecast.Value
                    });
                }
            }

            return(transactions);
        }