Skip to content

Commit 390e8bc

Browse files
committed
full report submitted1
1 parent cbc7255 commit 390e8bc

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

finding_donors.ipynb

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@
745745
"print \"Naive Predictor: [Accuracy score: {:.4f}, F-score: {:.4f}]\".format(accuracy, fscore)"
746746
]
747747
},
748+
{
749+
"cell_type": "markdown",
750+
"metadata": {},
751+
"source": [
752+
"**Answer: ** \n",
753+
"The results of running the cell code above are:\n",
754+
"\n",
755+
"Naive Predictor accuracy score: 0.1986\n",
756+
"Naive Predictor F-score: 0.2365"
757+
]
758+
},
748759
{
749760
"cell_type": "markdown",
750761
"metadata": {},
@@ -915,7 +926,9 @@
915926
"cell_type": "markdown",
916927
"metadata": {},
917928
"source": [
918-
"**Answer: ** To aid in the selection of three models I generated a collection of bar graphs indicating the resulting f-score on the test set as well as the training times for each classifier. See figure above. I chose three classifiers yielding the highest f-score and reasonably short training times. Amongst the slow algorithms (righ-panel) I chose Gradient Boosting as it yielded the highest f-score of all classifiers tested; among the intermediate algorithms (middle panel) I chose logistic regression which runs fast and yields the best score in that group. In the left panel, I chose linear SVC as it yielded the hightes f-score in that group; Random Forest could have been a good choice as well.\n",
929+
"**Answer: ** To aid in the selection of three models I generated a collection of bar graphs indicating the resulting f-score on the test set as well as the training times for each classifier. See figure above that displays the results as bar chart plots. \n",
930+
"\n",
931+
"I chose three classifiers yielding the highest f-score and reasonably short training times. Amongst the slow algorithms (righ-panel) I chose Gradient Boosting as it yielded the highest f-score of all classifiers tested; among the intermediate algorithms (middle panel) I chose logistic regression which runs fast and yields the best score in that group. In the left panel, I chose linear SVC as it yielded the hightes f-score in that group; Random Forest could have been a good choice as well.\n",
919932
"\n",
920933
"\n",
921934
"** 1. Gradient Boosting:**\n",
@@ -1520,25 +1533,24 @@
15201533
"cell_type": "markdown",
15211534
"metadata": {},
15221535
"source": [
1523-
"**Answer:** To answer this question accurately we need to apply feature selection engineering methods. However, we may attempt first to gain insight about the features that could be informative and discriminating and/or those that could provide the highest information gain, say using a \"rule of thumb\" or heuristic criterion. \n",
1536+
"**Answer:** \n",
1537+
"To answer this question accurately we need to apply feature selection engineering methods. However, we may attempt first to gain insight about the features that could be informative and discriminating and/or those that could provide the highest information gain, say using a \"rule of thumb\" or heuristic criterion. \n",
15241538
"\n",
1525-
"First, we can remove subsets of features from the training dataset and observe whether their removal maintains or improves our predictive performance metric. Features that don't affect performance metrics according to an established criterion or tolerance will be deemed irrelevant. Features that imply some form or redundancy would be removed accordingly as well. \n",
1539+
"First, we can remove subsets of features from the training dataset and observe whether their removal maintains or improves our predictive performance metric. Features that don't affect performance metrics according to an established criterion or tolerance will be deemed irrelevant. Features that imply some form of redundancy or linear dependance on others would be removed accordingly as well. \n",
15261540
"\n",
15271541
"Second, we can try to estimate the purity of the feature or sufeatures that split into the classes of interest. Let us take a look at the subplots given above, each representing a selected feature, e.g education, occupation, etc. For categorical features we identify subfeatures representing a unique value of the parent feature and which splits the data classes, '<=50K' (black color) and '>50K' (green color); for continuous data each subfeature represents an interval and each interval splits the data in the same corresponding classes.\n",
15281542
"\n",
1529-
"Intution from visual inspection (\"rule of thumb\"):\n",
1543+
"Intuition from visual inspection (\"rule of thumb\"):\n",
15301544
"\n",
1531-
"When targeting a specific feature, we aim to identify the subfeatures with the highest purity, i.e. a clear separation or discrimination between two classes of interest; preferentially in our case, observing a higher proportion of individuals earning '>50K' in some of the subfeatures, i.e taller green bars somewhere in the attribute distribution.\n",
1545+
"When targeting a specific feature, we aim to identify the subfeatures with the highest purity, i.e. a clear separation or discrimination between two classes of interest; preferentially in our case, observing a higher proportion of individuals earning '>50K' in some of the subfeatures, i.e taller green bars somewhere in the attribute distribution. A crude measure of this is the following ratio: \n",
15321546
"\n",
1533-
"A crude measure of this is the following ratio: R =(No. '>50K')/(No. '<=50K') > threshold >= 0.5 (50%)\n",
1534-
"or equivalently with largest group percentage: GP = (No. '>50K')/((No. '<=50K') + (No. '<=50K')). \n",
1547+
"R =(No. '>50K')/(No. '<=50K') > threshold >= 0.5 (50%), or equivalently with largest group percentage: \n",
1548+
"GP = (No. '>50K')/((No. '<=50K') + (No. '<=50K')). \n",
15351549
"\n",
1536-
"In addition, these numbers should be representative of the total number of individuals earning '>50K'\n",
1537-
"GT = (No. '>50K')/(Total No. '50K'). Here (Total No. '50K') = 11,208 \n",
1538-
"So we are also looking for MAXIMAL values of GT when possible\n",
1550+
"In addition, the proportion of individuals belonging to a given class within a group should be representative of the total number of individuals earning '>50K'.\n",
15391551
"\n",
15401552
"** 1. Age:**\n",
1541-
"The class distribution appears to be the envelope of a normal distribution, which is good for expectation values in relation to '>50K' class. Near the center we have subfeatures corresponding to age groups 40-50, 50-60 with a significant proportion of '>50K', R >0.5.\n",
1553+
"The class distribution appears to be the envelope of a normal distribution, which is good for expectation values in relation to the '>50K' class. Near the center we have subfeatures corresponding to age groups 40-50, 50-60 with a significant proportion of '>50K', R >0.5.\n",
15421554
"\n",
15431555
"** 2. Capital loss:**\n",
15441556
"This feature contains 3 subfeatures (capital gain amounts of 10-20K, 20-30K and 90-100K) with majority '>50K' class and clearly discriminated from the rest of the subfeatures. Among all features, capital gain fulfills all of our simplified feature importance criteria.\n",
@@ -1550,9 +1562,9 @@
15501562
"Contains the subfeatures \"50-60h\" and \"60-70h\" which contain a significant proportion of '>50K' earners, R >0.5. In addition, the \"40-50h\" groups seems discriminating, i.e. most people working 40 to 50 hours per week would earn less than 50K.\n",
15511563
"\n",
15521564
"** 5. Education Level:**\n",
1553-
"It contains subfeatures \"Masters\", \"Doctorate\" and \"Prof. School\" with majority '>50K' class, and \"Bachelors\", with a high percentage of \">50K\" earners in that group R > 0.5. Althought these groups discriminate between the two income classes, the '>50K' (green) distribution spreads a bit more among the rest of the groups in comparison to capital gain and loss. \n",
1565+
"It contains subfeatures \"Masters\", \"Doctorate\" and \"Prof. School\" with majority '>50K' class, and \"Bachelors\", with a high percentage of \">50K\" earners in that group R > 0.5. Although these groups discriminate between the two income classes, the '>50K' (green) distribution spreads a bit more among the rest of the groups in comparison to capital gain and loss. \n",
15541566
"\n",
1555-
"The rest of the features do not fulfill our \"rule of thumb\" criteria except for \"Occupation\" and \"Civil Status\", which contain several \">50K\" groups with R>0.5, but no '>50K' majority groups. In addition, 'occupation' seems to be correlated or dependent on the education feature (possibly redundant)."
1567+
"The rest of the features do not fulfill our \"rule of thumb\" criteria except for \"Occupation\" and \"Civil Status\", which contain several \">50K\" groups with R>0.5, but no '>50K' majority groups. In addition, 'occupation' seems to be correlated or dependent on the education feature (possibly redundant).\n"
15561568
]
15571569
},
15581570
{
@@ -1615,9 +1627,12 @@
16151627
"cell_type": "markdown",
16161628
"metadata": {},
16171629
"source": [
1618-
"**Answer: ** There is qualitative agreement between these results and those discussed in question 6. In particular, the features \"Capital-gain and Capital-loss confirm our expectations regarding them as being the features that have the largest weight and impact on the model's performance metrics. The same comparison applies broadly to the \"education\" feature. (Notice that sklearn refers to the \"education number\" assigned to the categorical attributes in our \"education\" feature in question 6; it is understood that they are equivalent).\n",
1630+
"**Answer: ** \n",
1631+
"There is qualitative agreement between these results and those discussed in question 6. In particular, the features \"Age\", \"Capital-gain\" and \"Capital-loss\" confirm our expectations regarding them as the features that have the largest weight and impact on the model's performance metrics. The same comparison applies broadly to the \"education\" and \"civil status\" features. (Notice that sklearn refers to the \"education number\" assigned to the categorical attributes of the \"education\" feature in question 6; it is understood that they are equivalent).\n",
1632+
"\n",
1633+
"Notice that sklearn feature selection is highly dependent on the hyperparameters passed to the classifier and/or the resulting optimized hyperparameters. In addition, sklearn feature weighing takes place over the full set of 103 scaled and encoded features, not over the original features being ranked in question 6. \n",
16191634
"\n",
1620-
"Regarding the \"marital status\" it seems that sklearn's implementation picked the subfeature \"married-civ-spouse\" as being the relevant feature while discarding the rest of subfeatures within \"marital status\". This also seems reasonable and confirms our expectations; We need to notice however that sklearn feature selection takes place over the full set of 103 scaled and encoded features, not the original features being ranked in question 6. Feature selection over the final set of features makes more sense as several subfeatures whithin the main attributes discussed in the bar plots in question carried little information about the '>50K' class, and in some cases the class was absent, e.g. such as in the subfeature \"married-AF-spouse\" or \"Married spouse-absent\", etc."
1635+
"In my opinion, feature selection over the final set of features makes more sense as several attributes whithin the main features (see bar plots) carry little information about the '>50K' class."
16211636
]
16221637
},
16231638
{
@@ -1766,9 +1781,9 @@
17661781
"metadata": {},
17671782
"source": [
17681783
"**Answer:** \n",
1769-
"As shown in the bar plots above, feature selection produces a reduction on the performance metrics accuracy and f-score. In particular there is a 1.2% reduction in accuracy and a 3.2% reduction in the f-score.\n",
1784+
"As shown in the bar plots above, feature selection produces a reduction on the performance metrics accuracy and f-score. In particular, there is a 1.2% reduction in accuracy and a 3.2% reduction in the f-score.\n",
17701785
"\n",
1771-
"If training time was a factor I would definitively use the reduced data model as it is an order of magnitude faster. I belive this improvement in training time would be worthwhile for training a much lager data set at the expense of just 3.2% reduction on f-score."
1786+
"If training time was a factor I would definitively use the reduced data model as it is an order of magnitude faster. I belive this improvement in training time would be worthwhile for training a much lager data set at the expense of just 3.2% reduction in the f-score."
17721787
]
17731788
},
17741789
{

0 commit comments

Comments
 (0)