Inheritance: SourceBase
Exemplo n.º 1
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method is used to copy/paste a new item.</summary>
        ///
        /// <param name="copyItem">The item to copy/paste.</param>
        /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param>
        ///--------------------------------------------------------------------------------
        public DatabaseSourceViewModel PasteDatabaseSource(DatabaseSourceViewModel copyItem, bool savePaste = true)
        {
            DatabaseSource newItem = new DatabaseSource();

            newItem.ReverseInstance = new DatabaseSource();
            newItem.TransformDataFromObject(copyItem.DatabaseSource, null, false);
            newItem.SpecificationSourceID = Guid.NewGuid();
            newItem.IsAutoUpdated         = false;

            newItem.Solution = Solution;
            newItem.Solution = Solution;
            DatabaseSourceViewModel newView = new DatabaseSourceViewModel(newItem, Solution);

            newView.ResetModified(true);
            AddDatabaseSource(newView);

            // paste children
            if (savePaste == true)
            {
                Solution.DatabaseSourceList.Add(newItem);
                newView.OnUpdated(this, null);
                Solution.ResetModified(true);
            }
            return(newView);
        }
Exemplo n.º 2
0
        private void CreateBackup(
            DatabaseSmugglerOptionsServerSide options, string backupFilePath,
            long?startDocumentEtag, DocumentsOperationContext context,
            Action <IOperationProgress> onProgress)
        {
            // the last etag is already included in the last backup
            startDocumentEtag = startDocumentEtag == null ? 0 : ++startDocumentEtag;

            using (var file = File.Open(backupFilePath, FileMode.CreateNew))
            {
                var smugglerSource      = new DatabaseSource(_database, startDocumentEtag.Value);
                var smugglerDestination = new StreamDestination(file, context, smugglerSource);
                var smuggler            = new Smuggler.Documents.DatabaseSmuggler(_database,
                                                                                  smugglerSource,
                                                                                  smugglerDestination,
                                                                                  _database.Time,
                                                                                  options: options,
                                                                                  result: _backupResult,
                                                                                  onProgress: onProgress,
                                                                                  token: TaskCancelToken.Token);

                smuggler.Execute();
                file.Flush(flushToDisk: true);
            }
        }
        // Change this code to create your own sample data
        #region CreateSingleDataSample
        // Method to load single row of dataset to try a single prediction
        private static ModelInput CreateSingleDataSample()
        {
            // Create MLContext
            MLContext mlContext = new MLContext();

            // Load dataset
            var    loader           = mlContext.Data.CreateDatabaseLoader <ModelInput>();
            string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;Database=TrainingRecommender;Integrated Security=True;Connect Timeout=30";

            string sqlCommand = @"SELECT CAST(Weight as REAL) as Weight, 
                                    CAST(Height as REAL) as Height, CAST(Age as REAL) as Age, CAST(FigureType as REAL) as FigureType, CAST(Gender as REAL) as Gender,
                                    CAST(Activity as REAL) as Activity, CAST(Goal as REAL) as Goal, CAST(TrainingRate as REAL) as TrainingRate, CAST(Level as REAL) as Level,
                                    CAST(Duration as REAL) as Duration, CAST(ExerciseIndex as REAL) as ExerciseIndex,
                                    UserId, CAST(TrainingId as REAL) as TrainingId, 
                                    CAST(Score as REAL) as Score FROM UserTrainingsView";

            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance, connectionString, sqlCommand);

            IDataView dataView = loader.Load(dbSource);

            // Use first line of dataset as model input
            // You can replace this with new test data (hardcoded or from end-user application)
            ModelInput sampleForPrediction = mlContext.Data.CreateEnumerable <ModelInput>(dataView, false)
                                             .First();

            return(sampleForPrediction);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            //Console.WriteLine("Enter the name of the table:");
            //String tblName = Console.ReadLine();
            //String TrainDataRelativePath = ConvertDataToCsv(tblName);
            //Console.WriteLine("Enter the name of the target field:");
            //LabelColumnName = Console.ReadLine();

            String tblName = "tblFE_Ana_Titanic";
            String TrainDataRelativePath = ConvertDataToCsv(tblName);

            LabelColumnName = "fblnSurvived";


            mlContext = new MLContext(seed: 1);
            DatabaseLoader loader   = mlContext.Data.CreateDatabaseLoader <TitanicData>();
            DatabaseSource dbSource = new DatabaseSource(providerFactory: SqlClientFactory.Instance, connectionString: connectionString, commandText: commandText);

            //ColumnInferenceResults columnInference = mlContext.Auto().InferColumns();

            var columnInference = InferColumns(mlContext, GetAbsolutePath(TrainDataRelativePath));

            LoadData(mlContext, columnInference, GetAbsolutePath(TrainDataRelativePath), GetAbsolutePath(TrainDataRelativePath));

            var experimentResult = RunAutoMLExperiment(mlContext: mlContext, columnInference: columnInference);

            EvaluateModel(mlContext, experimentResult.BestRun.Model, experimentResult.BestRun.TrainerName);

            SaveModel(mlContext, experimentResult.BestRun.Model);

            // PlotRegressionChart(mlContext, TestDataPath, numberOfRecordsToRead: 100, args);

            var refitModel = RefitBestPipeline(mlContext, experimentResult, columnInference, GetAbsolutePath(TrainDataRelativePath), GetAbsolutePath(TrainDataRelativePath));
        }
Exemplo n.º 5
0
        private void UpdateActions()
        {
            InterfaceActionService uia_service = ServiceManager.Get <InterfaceActionService> ();

            Gtk.Action action = uia_service.TrackActions["BurnDiscAction"];

            bool visible   = false;
            bool sensitive = false;

            DatabaseSource source = ServiceManager.SourceManager.ActiveSource as DatabaseSource;

            // FIXME: Figure out how to handle non-music-library sources
            if (source != null)
            {
                if (source is MusicLibrarySource || source.Parent is MusicLibrarySource)
                {
                    visible = true;
                }

                sensitive = source.TrackModel.Selection.Count > 0;
            }

            action.Sensitive = sensitive;
            action.Visible   = visible;
        }
        private void HandleActiveSourceChanged(SourceEventArgs args)
        {
            if (last_source != null)
            {
                foreach (IFilterListModel filter in last_source.AvailableFilters)
                {
                    filter.Selection.Changed -= OnSelectionChanged;
                }
                last_source.TrackModel.Selection.Changed -= OnSelectionChanged;
                last_source = null;
            }

            last_source = args.Source as DatabaseSource;
            if (IsPodcastSource)
            {
                if (last_source != null)
                {
                    foreach (IFilterListModel filter in last_source.AvailableFilters)
                    {
                        filter.Selection.Changed += OnSelectionChanged;
                    }
                    last_source.TrackModel.Selection.Changed += OnSelectionChanged;
                }
            }
            else
            {
                last_source = null;
            }

            OnSelectionChanged(null, null);
        }
        static void Main_BinaryClassifications(string[] args)
        {
            var mlContext = new MLContext();

            string connectionString = @"Data Source=LAPTOP-ILQS92OM\SQLEXPRESS;Initial Catalog=ContosoRetailDW;Integrated Security=True;Pooling=False";

            string commandText = "SELECT CONVERT(real, Age),CONVERT(real, YearlyIncome),CONVERT(real, TotalChildren),CONVERT(real, NumberChildrenAtHome) ," +
                                 "CONVERT(real, NumberCarsOwned),CONVERT(real, ProductKey),CONVERT(real, PromotionKey)," +
                                 "CONVERT(bit, HouseOwnerFlag) FROM V_CustomerPromotion";

            DatabaseLoader loader = mlContext.Data.CreateDatabaseLoader <CustomerPromotionData>();

            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance,
                                                         connectionString,
                                                         commandText);

            IDataView dataView = loader.Load(dbSource);
            //ConsoleHelper.ShowDataViewInConsole(mlContext, dataView, 500);
            var trainTestData = mlContext.Data.TrainTestSplit(dataView, testFraction: 0.2).TestSet;

            //BuildTrainEvaluateAndSaveModel(mlContext, dataView, trainTestData);

            TestPrediction(mlContext);

            Console.WriteLine("=============== End of process, hit any key to finish ===============");
        }
Exemplo n.º 8
0
        public Workspace(string workspaceFolder, DatabaseSource databaseSource, string envimetFolder = null)
        {
            _systemFolder = GetEnvimetSystemFolder(SYSTEM_FOLDER, envimetFolder);
            _userFolder   = GetEnvimetSystemFolder(USER_FOLDER, envimetFolder);

            if (_systemFolder == null)
            {
                throw new ArgumentOutOfRangeException("Envimet not found! Check on your machine or set EnvimetFolder.");
            }

            WorkspaceFolder = workspaceFolder;
            ProjectName     = "Project";
            ModelName       = "Model";

            ProjectFolder = System.IO.Path.Combine(WorkspaceFolder, ProjectName);
            ModelPath     = System.IO.Path.Combine(ProjectFolder, ModelName + ".inx");

            string workspaceInfoxAbsPath = System.IO.Path.Combine(_systemFolder, WORKSPACE_INFOX);
            string projectInfoxAbsPath   = System.IO.Path.Combine(ProjectFolder, PROJECT_INFOX);

            SetWorkSpaceInfox(workspaceInfoxAbsPath);
            SetProjectInfox(projectInfoxAbsPath, databaseSource);

            SetDatabase(databaseSource, _systemFolder, _userFolder);
        }
Exemplo n.º 9
0
        public int calculateFinishTime(string userName, float commentLength, float noteLength, float workFollowRowCount)
        {
            string connectionString = "Data Source=.;Initial Catalog=Trello_Clone;Integrated Security=True";
            var    loaderColumns    = new DatabaseLoader.Column[]
            {
                new DatabaseLoader.Column()
                {
                    Name = "taskCommentLength", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "taskNoteLength", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "taskWorkFollowRowCount", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "taskFinishTime", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "userName", Type = DbType.String
                }
            };
            var connection = new SqlConnection(connectionString);
            var factory    = DbProviderFactories.GetFactory(connection);

            var context = new MLContext();

            var loader = context.Data.CreateDatabaseLoader(loaderColumns);

            var dbSource = new DatabaseSource(factory, connectionString,
                                              "select U.userName,F.taskCommentLength,F.taskNoteLength,F.taskWorkFollowRowCount,F.taskFinishTime from userTable U inner join FinishTime F on U.userID=F.userID");

            var data = loader.Load(dbSource);

            var preview = data.Preview();

            var testTrainSplit = context.Data.TrainTestSplit(data, testFraction: 0.9);

            var pipeline = context.Transforms.Categorical.OneHotEncoding(outputColumnName: "userNameEncoded", inputColumnName: "userName")
                           .Append(context.Transforms.Concatenate("Features", "taskCommentLength", "taskNoteLength", "taskWorkFollowRowCount", "userNameEncoded"))
                           .Append(context.Regression.Trainers.LbfgsPoissonRegression(labelColumnName: "taskFinishTime"));

            var model = pipeline.Fit(testTrainSplit.TestSet);

            var predictionFunc = context.Model.CreatePredictionEngine <HousingData, HousingPrediction>(model);

            var prediction = predictionFunc.Predict(new HousingData
            {
                userName               = userName,
                taskCommentLength      = commentLength,
                taskNoteLength         = noteLength,
                taskWorkFollowRowCount = workFollowRowCount
            });

            return(Convert.ToInt32(prediction.taskFinishTime));
        }
Exemplo n.º 10
0
        public override bool SetSource(ISource source)
        {
            //Console.WriteLine ("PSC.set_source 1");
            DatabaseSource track_source = source as DatabaseSource;

            if (track_source == null)
            {
                return(false);
            }

            this.source = source;

            SetModel(track_view, track_source.TrackModel);

            foreach (IListModel model in track_source.CurrentFilters)
            {
                if (model is PodcastFeedModel)
                {
                    SetModel(feed_view, (model as IListModel <Feed>));
                }
                else if (model is PodcastUnheardFilterModel)
                {
                    SetModel(unheard_view, (model as IListModel <OldNewFilter>));
                }
                else
                {
                    Hyena.Log.DebugFormat("PodcastContents got non-feed filter model: {0}", model);
                }
            }

            track_view.HeaderVisible = true;
            //Console.WriteLine ("PSC.set_source 2");
            return(true);
        }
Exemplo n.º 11
0
        private void SetProjectInfox(string projectInfoxAbsPath, DatabaseSource databaseSource)
        {
            var now = DateTime.Now;

            string[] textProjectFileInfox =
            {
                "<ENVI-MET_Datafile>",
                "<Header>",
                "<filetype>infoX ENVI-met Project Description File</filetype>",
                $"<version>{VERSION}</version>",
                $"<revisiondate>{now.ToString("yyyy-MM-dd HH:mm:ss")}</revisiondate>",
                "<remark></remark>",
                $"<checksum>{CHECK_SUM}</checksum>",
                $"<encryptionlevel>{ENCRIPTION_LEVEL}</encryptionlevel>",
                "</Header>",
                "<project_description>",
                $"<name> {ProjectName} </name>",
                "<description>  </description>",
                $"<useProjectDB> {(int) databaseSource} </useProjectDB>",
                "</project_description>",
                "</ENVI-MET_Datafile>"
            };

            System.IO.File.WriteAllLines(projectInfoxAbsPath, textProjectFileInfox);
        }
Exemplo n.º 12
0
        public void Train()
        {
            // Define paths and initial variables
            var modelPath        = WorkshopHelper.GetModelPath(ModelFile);
            var trainingData     = WorkshopHelper.GetTrainingDataFile("ms", TrainingFile);
            var connectionString = $"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename={trainingData};Integrated Security=True;Connect Timeout=30;";

            // Load the data
            var loader     = Context.Data.CreateDatabaseLoader <BikeInput>();
            var query      = "SELECT RentalDate, CAST(Year as REAL) as Year, CAST(TotalRentals as REAL) as TotalRentals FROM Rentals";
            var dbSource   = new DatabaseSource(SqlClientFactory.Instance, connectionString, query);
            var dataView   = loader.Load(dbSource);
            var firstYear  = Context.Data.FilterRowsByColumn(dataView, "Year", upperBound: 1);
            var secondYear = Context.Data.FilterRowsByColumn(dataView, "Year", upperBound: 2);

            // Define analysis pipeline
            var forecastPipeline = Context.Forecasting.ForecastBySsa(
                outputColumnName: "ForecastedRentals",
                inputColumnName: "TotalRentals",
                windowSize: 7,
                seriesLength: 30,
                trainSize: 365,
                horizon: 7,
                confidenceLevel: 0.95f,
                confidenceLowerBoundColumn: "LowerBoundRentals",
                confidenceUpperBoundColumn: "UpperBoundRentals");
            var forecaster = forecastPipeline.Fit(firstYear);
        }
Exemplo n.º 13
0
        public static void CreateModel()
        {
            // Load Data
            var    loader           = mlContext.Data.CreateDatabaseLoader <ModelInput>();
            string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;Database=TrainingRecommender;Integrated Security=True;Connect Timeout=30";

            string sqlCommand = @"SELECT CAST(Weight as REAL) as Weight, 
                                    CAST(Height as REAL) as Height, CAST(Age as REAL) as Age, CAST(FigureType as REAL) as FigureType, CAST(Gender as REAL) as Gender,
                                    CAST(Activity as REAL) as Activity, CAST(Goal as REAL) as Goal, CAST(TrainingRate as REAL) as TrainingRate, CAST(Level as REAL) as Level,
                                    CAST(Duration as REAL) as Duration, CAST(ExerciseIndex as REAL) as ExerciseIndex,
                                    UserId, CAST(TrainingId as REAL) as TrainingId, 
                                    CAST(Score as REAL) as Score FROM UserTrainingsView";

            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance, connectionString, sqlCommand);

            IDataView trainingDataView = loader.Load(dbSource);

            // Build training pipeline
            IEstimator <ITransformer> trainingPipeline = BuildTrainingPipeline(mlContext);

            // Evaluate quality of Model
            Evaluate(mlContext, trainingDataView, trainingPipeline);

            // Train Model
            ITransformer mlModel = TrainModel(mlContext, trainingDataView, trainingPipeline);

            // Save model
            SaveModel(mlContext, mlModel, MODEL_FILEPATH, trainingDataView.Schema);
        }
Exemplo n.º 14
0
        private static IDataView LoadDataView(string source)
        {
            var       tmpPath = GetAbsolutePath(TRAIN_DATA_FILEPATH);
            IDataView trainingDataView;

            if (source == "textFile")
            {
                trainingDataView = mlContext.Data.LoadFromTextFile <ModelInput>(
                    path: tmpPath,
                    hasHeader: true,
                    separatorChar: '\t',
                    allowQuoting: true,
                    allowSparse: false);
            }
            else if (source == "SQL")
            {
                DatabaseLoader loader   = mlContext.Data.CreateDatabaseLoader <ModelInput>();
                DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance, CONNECTION_STRING, SQL_COMMAND);
                trainingDataView = loader.Load(dbSource);
            }
            else
            {
                ModelInput[] inMemoryCollection = new ModelInput[]
                {
                    new ModelInput()
                    {
                        Lead_time = 0,
                        //To Do: Instanciar el objeto
                    }
                };
                trainingDataView = mlContext.Data.LoadFromEnumerable <ModelInput>(inMemoryCollection);
            }

            return(trainingDataView);
        }
        static void Main_AnomalyDetections(string[] args)
        {
            var mlContext = new MLContext();

            string connectionString = @"Data Source=LAPTOP-ILQS92OM\SQLEXPRESS;Initial Catalog=ContosoRetailDW;Integrated Security=True;Pooling=False";

            string commandText = "SELECT top 100000 EntityKey,ScenarioKey,AccountKey,ProductCategoryKey,CONVERT(real, Amount * 100) from FactStrategyPlan";

            DatabaseLoader loader = mlContext.Data.CreateDatabaseLoader <StrategyPlan>();

            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance,
                                                         connectionString,
                                                         commandText);

            IDataView dataView = loader.Load(dbSource);
            //ConsoleHelper.ShowDataViewInConsole(mlContext, dataView, 500);
            var trainTestData = mlContext.Data.TrainTestSplit(dataView);

            const int size = 100;

            ////To detech temporay changes in the pattern
            DetectSpike(mlContext, size, dataView);

            //To detect persistent change in the pattern
            //DetectChangepoint(mlContext, size, dataView);

            Console.WriteLine("=============== End of process, hit any key to finish ===============");
        }
        private IDataView EnsureDataLoaded()
        {
            var loader   = _mlContext.Data.CreateDatabaseLoader <ModelInput>();
            var dbSource = new DatabaseSource(SqlClientFactory.Instance, _configuration.GetConnectionString("DefaultConnectionString"), "SELECT * FROM ModelInputs");

            return(loader.Load(dbSource));
        }
Exemplo n.º 17
0
        private void OnBurnDisc(object o, EventArgs args)
        {
            DatabaseSource source = ServiceManager.SourceManager.ActiveSource as DatabaseSource;

            if (source == null)
            {
                return;
            }

            StringBuilder file_args = new StringBuilder();

            file_args.Append("-a");

            foreach (TrackInfo track in source.TrackModel.SelectedItems)
            {
                if (track.Uri.IsLocalPath)
                {
                    file_args.AppendFormat(" \"{0}\"", track.Uri.AbsolutePath.Replace("\"", "\\\""));
                }
            }

            try {
                Run(file_args.ToString());
            } catch (Exception e) {
                Log.Exception("Problem starting Brasero", e);
                Log.Error(Catalog.GetString("Could not write CD"),
                          Catalog.GetString("Brasero could not be started"), true);
            }
        }
Exemplo n.º 18
0
        public HeaderWidget CreateHeaderWidget()
        {
            var header_widget = new HeaderWidget(shuffler, populate_shuffle_mode, populate_from_name);

            header_widget.ModeChanged += delegate(object sender, EventArgs <RandomBy> e) {
                populate_shuffle_mode = e.Value.Id;
                PopulateModeSchema.Set(populate_shuffle_mode);
                UpdatePlayQueue();
                OnUpdated();
            };

            populate_shuffle_mode = header_widget.ShuffleModeId;

            header_widget.SourceChanged += delegate(object sender, EventArgs <DatabaseSource> e) {
                populate_from = e.Value;
                if (populate_from == null)
                {
                    populate_from_name = String.Empty;
                    PopulateFromSchema.Set(String.Empty);
                    return;
                }

                populate_from_name = e.Value.Name;
                PopulateFromSchema.Set(e.Value.Name);
                source_set_at = DateTime.Now;
                populate_from.Reload();
                Refresh();
            };

            return(header_widget);
        }
        /// <summary>
        /// Runtime constructor
        /// </summary>
        /// <param name="availableDatabases"></param>
        /// <param name="activeDatabase"></param>
        public DatabaseSelectViewModel(List <DatabaseSource> availableDatabases, DatabaseSource activeDatabase)
        {
            AvailableTaskList = availableDatabases;
            SelectedTaskItem  = activeDatabase;

            UseGlobalTaskStoreCommand      = new RelayCommand(_ => SwitchToGlobalTaskList(), (x) => CanUseGlobalStore());
            CreateSolutionTaskStoreCommand = new RelayCommand(_ => CreateSolutionTaskStore(), (x) => CanCreateTask());
        }
Exemplo n.º 20
0
        private IDataView LoadData()
        {
            DatabaseLoader loader   = mlContext.Data.CreateDatabaseLoader <Data>();
            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance, Configuration.ConnectString, @"SELECT Comment,ReplyComment FROM  Datasets");

            //DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance, "Data Source=(local);Initial Catalog=MonitoringSocialNetwork;Integrated Security=True", @"SELECT Comment,ReplyComment FROM  dbo.Datasets");
            return(loader.Load(dbSource));
        }
Exemplo n.º 21
0
 public StreamDocumentActions(AsyncBlittableJsonTextWriter writer, DocumentsOperationContext context, DatabaseSource source, DatabaseSmugglerOptionsServerSide options, Func <LazyStringValue, bool> filterMetadataProperty, string propertyName)
     : base(writer, propertyName)
 {
     _context = context;
     _source  = source;
     _options = options;
     _filterMetadataProperty = filterMetadataProperty;
 }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Console.WriteLine("Training time series analysis");
            //Step 1. Create a ML Context
            var ctx = new MLContext();

            string connectionString = "Data Source=localhost;Initial Catalog=kaggle_wallmart;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;";

            connectionString = "Server=localhost;Database=kaggle_wallmart;Integrated Security=True";

            string Query = @"
                SELECT 
                      CAST(X.[Value] AS REAL) AS [TotalSales],
                      CAST(Y.date AS DATE) AS [SalesDate],
	                  CAST(year(Y.date) AS REAL) As [Year]
                  FROM [dbo].[RAW_Train_Eval] AS X
                  INNER JOIN [dbo].RAW_Calendar AS Y ON Y.d=X.dCode
                  where Id='HOBBIES_1_278_CA_1_evaluation' 
                  order by 2

            ";

            Console.WriteLine("Connecting to the database...");
            //dbChecks dbchecks = new dbChecks();
            //dbchecks.ExecuteQuery(connectionString, Query);


            System.Data.SqlClient.SqlClientFactory newFactory = SqlClientFactory.Instance;
            Console.WriteLine("Loading data...");
            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance, connectionString, Query);
            DatabaseLoader loader   = ctx.Data.CreateDatabaseLoader <ModelInput>();
            IDataView      dataView = loader.Load(dbSource);

            Console.WriteLine($"Loaded {dataView.GetRowCount()} rows...");

            IDataView trainingData   = ctx.Data.FilterRowsByColumn(dataView, "Year", upperBound: 2016);
            IDataView ValidationData = ctx.Data.FilterRowsByColumn(dataView, "Year", lowerBound: 2016);

            var forecastingPipeline = ctx.Forecasting.ForecastBySsa(
                outputColumnName: "ForecastedSales",
                inputColumnName: "TotalSales",
                windowSize: 7,
                seriesLength: 60,
                trainSize: 300,
                horizon: 30,
                confidenceLevel: 0.95f,
                confidenceLowerBoundColumn: "LowerBoundSales",
                confidenceUpperBoundColumn: "UpperBoundSales");
            SsaForecastingTransformer forecaster = forecastingPipeline.Fit(trainingData);

            Evaluate(ValidationData, forecaster, ctx);
            var forecastEngine = forecaster.CreateTimeSeriesEngine <ModelInput, ModelOutput>(ctx);

            forecastEngine.CheckPoint(ctx, "c:\\temp\\Model.zip");
            forecastEngine.CheckPoint(ctx, "C:\\Temp\\WallMartModels\\evaluation\\Model_HOBBIES_1_278_CA_1_evaluation.zip");
            Forecast(ValidationData, 7, forecastEngine, ctx);
            Console.WriteLine("Training time series analysis completed");
        }
Exemplo n.º 23
0
        private void IrisLightGbmImpl(DatabaseSource dbs)
        {
            var mlContext = new MLContext(seed: 1);

            var loaderColumns = new DatabaseLoader.Column[]
            {
                new DatabaseLoader.Column()
                {
                    Name = "Label", Type = DbType.Int32
                },
                new DatabaseLoader.Column()
                {
                    Name = "SepalLength", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "SepalWidth", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "PetalLength", Type = DbType.Single
                },
                new DatabaseLoader.Column()
                {
                    Name = "PetalWidth", Type = DbType.Single
                }
            };

            var loader = mlContext.Data.CreateDatabaseLoader(loaderColumns);

            var trainingData = loader.Load(dbs);

            IEstimator <ITransformer> pipeline = mlContext.Transforms.Conversion.MapValueToKey("Label")
                                                 .Append(mlContext.Transforms.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"))
                                                 .AppendCacheCheckpoint(mlContext)
                                                 .Append(mlContext.MulticlassClassification.Trainers.LightGbm())
                                                 .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            var model = pipeline.Fit(trainingData);

            var engine = mlContext.Model.CreatePredictionEngine <IrisData, IrisPrediction>(model);

            Assert.Equal(0, engine.Predict(new IrisData()
            {
                SepalLength = 4.5f,
                SepalWidth  = 5.6f,
                PetalLength = 0.5f,
                PetalWidth  = 0.5f,
            }).PredictedLabel);

            Assert.Equal(1, engine.Predict(new IrisData()
            {
                SepalLength = 4.9f,
                SepalWidth  = 2.4f,
                PetalLength = 3.3f,
                PetalWidth  = 1.0f,
            }).PredictedLabel);
        }
Exemplo n.º 24
0
 public void Start()
 {
     if (string.IsNullOrWhiteSpace(DatabasePath))
     {
         DatabasePath = Alias + ".db";
     }
     database = CreateDb(DatabasePath);
     DatabaseSource?.Invoke(database);
 }
        public static IDataView LoadData(MLContext mlContext)
        {
            DatabaseLoader loader           = mlContext.Data.CreateDatabaseLoader <MovieRating>();
            string         connectionString = @"Data Source=(Local);Database=MovieReviews;Integrated Security=True;Connect Timeout=30";
            string         sqlCommand       = "SELECT AccountId as userId, MovieId as movieId, CAST(Ratings as REAL) as Label FROM dbo.Reviews";
            DatabaseSource dbSource         = new DatabaseSource(SqlClientFactory.Instance, connectionString, sqlCommand);

            return(loader.Load(dbSource));
        }
Exemplo n.º 26
0
        private static IDataView LoadDataFromDB()
        {
            var    loader   = _mlContext.Data.CreateDatabaseLoader <ModelInput>();
            string query    = "SELECT RentalDate, CAST(Year as REAL) as Year, CAST(TotalRentals as REAL) as TotalRentals FROM Rentals";
            var    dbSource = new DatabaseSource(SqlClientFactory.Instance, connectionString, query);
            var    dataView = loader.Load(dbSource);

            return(dataView);
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            string rootDir = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../"));
            //string dbFilePath = Path.Combine(rootDir, "Data", "DailyDemand.mdf");
            string modelPath = Path.Combine(rootDir, "MLModel.zip");
            //            var connectionString = $"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename={dbFilePath};Integrated Security=True;Connect Timeout=30;";

            // you can use TblSmartAr.sql and able to make this table
            var connectionString = $"Data Source = (localdb)\\MSSQLLocalDB; Initial Catalog = Ar_Database; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False;";


            MLContext mlContext = new MLContext();

            DatabaseLoader loader = mlContext.Data.CreateDatabaseLoader <ModelInput>();

            string query = "SELECT Invoice_Date, CAST(Due_year as REAL) as Due_year, CAST(OverDue_Days as REAL) as OverDue_Days FROM TblSmartAR";

            DatabaseSource dbSource = new DatabaseSource(SqlClientFactory.Instance,
                                                         connectionString,
                                                         query);
            DateTime now = DateTime.Today;

            int thisyear = (now.Year);


            IDataView dataView = loader.Load(dbSource);

            IDataView firstYearData  = mlContext.Data.FilterRowsByColumn(dataView, "Due_year", upperBound: thisyear);
            IDataView secondYearData = mlContext.Data.FilterRowsByColumn(dataView, "Due_year", lowerBound: thisyear);

            var forecastingPipeline = mlContext.Forecasting.ForecastBySsa(
                outputColumnName: "ForecastedDays",
                inputColumnName: "OverDue_Days",
                windowSize: 80,
                seriesLength: 90,
                trainSize: 365,
                horizon: 80,
                confidenceLevel: .90f,
                confidenceLowerBoundColumn: "MinimumDays",
                confidenceUpperBoundColumn: "MaximumDays");

            SsaForecastingTransformer forecaster = forecastingPipeline.Fit(firstYearData);

            Evaluate(secondYearData, forecaster, mlContext);

            var forecastEngine = forecaster.CreateTimeSeriesEngine <ModelInput, ModelOutput>(mlContext);

            forecastEngine.CheckPoint(mlContext, modelPath);
            //foreach(var j in )
            //{
            //    if()
            //}

            Forecast(secondYearData, 40, forecastEngine, mlContext);

            Console.ReadKey();
        }
Exemplo n.º 28
0
        public void ReadDatabaseRecords()
        {
            var connectionString   = "Server=.;Database=ETLTest;Integrated Security=SSPI;";
            var connectionProvider = new Func <IDbConnection>(() => new SqlConnection(connectionString));
            var source             = new DatabaseSource <Record>(connectionProvider, "SELECT TOP 1000 * FROM TestTableSize");
            var pipeline           = CreateNewPipeline();

            pipeline.AddOperation(source);
            pipeline.Execute();
        }
Exemplo n.º 29
0
 private IOperationResult ExportDatabaseInternal(DatabaseSmugglerOptions options, Action <IOperationProgress> onProgress, DocumentsOperationContext context, OperationCancelToken token)
 {
     using (token)
     {
         var source      = new DatabaseSource(Database, 0);
         var destination = new StreamDestination(ResponseBodyStream(), context, source);
         var smuggler    = new DatabaseSmuggler(Database, source, destination, Database.Time, options, onProgress: onProgress, token: token.Token);
         return(smuggler.Execute());
     }
 }
 private void TaskSourceViewModel_SelectedTaskListChange(object sender, DatabaseSource targetTaskSource)
 {
     // Don't act on task list changes until the viewmodel is ready
     if (_viewModelReady == false)
     {
         return;
     }
     _taskListManager.SwitchDatabase(targetTaskSource);
     _vmDataContext.UpdateTaskList();
 }