3. Predictive Modelling: From Correlation to Supervised Segmentation - 6bolin9/Data-Science-For-Business-Foster-Provost-and-Tom-Fawcett- GitHub Wiki
Basic Concepts of Predictive Modeling
-
Fundamental concepts: Identifying informative attributes; Segmenting data by progressive attribute selection.
-
Exemplary techniques: Finding correlations; Attribute/variable selection; Tree induction.
-
Finding or selecting important, informative variables or “attributes” of the entities described by the data.
What exactly it means to be “informative” varies among applications, but generally, information is a quantity that reduces uncertainty about something. The better the information, the more my uncertainty is reduced.- "is there one or more other variables that reduce our uncertainty about the value of the target?" we would like to find knowable attributes that correlate with the target of interest—that reduce our uncertainty in it. Just finding these correlated variables may provide important insight into the business problem.
- Finding informative attributes also is the basis for a widely used predictive modeling technique called tree induction.
Models, Induction, and Prediction.
a model is a simplified representation of reality created to serve a purpose.
Predictive VS Descriptive Model
- a predictive model is a formula for estimating the unknown value of interest: the target. The formula could be mathematical, or it could be a logical statement such as a rule. Often it is a hybrid of the two.
- descriptive model: the primary purpose of the model is not to estimate a value but instead to gain insight into the underlying phenomenon or process.
A descriptive model of churn behavior would tell us what customers who churn typically look like.
A descriptive model must be judged in part on its intelligibility, and a less accurate model may be preferred if it is easier to understand. A predictive model may be judged solely on its predictive performance, although we will discuss why intelligibility is nonetheless important. The difference between these model types is not as strict as this may imply; some of the same techniques can be used for both, and usually, one model can serve both purposes (though sometimes poorly). Sometimes much of the value of a predictive model is in the understanding gained from looking at it rather than in the predictions it makes.
Induction VS Deduction
- The creation of models from data is known as model induction. Induction is a term from a philosophy that refers to generalizing from specific cases to general rules (or laws, or truths). Models are general rules in a statistical sense, and the procedure that creates the model from the data is called the induction algorithm or learner.
- Deduction starts with general rules and specific facts and creates other specific facts from them. The use of our models can be considered a procedure of (probabilistic) deduction.
How to judge Whether a variable contains important information about the target variable? How much?
Attributes:head-shape: square, circular; body-shape: rectangular, oval; body-color: gray, white; Target variable:write-off: Yes, No.
we seldom expect to find a variable that will make the segments pure. But if we can reduce the impurity substantially, we can use the attribute in a predictive model, predicting that members of one segment will have higher or lower write-off rates than those in another segment.
Create a formula that evaluates how well each attribute splits a set of examples into segments, with respect to a chosen target variable. Such a formula is based on a purity measure.
The most common splitting criterion is called information gain, and it is based on a purity measure called entropy. Both concepts were invented by one of the pioneers of information theory, Claude Shannon, in his seminal work in the field (Shannon, 1948).
Each pi is the probability of property i within the set, ranging from pi = 1 when all members of the set have property i, and pi = 0 when no members of the set have property i.
- For example: consider a set S of 10 people with seven of the non-write-off class and three of the write-off class.

how informative an attribute is with respect to our target:
- How much gain in the information an attribute gives us about the value of the target variable.
An attribute segments a set of instances into several subsets. Entropy only tells us how impure one individual subset is. - Use entropy to measure how disordered any set is,
- Define information gain (IG) to measure how much an attribute improves (decreases) entropy over the whole segmentation it creates.
Information gain measures the change in entropy due to any amount of new information being added.- For example, the attribute we split on has k different values. Call the original set of examples the parent set, and the result of splitting on the attribute values the k children sets.
- Information gain is a function of both a parent set and of the children resulting from some partitioning of the parent set.
- How much purer the children are than the parent?
The entropy for each child (ci) is weighted by the proportion of instances belonging to that child, p(ci).Noticing that that set is pure, may not be as good as splitting the parent set into two nice large, relatively pure subsets, even if neither is pure.
One basic measure of attribute information is called information gain, which is based on a purity measure called entropy; another is variance reduction.
分别计算 target variable 和变量1/变量2的: entropy(parent), entropy(变量的每个level), 在计算information gaine
通过比较两个看量information gain 的大小区别去确定变量的重要性。 It does not require absolute purity. It can be applied to any number of child subsets. It takes into account the relative sizes of the children, giving more weight to larger subsets.
- A natural measure of impurity for numeric values is variance.
- finding variables that have the best correlation with the target, o are most predictive of the target.
Mushroom Classification Example: 1/0 ~ many attributes
find the single attribute that gives the highest information gain
- entropy is 0.96 (number of 1 and 0 in target variable), If the two classes were perfectly balanced in the dataset it would have an entropy of 1.
- For each attribute(color), and one level (blue) of this attribute has its entropy and its proportions in the whole set.
- Calculate each attribute's total weighted sum entropy and compare their information gain: entropy(parent) - weighted sum entropy.
ODOR has the highest information gain of any attribute in the Mushroom dataset. It can reduce the dataset’s total entropy to about 0.1, which gives it an information gain of 0.96 – 0.1 = 0.86.
Many odors are completely characteristic of poisonous or edible mushrooms, so odor is a very informative attribute to check when considering mushroom edibility.If you’re going to build a model to determine the mushroom edibility using only a single feature, you should choose its odor. If you were going to build a more complex model you might start with the attribute ODOR before considering adding others.
Multivariate (multiple attributes) Supervised Segmentation
Decision Tree
The tree is made up of nodes, interior nodes and terminal nodes, and branches emanating from the interior nodes.
Following the branches from the root node down, each path eventually terminates at a terminal node or leaf. The tree creates a segmentation of the data: every data point will correspond to one and only one path in the tree, and thereby to one and only one leaf. In other words, each leaf corresponds to a segment, and the attributes and values along the path give the characteristics of the segment.
- one would start at the root node and descend through the interior nodes,
- choosing branches based on the specific attribute values in the example
- the nonleaf nodes are often referred to as “decision nodes”
- at each node one uses the values of the attribute to make a decision about which branch to follow
Example: classified one people into a segment defined by (Employed=No, Balance=115K, Age<45) whose classification is Not Write -off.
- In practice: predict the probability of membership in the class (e.g., the probability of churn or the probability of write-off), rather than the class itself.

- The tree model is a recursive process of divide and conquer, where the goal at each step is to select an attribute to partition the current group into subgroups that are as pure as possible with respect to the target variable.

Decision Trees as Sets of Rules
If we trace down a single path from the root node to a leaf, collecting the conditions as we go, we generate a rule. Each rule consists of the attribute tests along the path connected with AND. The classification tree is equivalent to this rule set.
Probability Estimation: an estimate of the probability of membership in the different classes
For example, in the churn-prediction problem, rather than simply predicting whether a person will leave the company within 90 days of contract expiration, we would much rather have an estimate of the probability that he will leave the company within that time.
Rank prospects by their probability of leaving, and then allocate a limited incentive budget to the highest probability instances. Alternatively, allocate your incentive budget to the instances with the highest expected loss.
- Frequency-based estimate of class membership probability: if a leaf contains n positive instances and m negative instances, the probability of any new instance being positive may be estimated as n/(n+m).
- Prevent overfitting: use a “smoothed” version of the frequency-based estimate, Laplace correction.
n is the number of examples in the leaf belonging to class c, and m is the number of examples not belonging to class c.
- 20 right and 0 error (0.95) VS 2 right and 0 error (0.75): the effect of Laplace correction on several class ratios as the number of instances increases
Effect of Laplace correction on several class ratios
The number of instances increases (2/3, 4/5, and 1/1). For each ratio, the solid horizontal line shows the uncorrected (constant) estimate, while the corresponding dashed line shows the estimate with the Laplace correction applied. The uncorrected line is the asymptote of the Laplace correction as the number of instances goes to infinity.随着样本量的增加,Laplace correction逐渐能够接近于真实值。

Addressing the Churn Problem with Tree Induction
- Attributes for the cellular phone churn-prediction problem:
- Variables: college, annual income, Average overcharges per month, Average number of leftover minutes per month, Estimated value of dwelling (from census tract), Cost of the phone, Average number of long calls (15 mins or over) per month, Average duration of a call, Reported level of satisfaction, Self-reported usage level.
- Target Variable: Did the customer stay or leave (churn)? ---Leave.
- We want to use these data with our tree induction technique to predict which new customers are going to churn.
- The resulting tree-structured model partitions the space of all possible instances into a set of segments with different predicted values for the target.
- For example, when the target is a binary “class” variable, each leaf of the tree corresponds to a population segment with a different estimated probability of class membership
Use these data with our tree induction technique to predict which new customers are going to churn.
- How good are each of these variables individually? : measure the information gain of each attribute, as discussed earlier. Ranks:

- Applying a classification tree algorithm.
- The highest information gain feature (HOUSE) according to the picture is at the root of the tree.
- The second best feature, OVERAGE, also appears high in the tree. However, the order in which features are chosen for the tree doesn’t exactly correspond to their independent ranking.
- The tree achieved 73% accuracy on its decisions--- raises two questions:
- First, do you trust this number? If we applied the tree to another sample of 20,000 people from the same dataset, do you think we’d still get about 73% accuracy?
- If you do trust the number, does it mean this model is good? In other words, is a model with 73% accuracy worth using?
Research on tree induction goes back at least to the 1950s and 1960s. Some of the earliest popular tree induction systems include CHAID (Chi-squared Automatic Interaction Detection) (Kass, 1980) and CART (Classification and Regression Trees) (Breiman, Friedman, Olshen, & Stone, 1984), which are still widely used. C4.5 and C5.0 are also very popular tree induction algorithms, which have a notable lineage (Quinlan, 1986, 1993). J48 is a reimplementation of C4.5 in the Weka package (Witten & Frank, 2000; Hall et al., 2001).
In practice, tree-structured models work remarkably well, though they may not be the most accurate model one can produce from a particular data set.
Each pi is the probability of property i within the set, ranging from pi = 1 when all members of the set have property i, and pi = 0 when no members of the set have property i.