A mining structure is the definition of the data structure that is used to create all mining models. A mining structure contains a binding to a data source view that is defined in the database, and contains definitions for all columns participating in the mining models. A mining structure can have more than one mining model.
Creating a MiningStructure object requires the following steps:
-
Create the MiningStructure object and populate the basic attributes. Basic attributes include object name, object ID (internal identification), and data source binding.
-
Create columns for the model. Columns can be either scalar or table definitions.
Each column needs a name and internal ID, a type, a content definition, and a binding.
-
Update the MiningStructure object to the server, by using the Update method of the object.
Mining structures can be processed, and when they are processed, the children mining models are processed or retrained.
The following sample code creates a mining structure to forecast sales in a time series. Before running the sample code, make sure that the database db, passed as parameter for CreateSalesForecastingMiningStructure, contains in db.DataSourceViews[0] a reference to the view dbo.vTimeSeries in the AdventureWorksDW sample database.
public static MiningStructure CreateSalesForecastingMiningStructure(Database db)
{
MiningStructure ms = db.MiningStructures.FindByName("Forecasting Sales Structure");
if (ms != null)
ms.Drop();
ms = db.MiningStructures.Add("Forecasting Sales Structure", "Forecasting Sales Structure");
ms.Source = new DataSourceViewBinding(db.DataSourceViews[0].ID);
ScalarMiningStructureColumn amount = ms.Columns.Add("Amount", "Amount");
amount.Type = MiningStructureColumnTypes.Double;
amount.Content = MiningStructureColumnContents.Continuous;
amount.KeyColumns.Add("vTimeSeries", "Amount", OleDbType.Currency);
ScalarMiningStructureColumn modelRegion = ms.Columns.Add("Model Region", "Model Region");
modelRegion.IsKey = true;
modelRegion.Type = MiningStructureColumnTypes.Text;
modelRegion.Content = MiningStructureColumnContents.Key;
modelRegion.KeyColumns.Add("vTimeSeries", "ModelRegion", OleDbType.WChar, 56);
ScalarMiningStructureColumn qty = ms.Columns.Add("Quantity", "Quantity");
qty.Type = MiningStructureColumnTypes.Long;
qty.Content = MiningStructureColumnContents.Continuous;
qty.KeyColumns.Add("vTimeSeries", "Quantity", OleDbType.Integer);
ScalarMiningStructureColumn timeIndex = ms.Columns.Add("TimeIndex", "TimeIndex");
timeIndex.IsKey = true;
timeIndex.Type = MiningStructureColumnTypes.Long;
timeIndex.Content = MiningStructureColumnContents.KeyTime;
timeIndex.KeyColumns.Add("vTimeSeries", "TimeIndex", OleDbType.Integer);
ms.Update();
return ms;
}