Ejemplo n.º 1
0
        /*
         * Create mining model for the selected mining strucutre
         */
        private void CreateModels(MiningStructure objStructure)
        {
            MiningModel       ClusterModel;
            MiningModel       TreeModel;
            MiningModelColumn mmc;

            // Create the Cluster model and set the algorithm
            // and parameters
            DropExistingMiningModels(objStructure, sModelName);
            ClusterModel           = objStructure.CreateMiningModel(true, sModelName);
            ClusterModel.Algorithm = MiningModelAlgorithms.MicrosoftClustering;// "Microsoft_Clustering";
            ClusterModel.AlgorithmParameters.Add("CLUSTER_COUNT", 0);
            ClusterModel.Update();


            // The CreateMiningModel method adds
            // all the structure columns to the collection
            // Copy the Cluster model and change the necessary properties
            TreeModel = ClusterModel.Clone();
            DropExistingMiningModels(objStructure, sModelName + "Generation Trees");
            TreeModel.Name      = sModelName + "Generation Trees";
            TreeModel.ID        = sModelName + "Generation Trees";
            TreeModel.Algorithm = MiningModelAlgorithms.MicrosoftDecisionTrees;// "Microsoft_Decision_Trees";
            TreeModel.AlgorithmParameters.Clear();
            TreeModel.Columns["Gender"].Usage = "Predict";
            //TreeModel.Columns["PayChannels"].Usage = "Predict";

            // Add an aliased copy of the PayChannels table to the trees model
            mmc = TreeModel.Columns.Add("MaritalStatus");
            mmc.SourceColumnID = "MaritalStatus";
            mmc = mmc.Columns.Add("MaritalStatus");
            mmc.SourceColumnID = "MaritalStatus";
            mmc.Usage          = "Key";
            // Now set a filter on the PayChannels_Hbo_Encore table and use it
            // as input to predict other channels

            //TreeModel.Columns["PayChannels_Hbo_Encore"].Filter = "Channel=’HBO’ OR Channel=’Encore’";
            // Set a complementary filter on the payChannels predictable
            // nested table

            //TreeModel.Columns["PayChannels"].Filter = "Channel<>’HBO’ AND Channel<>’Encore’";
            objStructure.MiningModels.Add(TreeModel);

            // Submit the models to the server
            // ToDo: fix this
            //TreeModel.Update();
        }
Ejemplo n.º 2
0
        /*
         * Create mining model with custom fields and algorithm
         */
        private void CreateCustomModel(MiningStructure objStructure, string sAlgorithm, string sModelName, string sKeyColumn, List <string> lPredictColumns, List <bool> lbPredictColumns, int parOne, int parTwo)
        {
            // drop existing model
            if (objStructure.MiningModels.ContainsName(sModelName))
            {
                objStructure.MiningModels[sModelName].Drop();
            }

            // Detailed description of the model algorithms is here:
            // http://msdn.microsoft.com/en-us/library/ms175595.aspx

            // More customisation for these algorithms can be found here:
            // http://msdn.microsoft.com/en-us/library/cc280427.aspx

            // Also a model example can be found here:
            // http://msdn.microsoft.com/en-us/library/ms345087(v=SQL.100).aspx

            Microsoft.AnalysisServices.MiningModel myMiningModel = objStructure.CreateMiningModel(true, sModelName);
            myMiningModel.Algorithm = sAlgorithm;

            switch (sAlgorithm)
            {
            case MiningModelAlgorithms.MicrosoftClustering:
                myMiningModel.AlgorithmParameters.Add("CLUSTERING_METHOD", parOne);
                myMiningModel.AlgorithmParameters.Add("CLUSTER_COUNT", parTwo);
                break;

            //case MiningModelAlgorithms.MicrosoftTimeSeries:
            //    myMiningModel.AlgorithmParameters.Add("PERIODICITY_HINT", "{12}");              // {12} represents the number of months for prediction
            //    break;
            case MiningModelAlgorithms.MicrosoftNaiveBayes:
                break;

            case MiningModelAlgorithms.MicrosoftDecisionTrees:
                myMiningModel.AlgorithmParameters.Add("SCORE_METHOD", parOne);
                myMiningModel.AlgorithmParameters.Add("SPLIT_METHOD", parTwo);
                break;
            }


            /***************** Predict columns *****************/
            // add optional predict columns
            if (lPredictColumns.Count != 0)
            {
                // predict columns
                for (int i = 0; i < lPredictColumns.Count; i++)
                {
                    Microsoft.AnalysisServices.MiningModelColumn modelColumn = myMiningModel.Columns.GetByName(lPredictColumns[i]);
                    modelColumn.SourceColumnID = lPredictColumns[i];

                    if (lbPredictColumns[i] == true)
                    {
                        modelColumn.Usage = MiningModelColumnUsages.PredictOnly;
                    }
                    else
                    {
                        modelColumn.Usage = MiningModelColumnUsages.Predict;
                    }
                }
            }

            myMiningModel.Update();
        }
Ejemplo n.º 3
0
        /*
         * Create mining model with custom fields and algorithm
         */
        private void CreateCustomModel(MiningStructure objStructure, string sAlgorithm, string sModelName, string sKeyColumn, List<string> lPredictColumns, List<bool> lbPredictColumns, int parOne, int parTwo)
        {
            // drop existing model
            if (objStructure.MiningModels.ContainsName(sModelName))
                objStructure.MiningModels[sModelName].Drop();

            // Detailed description of the model algorithms is here:
            // http://msdn.microsoft.com/en-us/library/ms175595.aspx

            // More customisation for these algorithms can be found here:
            // http://msdn.microsoft.com/en-us/library/cc280427.aspx

            // Also a model example can be found here:
            // http://msdn.microsoft.com/en-us/library/ms345087(v=SQL.100).aspx

            Microsoft.AnalysisServices.MiningModel myMiningModel = objStructure.CreateMiningModel(true, sModelName);
            myMiningModel.Algorithm = sAlgorithm;

            switch (sAlgorithm)
            {
                case MiningModelAlgorithms.MicrosoftClustering:
                    myMiningModel.AlgorithmParameters.Add("CLUSTERING_METHOD", parOne);
                    myMiningModel.AlgorithmParameters.Add("CLUSTER_COUNT", parTwo);
                    break;
                //case MiningModelAlgorithms.MicrosoftTimeSeries:
                //    myMiningModel.AlgorithmParameters.Add("PERIODICITY_HINT", "{12}");              // {12} represents the number of months for prediction
                //    break;
                case MiningModelAlgorithms.MicrosoftNaiveBayes:
                    break;
                case MiningModelAlgorithms.MicrosoftDecisionTrees:
                    myMiningModel.AlgorithmParameters.Add("SCORE_METHOD", parOne);
                    myMiningModel.AlgorithmParameters.Add("SPLIT_METHOD", parTwo);
                    break;
            }

            /***************** Predict columns *****************/
            // add optional predict columns
            if (lPredictColumns.Count != 0)
            {
                // predict columns
                for (int i = 0; i < lPredictColumns.Count; i++)
                {
                    Microsoft.AnalysisServices.MiningModelColumn modelColumn = myMiningModel.Columns.GetByName(lPredictColumns[i]);
                    modelColumn.SourceColumnID = lPredictColumns[i];

                    if (lbPredictColumns[i] == true)
                        modelColumn.Usage = MiningModelColumnUsages.PredictOnly;
                    else
                        modelColumn.Usage = MiningModelColumnUsages.Predict;
                }
            }

            myMiningModel.Update();
        }
Ejemplo n.º 4
0
        /*
         * Create mining model for the selected mining strucutre
         */
        private void CreateModels(MiningStructure objStructure)
        {
            MiningModel ClusterModel;
            MiningModel TreeModel;
            MiningModelColumn mmc;

            // Create the Cluster model and set the algorithm
            // and parameters
            DropExistingMiningModels(objStructure, sModelName);
            ClusterModel = objStructure.CreateMiningModel(true, sModelName);
            ClusterModel.Algorithm = MiningModelAlgorithms.MicrosoftClustering;// "Microsoft_Clustering";
            ClusterModel.AlgorithmParameters.Add("CLUSTER_COUNT", 0);
            ClusterModel.Update();

            // The CreateMiningModel method adds
            // all the structure columns to the collection
            // Copy the Cluster model and change the necessary properties
            TreeModel = ClusterModel.Clone();
            DropExistingMiningModels(objStructure, sModelName + "Generation Trees");
            TreeModel.Name = sModelName + "Generation Trees";
            TreeModel.ID = sModelName + "Generation Trees";
            TreeModel.Algorithm = MiningModelAlgorithms.MicrosoftDecisionTrees;// "Microsoft_Decision_Trees";
            TreeModel.AlgorithmParameters.Clear();
            TreeModel.Columns["Gender"].Usage = "Predict";
            //TreeModel.Columns["PayChannels"].Usage = "Predict";

            // Add an aliased copy of the PayChannels table to the trees model
            mmc = TreeModel.Columns.Add("MaritalStatus");
            mmc.SourceColumnID = "MaritalStatus";
            mmc = mmc.Columns.Add("MaritalStatus");
            mmc.SourceColumnID = "MaritalStatus";
            mmc.Usage = "Key";
            // Now set a filter on the PayChannels_Hbo_Encore table and use it
            // as input to predict other channels

            //TreeModel.Columns["PayChannels_Hbo_Encore"].Filter = "Channel=’HBO’ OR Channel=’Encore’";
            // Set a complementary filter on the payChannels predictable
            // nested table

            //TreeModel.Columns["PayChannels"].Filter = "Channel<>’HBO’ AND Channel<>’Encore’";
            objStructure.MiningModels.Add(TreeModel);

            // Submit the models to the server
            // ToDo: fix this
            //TreeModel.Update();
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Generate a mining structure and full process it
        /// </summary>
        /// <param name="objDatabase">Analysis Service Database instance</param>
        /// <param name="objDataSourceView">Analysis Service DataSourceView instance</param>
        /// <param name="strCaseTableName">Mining table name</param>
        /// <returns>Mining structure</returns>
        public static object GenerateMiningStructure(Database objDatabase, DataSourceView objDataSourceView, string strCaseTableName, DecisionTreeAlgorithmParameters dtParams)
        {
            try
            {

                MiningStructure objMiningStructure = new MiningStructure();
                objMiningStructure = objDatabase.MiningStructures.Add(objDatabase.MiningStructures.GetNewName(StringEncode(strCaseTableName)));
                objMiningStructure.HoldoutMaxPercent = dtParams.HoldoutMaxPercent; // Percent for testing
                objMiningStructure.Source = new DataSourceViewBinding(objDataSourceView.ID);
                objMiningStructure.CaseTableName = strCaseTableName;

                foreach (string name in getAllColumnName(objDataSourceView, strCaseTableName))
                {
                    string colName = StringEncode(name);
                    ScalarMiningStructureColumn column = new ScalarMiningStructureColumn(colName, colName);
                    switch (colName)
                    {
                        case "ID":
                            // ProfileBasicId column
                            column.Type = MiningStructureColumnTypes.Long;
                            column.Content = MiningStructureColumnContents.Key;
                            column.IsKey = true;

                            // Add data binding to the column
                            column.KeyColumns.Add(strCaseTableName, name);
                            // Add the column to the mining structure
                            objMiningStructure.Columns.Add(column);
                            break;
                        case "ProfileBasicId":
                        case "JobPostingId":
                        case "UserId":
                        case "JobTitle":
                        case "JobName":
                        case "CompanyId":
                        case "CompanyName":
                            //column.Type = MiningStructureColumnTypes.Text;
                            //column.Content = MiningStructureColumnContents.Discrete;
                            break;
                        case "IsApproved":
                        default:
                            column.Type = MiningStructureColumnTypes.Boolean;
                            column.Content = MiningStructureColumnContents.Discrete;

                            // Add data binding to the column
                            column.KeyColumns.Add(strCaseTableName, name);
                            // Add the column to the mining structure
                            objMiningStructure.Columns.Add(column);
                            break;
                    }

                }

                MiningModel objMiningModel = objMiningStructure.CreateMiningModel(true, StringEncode(strCaseTableName));
                //MiningModel objMiningModel = objMiningStructure.MiningModels.Add(objMiningStructure.MiningModels.GetNewName(strMiningStructureName));
                objMiningModel.Algorithm = MiningModelAlgorithms.MicrosoftDecisionTrees;
                objMiningModel.AllowDrillThrough = true;
                objMiningModel.AlgorithmParameters.Add("SCORE_METHOD", dtParams.SCORE_METHOD);
                objMiningModel.AlgorithmParameters.Add("COMPLEXITY_PENALTY", dtParams.COMPLEXITY_PENALTY);
                objMiningModel.AlgorithmParameters.Add("SPLIT_METHOD", dtParams.SPLIT_METHOD);
                objMiningModel.AlgorithmParameters.Add("MAXIMUM_INPUT_ATTRIBUTES", dtParams.MAXIMUM_INPUT_ATTRIBUTES);
                objMiningModel.AlgorithmParameters.Add("MAXIMUM_OUTPUT_ATTRIBUTES", dtParams.MAXIMUM_OUTPUT_ATTRIBUTES);
                objMiningModel.AlgorithmParameters.Add("MINIMUM_SUPPORT", dtParams.MINIMUM_SUPPORT);

                int i = 0;
                foreach(MiningModelColumn col in objMiningModel.Columns)
                {
                    switch (col.Name)
                    {
                        case "IsApproved":
                            objMiningModel.Columns[i].Usage = "Predict";
                            break;
                        case "ID":
                            objMiningModel.Columns[i].Usage = "Key";
                            break;
                        default:
                            objMiningModel.Columns[i].Usage = "Input";
                            break;
                    }
                    ++i;
                }
                //objMiningModel.Update(UpdateOptions.ExpandFull);
                objMiningStructure.Update(UpdateOptions.ExpandFull);
                Console.WriteLine("Processing mining model " + objMiningStructure.Name + "...");
                objMiningModel.Process(ProcessType.ProcessFull);
                Console.WriteLine("Process " + objMiningStructure.Name + " finished!");
                return objMiningStructure;
            }
            catch (Exception ex)
            {
                throw new Exception("Error in Creating a Mining structure - GenerateMiningStructure. Error Message -> " + ex.Message);
            }
        }