Payment of ₹ requested by HONEY VIG. Click the link to pay securely via Razorpay: Make 5000 payment Payment of ₹ requested by HONEY VIG. Click the link to pay securely via Razorpay: Make 5000 payment ⭐ If you would like to buy me a coffee, well thank you very much that is mega kind! : https://www.buymeacoffee.com/honeyvig
Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies
Showing posts with label Classification Model. Show all posts
Showing posts with label Classification Model. Show all posts

Tuesday, October 7, 2025

pro/con, overview, and recommendations comparison of the technologies and platforms

 

Here’s a detailed pro/con, overview, and recommendations comparison of the technologies and platforms you listed, structured to give you clear guidance on strengths, limitations, and use cases for a web or app developer. I’ll also highlight potential drawbacks and strategic recommendations.


1. Microsoft .NET Stack

Technologies: ASP.NET, VB.NET, C#, AJAX, JQuery, Kentico, SmartStore.Net, Infragistics, Telerik, Atalasoft, ABCpdf, GoJS, OpenXml, xmlrpcnet

Pros:

  • Strong enterprise-level performance and security.

  • Rich IDE support via Visual Studio.

  • Mature ecosystem for web, desktop, and mobile apps.

  • Component libraries (Infragistics, Telerik) accelerate UI development.

  • Excellent integration with MSSQL and MSAccess.

  • Good reporting/document generation tools (ABCpdf, Atalasoft).

Cons:

  • Licensing costs for some enterprise tools and libraries.

  • Steeper learning curve for complex frameworks.

  • Heavyweight compared to lightweight PHP or Node.js apps.

Recommendations:

  • Best suited for enterprise applications, e-commerce (SmartStore.Net), and document-heavy apps.

  • Consider ASP.NET Core for cross-platform flexibility.

  • Use AJAX and JQuery carefully; modern Angular/React/Vue may be better for SPAs.

Drawbacks/Warnings:

  • Overkill for small projects.

  • Updates to Telerik/Infragistics require maintenance attention.


2. PHP & Open Source CMS

Technologies: PHP, Joomla, WordPress, OpenCart, Magento, Squarespace, Zoho

Pros:

  • Fast development for websites and e-commerce.

  • Huge community support and plugin ecosystem.

  • WordPress and Joomla are ideal for content-heavy sites.

  • Magento/OpenCart are strong for e-commerce customization.

  • Zoho integration helps automate business workflows without heavy coding.

Cons:

  • Security vulnerabilities if plugins/themes aren’t updated.

  • Performance can degrade on large-scale sites without proper optimization.

  • Magento can be resource-heavy.

Recommendations:

  • Use WordPress/Joomla for blogs, CMS, and marketing websites.

  • Use Magento/OpenCart for mid-to-large e-commerce sites.

  • Leverage Zoho for CRM/ERP integration.

Drawbacks/Warnings:

  • Customizing core CMS code is tricky; plugin conflicts can arise.

  • PHP performance may lag compared to compiled .NET apps under high load.


3. Databases

Technologies: MSSQL, MySQL, MSAccess

Pros:

  • MSSQL: Great for enterprise apps, strong integration with .NET.

  • MySQL: Lightweight, open-source, widely supported by PHP apps.

  • MSAccess: Simple desktop databases, easy for prototypes.

Cons:

  • MSSQL: Licensing costs; Windows-centric.

  • MSAccess: Not suitable for large-scale web apps.

Recommendations:

  • MSSQL for enterprise, large-scale systems.

  • MySQL for open-source CMS or mid-level apps.

  • Avoid MSAccess for production web apps.


4. Frontend / Web Design

Technologies: Dreamweaver, CSS, HTML/XHTML, JavaScript, Web 2.0 design

Pros:

  • Standard web technologies ensure broad compatibility.

  • Dreamweaver provides a visual design + code workflow.

  • Web 2.0 design is user-friendly and interactive.

Cons:

  • Dreamweaver is outdated compared to VSCode or WebStorm.

  • Pure HTML/CSS/JS can be cumbersome for complex SPAs.

Recommendations:

  • Use modern frameworks (Angular, React, Vue) for SPAs.

  • CSS preprocessors (SASS/LESS) improve maintainability.


5. Mobile App Development

Technologies: Ionic Framework, Cordova, PhoneGap, Android app customizations

Pros:

  • Cross-platform development reduces cost and time.

  • Familiar web technologies (HTML, JS, CSS) for hybrid apps.

Cons:

  • Performance lags compared to native apps.

  • Plugin compatibility issues can arise with complex native features.

Recommendations:

  • Best for MVPs, simple business apps, or web-view heavy apps.

  • For high-performance apps, consider native Android/iOS or Flutter/React Native.


6. Frontend JavaScript Frameworks

Technologies: AngularJS, BackboneJS, KnockoutJS, JQuery

Pros:

  • AngularJS: Full-featured MV* framework, two-way binding.

  • BackboneJS/KnockoutJS: Lightweight frameworks for structured JS apps.

  • JQuery: Easy DOM manipulation, legacy support.

Cons:

  • AngularJS is legacy; modern Angular or React is preferred.

  • BackboneJS and KnockoutJS are outdated for new projects.

Recommendations:

  • For new SPAs, choose Angular 14+/React/Vue.

  • Use JQuery only for legacy maintenance or small UI interactions.


Overall Recommendations:

  • Enterprise apps: .NET + MSSQL + Telerik/Infragistics.

  • CMS & e-commerce: PHP (WordPress/Joomla/OpenCart/Magento) + MySQL.

  • Hybrid mobile apps: Ionic + Cordova/PhoneGap.

  • Frontend SPAs: Modern Angular/React/Vue + CSS3/HTML5.

  • Document/Reporting-heavy apps: ABCpdf, Atalasoft, OpenXml.


Ah, I see—you want famous case studies or well-known examples where these technologies have been used successfully (or faced notable issues). Here’s a detailed rundown:


1. .NET & Enterprise Tools

Technologies: ASP.NET, C#, VB.NET, Telerik, Infragistics, Kentico, SmartStore.Net

Famous Cases:

  • Stack Overflow: Uses .NET and SQL Server for its Q&A platform, with C# on the backend.

  • Visual Studio Online / Azure DevOps: Built on .NET ecosystem.

  • Kentico: Powers brands like UNICEF, Canon Europe, and Sephora for enterprise CMS.

  • SmartStore.Net: Popular in European e-commerce SMEs.

Overhead Notes:

  • High licensing costs for Telerik/Infragistics.

  • Enterprise-level infrastructure needed for performance at scale.


2. PHP & Open Source CMS

Technologies: WordPress, Joomla, Magento, OpenCart, Squarespace

Famous Cases:

  • WordPress:

    • Used by TechCrunch, The New Yorker, BBC America.

    • Overhead mainly comes from plugins and updates; can slow down with heavy traffic.

  • Magento:

    • Coca-Cola, Nike, Ford stores for e-commerce.

    • Requires strong hosting; overhead in complex customizations.

  • OpenCart:

    • Used by Bata, small to mid-size stores globally.

    • Lightweight, but extensions can conflict.

  • Squarespace:

    • Creative agencies, Lyft Blog, Keanu Reeves site.

    • Limited backend flexibility, but low overhead for content management.


3. Databases

Technologies: MSSQL, MySQL, MSAccess

Famous Cases:

  • MSSQL:

    • Used by Stack Overflow, Dell, Microsoft Teams backend.

    • Overhead: Requires server resources and proper maintenance.

  • MySQL:

    • Facebook (initially), YouTube, Airbnb used MySQL heavily.

    • Lightweight, open-source, but can be bottlenecked without sharding/optimization.

  • MSAccess:

    • Internal corporate apps; often a prototype tool.

    • Overhead: Not scalable for web apps.


4. Frontend Technologies

Technologies: HTML, CSS, JavaScript, AngularJS, JQuery

Famous Cases:

  • AngularJS: Google’s Gmail, Google Fiber portal (legacy AngularJS).

  • JQuery: Widely used in WordPress themes, legacy apps, GitHub early UI.

  • Overhead: AngularJS legacy apps require migration; JQuery can bloat frontends if overused.


5. Hybrid Mobile Apps

Technologies: Ionic, Cordova, PhoneGap

Famous Cases:

  • Ionic:

    • MarketWatch, Sworkit, JustWatch apps.

    • Overhead: Limited native performance for graphics-heavy apps.

  • PhoneGap/Cordova:

    • Wikipedia mobile app (initially), Untappd.

    • Overhead: Plugin maintenance, slow updates for new OS features.


6. Document & Visualization Tools

Technologies: ABCpdf, Atalasoft, OpenXml, GoJS

Famous Cases:

  • ABCpdf / Atalasoft:

    • Enterprise document generation for banks, insurance firms.

    • High overhead: Licensing + server resources for PDF generation.

  • GoJS:

    • Used in Microsoft Visio Online diagrams, flowchart-heavy apps.

    • Overhead: Browser rendering heavy for very large datasets.


Summary Insight

  • Enterprise .NET + MSSQL: High-performance, high-overhead, used by large enterprises.

  • PHP / Open Source CMS: Fast to deploy, lower cost, some overhead from plugins/themes.

  • Hybrid Mobile Apps: Quick to market, lower cost, but performance overhead for complex apps.

  • Document-heavy apps: Need dedicated servers and licenses, overhead justified only for enterprise use.


Ah, I see—you want famous case studies or well-known examples where these technologies have been used successfully (or faced notable issues). Here’s a detailed rundown:


1. .NET & Enterprise Tools

Technologies: ASP.NET, C#, VB.NET, Telerik, Infragistics, Kentico, SmartStore.Net

Famous Cases:

  • Stack Overflow: Uses .NET and SQL Server for its Q&A platform, with C# on the backend.

  • Visual Studio Online / Azure DevOps: Built on .NET ecosystem.

  • Kentico: Powers brands like UNICEF, Canon Europe, and Sephora for enterprise CMS.

  • SmartStore.Net: Popular in European e-commerce SMEs.

Overhead Notes:

  • High licensing costs for Telerik/Infragistics.

  • Enterprise-level infrastructure needed for performance at scale.


2. PHP & Open Source CMS

Technologies: WordPress, Joomla, Magento, OpenCart, Squarespace

Famous Cases:

  • WordPress:

    • Used by TechCrunch, The New Yorker, BBC America.

    • Overhead mainly comes from plugins and updates; can slow down with heavy traffic.

  • Magento:

    • Coca-Cola, Nike, Ford stores for e-commerce.

    • Requires strong hosting; overhead in complex customizations.

  • OpenCart:

    • Used by Bata, small to mid-size stores globally.

    • Lightweight, but extensions can conflict.

  • Squarespace:

    • Creative agencies, Lyft Blog, Keanu Reeves site.

    • Limited backend flexibility, but low overhead for content management.


3. Databases

Technologies: MSSQL, MySQL, MSAccess

Famous Cases:

  • MSSQL:

    • Used by Stack Overflow, Dell, Microsoft Teams backend.

    • Overhead: Requires server resources and proper maintenance.

  • MySQL:

    • Facebook (initially), YouTube, Airbnb used MySQL heavily.

    • Lightweight, open-source, but can be bottlenecked without sharding/optimization.

  • MSAccess:

    • Internal corporate apps; often a prototype tool.

    • Overhead: Not scalable for web apps.


4. Frontend Technologies

Technologies: HTML, CSS, JavaScript, AngularJS, JQuery

Famous Cases:

  • AngularJS: Google’s Gmail, Google Fiber portal (legacy AngularJS).

  • JQuery: Widely used in WordPress themes, legacy apps, GitHub early UI.

  • Overhead: AngularJS legacy apps require migration; JQuery can bloat frontends if overused.


5. Hybrid Mobile Apps

Technologies: Ionic, Cordova, PhoneGap

Famous Cases:

  • Ionic:

    • MarketWatch, Sworkit, JustWatch apps.

    • Overhead: Limited native performance for graphics-heavy apps.

  • PhoneGap/Cordova:

    • Wikipedia mobile app (initially), Untappd.

    • Overhead: Plugin maintenance, slow updates for new OS features.


6. Document & Visualization Tools

Technologies: ABCpdf, Atalasoft, OpenXml, GoJS

Famous Cases:

  • ABCpdf / Atalasoft:

    • Enterprise document generation for banks, insurance firms.

    • High overhead: Licensing + server resources for PDF generation.

  • GoJS:

    • Used in Microsoft Visio Online diagrams, flowchart-heavy apps.

    • Overhead: Browser rendering heavy for very large datasets.


Summary Insight

  • Enterprise .NET + MSSQL: High-performance, high-overhead, used by large enterprises.

  • PHP / Open Source CMS: Fast to deploy, lower cost, some overhead from plugins/themes.

  • Hybrid Mobile Apps: Quick to market, lower cost, but performance overhead for complex apps.

  • Document-heavy apps: Need dedicated servers and licenses, overhead justified only for enterprise use.



Thursday, July 13, 2023

Machine Learning Model Evaluation Methods

 

Introduction

In both business and research, as we are getting more and more dependent on machine learning for solving strategic importance problems, real value must be added to organizations and business through the predictions that a machine learning model gives. While sometimes, we might have enough data that we use to train a model but it might so happen that it may not,in the future, be able to generalize to new data for which we wish to predict something.

Evaluating the model based on the data that we used for training makes little sense in assessing whether the model is a proper fit for the case. The reason being, the machine already learns from, what we call, the training data and when we try to predict for the same, then the machine remembers that correctly and by implication, predicts fairly well. This is called overfitting.

Our intention must be to see if the model generalizes well, so that it is able to predict correctly for new data, whether it actually works and how trustworthy the predictions are. For the purpose of the same, we have to use another data set which we call the test set to evaluate the model that we have trained.  

Types of Evaluation Methods

The two major ways in which a model is evaluated in through 1. Holding Out and 2. Cross Validation.  
  1. Holding Out - Consider a full dataset. For holding out method of validation, we use a large part of the data, say 80%, to train the model and test on the rest 20% of the data. This is called train test splitting. Another set, called the validation set is also taken from the data, in which we can try the model to draw conclusions on how we can improve the model performance, through changing the specifications of the model. Not all modelling need validation platform.
  2. Cross Validation - In this method we split the data in k-different folds, which will divide the data into k sets equally. The choice of k depends on the length of the dataset and might vary according to the analyst’s understanding of the same.  The validation of the model is done with keeping the ith set as test and using the rest of the sets as training. This is repeated k times, each time changing the dataset. All metrics which indicate the performance of the model are calculated k-times and an average of the same is considered the final indication of the performance of the model. Other than the k-fold cross validation that we discussed above, we also have Leave-One-Out Cross Validation(LOOCV), in which the data is divided into “n” parts, “n” being the length of the data. The testing is done on one point and other “n-1” parts are used in training. Process similar to K-Fold validation is followed to assess the performance of the model. 

Methods of Model Evaluation 

We can list numerous methods of evaluating the performance of the model. The main evaluation of the model is to check how low is the error in the predictions made by the model that we are building. There are different techniques that we can use to assess the error. The motive of making the optimum model is to reduce the error as much as possible. Regression models and Classification models are evaluated through different metrics and the choice of the same differs from model to model. This section explains some of the important methods which are used for machine learning models.

Methods for Regression:

a. Goodness of Fit ,RMSE & MAPE:
 In a regression model, to check whether the variations in the target variable is well  explained by the input what we give to the model is judged by , which is given by the following:
                                <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>R</mi><mrow><mn>2</mn><mo>&#xA0;</mo></mrow></msup><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><mn>1</mn><mo>&#xA0;</mo><mo>-</mo><mo>&#xA0;</mo><mfrac><mrow><mstyle displaystyle="true"><munder><mo>&#x2211;</mo><mi>i</mi></munder></mstyle><msup><mfenced><mrow><mi>y</mi><mo>-</mo><mover><mi>y</mi><mo>&#x23DE;</mo></mover></mrow></mfenced><mn>2</mn></msup></mrow><mrow><munder><mo>&#x2211;</mo><mi>i</mi></munder><msup><mfenced><mrow><mi>y</mi><mo>-</mo><menclose notation="top"><mi>y</mi></menclose></mrow></mfenced><mn>2</mn></msup></mrow></mfrac><mspace linebreak="newline"/></math>
     
Where y is the target variable y_hat is the estimated value and y_bar is the mean of the same. Higher the score, the better is the fit of the input data. A 0.9 value indicates that the input data is being able to explain 90% of the variations in the target variable.

RMSE or Root Mean Squared Error is defined as the square root of the sum of squares of the error. The sum of squares of error is given by the numerator in the above equation. It is defined as :

                                           <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mi>M</mi><mi>S</mi><mi>E</mi><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><msqrt><mstyle displaystyle="false"><munder><mo>&#x2211;</mo><mi>i</mi></munder></mstyle><msup><mfenced><mrow><mi>y</mi><mo>-</mo><mover><mi>y</mi><mo>&#x23DE;</mo></mover></mrow></mfenced><mn>2</mn></msup></msqrt></math>     
 The lower the RMSE, the better is the performance of the model.

The mean absolute percentage error (MAPE) is a statistical measure of how accurate a forecast system is. It measures this accuracy as a percentage, and can be calculated as the average absolute percent error for each time period minus actual values divided by actual values. Where At is the actual value and Ft is the forecast value, this is given by:


 The mean absolute percentage error (MAPE) is the most common measure used to forecast error, and works best if there are no extremes to the data .

b. Information Criteria:
Mainly two information criteria is used to evaluate the performance of the model. Here we must note that, these two information is used, mainly in which the estimation of the model is done using Maximum Likelihood Estimation methods and also used to select the best model from many models that we might have tried. The two information criteria is given as follows :

I. Akaike Information Criterion (AIC) : This is a method of scoring the models and selecting the models. The score statistic is given by :

                                                      AIC = -2/N * LL + 2 * k/N
 
Where N is the number of examples in the training dataset, LL is the log-likelihood of the model on the training dataset, and k is the number of parameters in the model. The model with the lowest AIC is selected. Compared to the BIC method (below), the AIC statistic penalizes complex models less, meaning that it may put more emphasis on model performance on the training dataset, and, in turn, select more complex models.

II. Bayesian Information Criterion (BIC) : Similar to AIC, this is also a method of scoring and selecting the models, and is based on Bayesian probability and inference.
                                            BIC = -2 * LL + log(N) * k

Where log() has the base-e called the natural logarithm, LL is the log-likelihood of the model, N is the number of examples in the training dataset, and k is the number of parameters in the model.

Methods for Classification

Unlike regression, classification problems deal with proper identification of the classes that the algorithm is supposed to predict. The evaluation based on numeric errors becomes meaningless. The methods through which we evaluate these models are as follows :

Classification Report 
A classification report is used to judge the predictions that are made by the algorithm. How many predictions are True and how many are False. More specifically, True Positives, False Positives, True negatives and False Negatives are used to predict the metrics of a classification report. Take the following example. Here, the classes that are getting predicted are Iris-setosa, Iris-versicolor and Iris-virginica


There are four ways to check if the predictions are right or wrong:
  1. TN / True Negative: when a case was negative and predicted negative
  2. TP / True Positive: when a case was positive and predicted positive
  3. FN / False Negative: when a case was positive but predicted negative
  4. FP / False Positive: when a case was negative but predicted positive
I. Precision
Measures the ability of a classifier not to label an instance positive that is actually negative. For each class it is defined as the ratio of true positives to the sum of true and false positives.
                              Precision = TP/(TP + FP)


II. Recall
Measures the ability of a classifier to find all positive instances. For each class it is defined as the ratio of true positives to the sum of true positives and false negatives.
                              Recall = TP/(TP+FN)


III. F1-Score
The F1 score is a weighted harmonic mean of precision and recall such that the best score is 1.0 and the worst is 0.0.
                 F1 Score = 2*(Recall * Precision) / (Recall + Precision)

IV. Area Under ROC curve
The ROC curve is locus of all points derived by plotting the true positive rate against the false positive rate at various threshold settings. Below is an example of a ROC curve.

The ROC curve is given by the orange line. The more the area under this curve, the better are the predictions.

Decision Tree Algorithm in Machine Learning

 

Decision Tree in ML


Decision Tree algorithm belongs to the family of supervised machine learning algorithm. It is simple and popular and is based on choices as suggested by its name. This algorithm works both for continuous as well as choice variables i.e. it can be used for both classification as well as regression problems. The article unfolds in three sections, commencing with a general introduction of the algorithm, followed by the mathematical concepts that builds the blocks for the same and we shall conclude with a code walk through on building a  Decision Tree model in Python using Loan approval data set.

1. Introduction

Decision Tree learns decision rules inferred from prior data that we use to train it. The motive is to predict the target variables or predict the class based on these decision rules. As the name suggests, the algorithm solves problems by using a tree representation. Each internal node of the tree are attributes and the leaf nodes corresponds to the class labels.

1.1. Terminology

Root Node: It represents the entire population or sample and this further gets divided into two or more homogeneous sets.
Splitting: It is a process of dividing a node into two or more sub-nodes.
Decision Node: When a sub-node splits into further sub-nodes, then it is called the decision node.
Leaf / Terminal Node: Nodes do not split is called Leaf or Terminal node.
Pruning: When we remove sub-nodes of a decision node, this process is called pruning. You can say the opposite process of splitting.
Branch / Sub-Tree: A subsection of the entire tree is called branch or sub-tree.
Parent and Child Node: A node, which is divided into sub-nodes is called a parent node of sub-nodes whereas sub-nodes are the child of a parent node.




Figure 1. A sample Decision Tree




2. Pseudocode and Assumptions
The best attribute should be set a:s the root of the tree.
Split the data set into subsets in such a way that the subset contains the same value as an attribute.
Repeat the above two steps till the leaf nodes of all the branches of the tree is found out.
For predicting a class label for a record we start from the root of the tree. We compare the values of the root attribute with the record's attribute. On the basis of comparison, we follow the branch corresponding to that value and jump to the next node. The process is continued till the leaf node is reached.

We must first assume the whole training set is first taken as the root in the beginning, and the feature values are preferred to be categorical in nature. In case the values are continuous, it is discretized prior to model training. All the entries/records are distributed recursively in the sense that, the distribution will give similar information repeatedly for similar types of records.   Decision Trees follow Sum of Product (SOP) representation. The Sum of product (SOP) is also known as Disjunctive Normal Form. For a class, every branch from the root of the tree to a leaf node having the same class is conjunction (product) of values, different branches ending in that class form a dis-junction (sum).

3. Attribute Selection and Mathematical Elucidations.

Let us suppose that there are “k” number of attributes in the data set and our first step, as discussed above would be to select an attribute which will be set as the root attribute of tree. Random selection of the root and subsequent nodes will be a great idea since the decision of making strategic splits heavily affects a tree’s accuracy. For the same purpose, researchers have come up with several criteria of attribute selection, to name a few:
  • Entropy
  • Information Gain
  • Gini Index
These criterions will calculate values for every attribute. The values are sorted, and attributes are placed in the tree by following the order i.e, the attribute with a high value(in case of information gain) is placed at the root.

3.1. Entropy
The degree of randomness in the information given by an attribute is measured by entropy. More the entropy, it becomes more ambiguous to draw any concrete conclusion from the information. Generally, in the tree a branch with zero entropy is placed at the terminal node and branches with more than zero entropy needs to be split further. Mathematically,
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>E</mi><mfenced><mi>S</mi></mfenced><mo>=</mo><munder><mo>&#x2211;</mo><mi>i</mi></munder><mo>-</mo><msub><mi>p</mi><mi>i</mi></msub><msub><mi>log</mi><mn>2</mn></msub><msub><mi>p</mi><mi>i</mi></msub></math>

Where, S is the current state, p is the probability of an event i in the state S. For multiple attributes,

3.2. Information Gain

Information gain or IG is a statistical property that measures how well a given attribute separates the training examples according to their target classification. The building of a Decision Tree is based on finding the attribute that has the highest information gain. It computes the difference between entropy before split and average entropy after split of the dataset based on given attribute values.

<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi><mi>n</mi><mi>f</mi><mi>o</mi><mi>r</mi><mi>m</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>&#xA0;</mo><mi>G</mi><mi>a</mi><mi>i</mi><mi>n</mi><mo>(</mo><mi>T</mi><mo>,</mo><mi>X</mi><mo>)</mo><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><mi>E</mi><mi>n</mi><mi>t</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>y</mi><mo>(</mo><mi>T</mi><mo>)</mo><mo>&#xA0;</mo><mo>-</mo><mo>&#xA0;</mo><mi>E</mi><mi>n</mi><mi>t</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>y</mi><mo>(</mo><mi>T</mi><mo>,</mo><mi>X</mi><mo>)</mo></math>
           

Where T is the state before split and X is the state after split.

3.3. Gini Index

Gini Index is used to evaluate the splits of the dataset by using a cost function. It is calculated by subtracting the sum of the squared probabilities of each class from 1. Unlike information gain, it favours large partitions and is simpler to implement and to be noted that it performs binary splits only. Higher the value of Gini index higher the homogeneity. Mathematically,
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi><mi>i</mi><mi>n</mi><mi>i</mi><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><mn>1</mn><mo>-</mo><mo>&#xA0;</mo><munder><mo>&#x2211;</mo><mi>i</mi></munder><msup><mfenced><msub><mi>p</mi><mi>i</mi></msub></mfenced><mn>2</mn></msup></math>



4. Decision Tree using Python

As discussed previously, here we shall build a simple decision tree model in this section. For the same we have used the loan approval dataset. The dataset could be used to do Classification as well as regression, although however we shall use Decision Tree classifier to predict whether loan should be approved or not.

###Import required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split 

Read the data:

#import the data
df = pd.read_csv("train.csv")
df.info()


Python gives output as follows:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 614 entries, 0 to 613
Data columns (total 13 columns):
Loan_ID              614 non-null object
Gender               601 non-null object
Married              611 non-null object
Dependents           599 non-null object
Education            614 non-null object
Self_Employed        582 non-null object
ApplicantIncome      614 non-null int64
CoapplicantIncome    614 non-null float64
LoanAmount           592 non-null float64
Loan_Amount_Term     600 non-null float64
Credit_History       564 non-null float64
Property_Area        614 non-null object
Loan_Status          614 non-null object
dtypes: float64(4), int64(1), object(8)
memory usage: 62.4+ KB

The data has attributes as shown above and is pretty much self explanatory in nature and with the help of which we will be predicting the Loan_Status, whether loan will be approved or not.
As we see, there is missing data in the set. One way is to either drop the variable but that comes with a cost of losing a lot of degrees of freedom. Here, we will use simplistic methods to impute the missing values in the data. It is not necessary that we go by such preprocessing methods as shown here. For simplicity let us do the following steps to modify the data.


#Data Preprocessing

df["Gender"].fillna("unknown",inplace = True)
df["Married"].fillna("unknown",inplace = True)
df["Credit_History"].fillna(df.Credit_History.mean(),inplace = True)
df["Dependents"].fillna(0,inplace = True)
df["LoanAmount"].fillna(df.LoanAmount.mean(),inplace = True)
df["Self_Employed"].fillna("No",inplace = True)
df["Loan_Amount_Term"].fillna(round(df.Loan_Amount_Term.mean()),inplace=True)

As shown above, missing gender and marital status is filled with “unknown”, Credit History and loan amount and the loan amount terms is filled in with the mean of the variables. Whether the person is self employed is given “No” and number of dependents has been given 0 if the data was missing. After the preprocessing, we have:


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 614 entries, 0 to 613
Data columns (total 13 columns):
Loan_ID              614 non-null object
Gender               614 non-null object
Married              614 non-null object
Dependents           614 non-null object
Education            614 non-null object
Self_Employed        614 non-null object
ApplicantIncome      614 non-null int64
CoapplicantIncome    614 non-null float64
LoanAmount           614 non-null float64
Loan_Amount_Term     614 non-null float64
Credit_History       614 non-null float64
Property_Area        614 non-null object
Loan_Status          614 non-null object
dtypes: float64(4), int64(1), object(8)
memory usage: 62.4+ KB

All the fields are non-null , we will go ahead with some more feature extraction.


In[]: df["Dependents"]= df["Dependents"].map({"0":int(0),"1":int(1),"2":int(2),"3+":int(3)})
Dependents is the number of people dependent on the loan applicant. Since they are ordinal in nature we shall just map it to integer numbers.    

Let us get the summary statistics of the data.


df.describe()

A simple does that for you in python, its given as follows:




Dependents
ApplicantIncome
CoapplicantIncome
LoanAmount
Loan_Amount_Term
Credit_History
Loan_Status
count
599
614
614
614
614
614
614
mean
1
5403
1621
146
342
1
0
std
1
6109
2926
84
64
0
0
min
0
150
0
9
12
0
0
0
0
2878
0
100
360
1
0
1
0
3813
1189
129
360
1
0
1
2
5795
2297
165
360
1
1
max
3
81000
41667
700
480
1
1


Loan status as discussed before is the target variable and is labelled in 0s and 1s.


For training and validating the model let’s split the data into training and testing set.


X_train , X_test , y_train , y_test =train_test_split(X,y,test_size=0.33, random_state=42)

We are keeping the test size as 1/3rd of the total size of the whole data set. As a next step we will create the model, first with the “Gini” criterion, then with the Entropy criterion. Then we will fit the model to the training data and then predict for the test data. The code is simple and is as follows:

Model using Gini Criterion

clf_gini = DecisionTreeClassifier(criterion = "gini",random_state = 100,max_depth=3, min_samples_leaf=5)
In[] : clf_gini.fit(X_train, y_train)
Out[]: DecisionTreeClassifier(class_weight=None, criterion='gini'
            ,max_depth=3,
            max_features=None, max_leaf_nodes=None,
            min_impurity_decrease=0.0, min_impurity_split=None,
            min_samples_leaf=5, min_samples_split=2,
            min_weight_fraction_leaf=0.0, presort=False, random_state=100,
            splitter='best')
y_pred = clf_gini.predict(X_test)

y_pred in the above code is the predicted values of the target.

Let’s evaluate the model.

print("Confusion Matrix: ", confusion_matrix(y_test, y_pred))
print ("Accuracy : ",accuracy_score(y_test,y_pred)*100)
print("Report : ", classification_report(y_test, y_pred))
 


Gives the following output:


Confusion Matrix:  [[129 2]
[ 48  24]]

Accuracy :  75.36945812807882
Report :               precision recall f1-score   support

          0 0.73      0.98 0.84   131
          1 0.92      0.33 0.49     72

avg / total       0.80 0.75   0.71 203





The accuracy with the model is 75%. Let’s check what happens if we use the entropy criterion.

Model with Entropy Criterion

clf_ent = DecisionTreeClassifier(criterion = "entropy",random_state = 42,
max_depth=3, min_samples_leaf=10)

clf_ent.fit(X_train, y_train)

Out[] : DecisionTreeClassifier(class_weight=None, criterion='entropy',             max_depth=3,
            max_features=None, max_leaf_nodes=None,
            min_impurity_decrease=0.0, min_impurity_split=None,
            min_samples_leaf=10, min_samples_split=2,
            min_weight_fraction_leaf=0.0, presort=False, random_state=42,
            splitter='best')


y_pred = clf_ent.predict(X_test)

y_pred is defined as before. The evaluation report is given as below:


print("Confusion Matrix: ", confusion_matrix(y_test, y_pred))
print ("Accuracy : ",accuracy_score(y_test,y_pred)*100)
print("Report : ", classification_report(y_test, y_pred))

The reports are given as below:

Confusion Matrix:  [[129 2]
[ 39  33]]
Accuracy :  79.80295566502463
Report :               precision recall f1-score   support

          0 0.77      0.98 0.86   131
          1 0.94      0.46 0.62     72

avg / total       0.83 0.80   0.78 203

As we see that, using “Entropy” gives a better accuracy than the “Gini” model.