I build my DataMining DecisionTrees in SQL Server 2005.
How can I get the tree graph in DataMining DecisionTrees by C# coding ?
Start by adding a reference to Microsoft.AnalysisServices.AdomdClient
Then, create a new AdomdConnection and connect to the server:
AdomdConnection cn = new AdomdConnection();
cn.ConnectionString = "Data Source=localhost; Initial Catalog=MyDatabase"
cn.Open();
Continue by creating a Command object, associated with the connection
AdomdCommand cmd = new AdomdCommand(); cmd.Connection = cn;
Using the command object, you can now issue queries. A query like:
SELECT * FROM MyModel.CONTENT
will return all the content nodes, for all the trees in the model (there is one tree for each predictable attribute of the model)
Now, each node has multiple properties, returned by the query above as columns. Particularly important for the tree structure are the NODE_UNIQUE_NAME and the PARENT_UNIQUE_NAME columns. NODE_UNIQUE_NAME is a unique identifier of each node, PARENT_UNIQUE_NAME is the unique identifier of the parent. You can use this relationship to build the tree structure.
The content has one root node, which represents the mining model. This node is the first one returned by the SELECT * FROM Model.CONTENT query, it has PARENT_UNIQUE_NAME empty and the NODE_TYPE property has the value of 1. This node should not appear in the tree visualizer.
Its descendants are the root nodes for all the trees built by the mining model. These are direct children of the root node and have NODE_TYPE = 2.
The NODE_UNIQUE_NAME/PARENT_UNIQUE_NAME should be enough to build the rest of the tree.
Now, each node has a NODE_DISTRIBUTION property, returned by the query as a nested table (if you use cmd.ExecuteReader to get the query results, you will get an AdomdDataReader object for the result and you can use the GetDataReader method to obtain a reader for the nested table). The NODE_DISTRIBUTION table contains the distribution for each node. If the tree is a regression tree (continuous target), the NODE_DISTRIBUTION for the leafs contains the regression formula coefficients
Hope this helps,
|||Very very helpful, thanks a lot|||Microsoft.AnalysisServices.Controls.DLL
Microsoft.AnalysisServices.Viewers.DLL
Microsoft.DataWarehouse.DLL
No comments:
Post a Comment