Monday, December 28, 2020

Building a Decision tree tensorflow.js application

 Building a Decision tree tensorflow.js application: 

Introduction: TensorFlow is a machine learning framework for JavaScript applications. It helps us build models that can be directly used in the browser or in the node.js server. We use this framework for building an application that can find similar requests so that they might be used for prediction. 

Description: The JavaScript application uses data from a CSV that has categorizations of requests and the resolution time. The attributes of each request include a category_id, a few attributes, and the execution time. The data used in this sample has 1200 records. 

As with any ML learning example, the data is split into 70% training set and 30% test set. There is no order to the data and the split is taken over a random set.  

The model chosen is a decision tree model. This model is appropriate for splitting data based on column value and recursively for each level of columns one after the other with all the rows. After training this model, it can be used to make a prediction. This model is described in detail here. TensorFlow makes it easy to construct this model using an API. It can only present the output after the model is executed. In this case, the model must be run before the weights are available.  The feature column and input functions are used to train the model. The output of each layer can be printed using the describe() method.  

With the model and training/test sets defined, it is now as easy to evaluate the model and run the inference.  The model can also be saved and restored. It executed faster when there is GPU added to the computing. 

The features are available with the feature_extractor. It is evaluated on the training set using model.compile() and model.fit(). The model can then be called on a test input. Additionally, if a specific layer was to be evaluated, we can call just that layer on the test input. 

When the model is trained, it makes several passes of the entire training dataset It is helpful to visualize the training with the help of a high chart that shows the reasoning for the decision tree split at that level. 

When the model is tested, it predicts the resolution time for the given attributes of category_id and parameter attributes 

Conclusion: Tensorflow.js is becoming a standard for implementing machine learning models. Its usage is fairly simple but the choice of model and the preparation of data takes significantly more time than setting it up, evaluating, and using it. 

 

 

Sunday, December 27, 2020

Building a sample tensorflow.js application:


Introduction: TensorFlow is a machine learning framework for JavaScript applications. It helps us build models that can be directly used in the browser or in the node.js server. We use this framework for building an application that can predict request resolution time. 

Description: This JavaScript application uses data from a csv that has categorizations of requests and the resolution time. The attributes of each request include a category_id, a pseudo parameter attribute, and the execution time. This data is fabricated but it is also simplified to keep the application simple. 

As with any ML learning example, the data is split into 70% training set and 30% test set. There is no order to the data and the split is taken over a random set.  

The model chosen is a Sequential model. This model is appropriate for a plain stack of layers where each layer has exactly one input tensor and one output tensor.   Layers act in succession taking the output of one as the input of another. Thus, this model is suitable for one input and one output and where the layers are distinct and not sharing any input.  

Another model that can be used is one that is more generic and loads an acyclic graph.  A sequential model only uses a linear stack of layers. The input or output of the layers must be specified. A convolutional layer creates a convolution kernel which is a small matrix of weights. The kernel slides over the input layer and performs an element wise multiplication with the part of the input the kernel is on. The resulting scalar forms the element of a new kernel. This resulting kernel is called the convolution kernel. The graph model and sequential model can both be used with a tensor or a scalar. 

TensorFlow makes it easy to construct this model using an API keras Sequential. It can only present the hidden weight matrix after the model is executed. In this case, the model must be run before the weights are available.  The output of each layer can be printed using the summary() method.  

With the model and training/test sets defined, it is now as easy to evaluate the model and run the inference.  The model can also be saved and restored. It executed faster when there is GPU added to the computing. 

The features are available with the feature_extractor. It is evaluated on the training set using model.compile() and model.fit(). The model can then be called on a test input. Additionally, if a specific layer was to be evaluated, we can call just that layer on the test input. 

When the model is trained, it can be done in batches of predefined size. The number of passes of the entire training dataset called epochs can also be set upfront. It is helpful to visualize the training with the help of a high chart that updates the chart with the loss after each epoch 

When the model is tested, it predicts the resolution time for the given attributes of category_id and parameter attribute 

Conclusion: Tensorflow.js is becoming a standard for implementing machine learning models. Its usage is fairly simple but the choice of model and the preparation of data takes significantly more time than setting it up, evaluating, and using it. 

 

 

Saturday, December 26, 2020

Decision Tree modeling on IT Service requests

Decision Tree modeling on IT Service requests:  

   

Introduction: Service requests are opened by customers who report a problem and request mitigation. The IT department is a magnet for virtually all computing, storage, and networking related tasks requested by its customers. It is usually far more than the IT team can resolve quickly. In this regard, the IT teams look for automation that can provide self-service capabilities to users. The decision tree algorithm allows for predictions based on earlier requests such as the estimation of relief time based on past attributes for earlier requests. This article describes the implementation aspect of decision tree modeling.  Although linear regressions are useful in the prediction of a single column variable, decision trees can build on their own and are easy to visualize which allows experts to show the reasoning process and allows users to judge the quality of prediction. 

Description:  

The centerpiece of this technique involves both a classification and a regression tree. A function divides the rows into two datasets based on the value of a specific column. The two lists of rows that are returned are such that one set matches the criteria for the split while the other does not. When the attribute to be chosen is clear, this works well. 

To see how good an attribute is, the entropy of the whole group is calculated.  Then the group is divided by the possible values of each attribute and the entropy of the two new groups is calculated. The determination of which attribute is best to divide on, the information gain is calculated which is the difference between the current entropy and the weighted-average entropy of the two new groups. The algorithm calculates the information gain for every attribute and chooses the one with the highest information gain. 

Each set is subdivided only if the recursion of the above step can proceed. The recursion is terminated if a solid conclusion has been reached which is a way of saying that the information gain from splitting a node is no more than zero. The branches keep dividing, creating a tree by calculating the best attribute for each new node. If a threshold for entropy is set, the decision tree is ‘pruned’.  

When working with a set of tuples, it is easier to reserve the last one for results during a recursion level. Text and numeric data do not have to be differentiated for this algorithm to run. The algorithm takes all the existing rows and assumes the last row is the target value. A training/testing dataset is used with the application for each dataset. Usually, a training/testing data split of 70/30% is used in this regard.