<jupyter_start><jupyter_text>**Exercise set 9**==============>The goal of this exercise is to exemplify how decision trees>are created, and how we can perform PLSR regression and decision tree>classification for relatively complex data sets. **Exercise 9.1**Table 1 list certain conditions in which our friend Hermannis playing tennis. Use this data to create a decision tree (by hand) for whether ornot Hermann is playing tennis. Construct the tree by using the information entropyand information gain.|**Outlook**  | **Wind** | **Humidity** | **Playing tennis**  ||:---|:---|:---|:---||overcast | strong | normal | yes ||sunny    | strong | normal | yes ||rain     | weak   | high   | yes ||sunny    | strong | high   | no  ||sunny    | weak   | high   | no  ||sunny    | weak   | normal | yes ||rain     | strong | high   | no  ||**Table 1:** *Conditions for which Hermann is playing tennis.*|<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.1:** *Double click here* **Exercise 9.2**[<NAME> Stephenson](https://doi.org/10.1021/ac00046a015) have measured near-infrared spectrafor 140 mixtures of the solvents methylene chloride, 2-butanol, methanol,dichloropropane, and acetone. We will in this exercise see if we canpredict the compositions of the mixtures from the spectra.Each of the $140$ spectra have been sampled at $700$ wavelengthsbetween $1100$ and $2500$ nm. The raw data containing the spectraand the corresponding concentrations can be found in the file[`Data/windig.csv`](Data/windig.csv).**(a)**  Create a partial least-squares regression (PLSR) model for predictingthe concentrations. Use $1$ PLS component for your first model andassess it using $R^2$, RMSEC, RMSECV and RMSEP. The raw data canbe loaded as shown below.```python"""Load the Windig data set."""import pandas as pddata = pd.read_csv('Data/windig.csv')X = data.filter(like='data', axis=1).values   NIR spectraY = data.filter(like='concentrations', axis=1).values   Concentrations```<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.2(a):** *Double click here* **(b)** Improve your PLSR model by including morePLS components. Try components in therange from $2$ up to $15$ and compare the different models. How manyPLS components are you satisfied with? In the following, we will referto the model you are most satisfied with as "model A".<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.2(b):** *Double click here* **(c)**  Plot the regression coefficients for model A (see point **(b)**).<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.2(c):** *Double click here* **(d)**  If you are given a new spectrum of a mixture of methylene chloride,2-butanol, methanol, dichloropropane, and acetone, how well wouldyour model A predict the concentrations of the different solventsin the mixture?<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.2(d):** *Double click here* **(e)**  Create a least-squared model for predicting the concentrations.Assess it using $R^2$, RMSEC, RMSECV and RMSEP. Does this modelperform as you expect?<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.2(e):** *Double click here* **Exercise 9.3**[Schummer *et al.*](https://doi.org/10.1016/S0378-1119(99)00342-X) studied ovarian cancer by measuring gene expressionvalues for $1536$ genes in both normal and tumor tissues. One of their goals wasto find genes that were overexpressed in tumor samples compared with normal samples.This knowledge may be used for tumor diagnosis. The raw data can befound in the file [`Data/ovo.csv`](Data/ovo.csv).**(a)**  Perform a principal component analysis (PCA) on the gene expression data,and obtain the explained variance when using $1$, $2$, $5$ and $10$components.Center the data before performing the PCA. This can bedone as follows with the `scale` methodfrom `sklearn.preprocessing`: `X = scale(X, with_std=False)`.The raw data canbe loaded as shown below.```python"""Load the Windig data set."""import pandas as pddata = pd.read_csv('Data/ovo.csv')classes = data['objlabels']   Classification of data points.X = data.filter(like='X.', axis=1)   Gene expressions.```<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.3(a):** *Double click here* **(b)**  Inspect the data by plotting the scores and loadings for principal componentnumber $1$ and principal component number $2$:* (i)  Can you observe any clusteringof the samples?* (ii)  Are there any outliers among the samples?* (iii)  Can you identify somegenes which are overexpressed in tumors? * (iv)  Can you identify somegenes which are underexpressed in tumors?<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.3(b):** *Double click here* **(c)**  Based on your answer in **(b)**, canyou identify some pairs of genes that seem to distinguish betweennormal and tumor tissues? Support your findings by plotting the raw data.<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.3(c):** *Double click here* **(d)**  Create a classifier for this data set using a decision tree. Limit the depth of the decisiontree to $2$. Assess the classifier, and compare it with your findings in **(c)** .<jupyter_code># Your code here<jupyter_output><empty_output><jupyter_text>**Your answer to question 9.3(d):** *Double click here* **(e)**  Create a random forest classifier for the data set. Set the maximum depth to $2$, anduse $500$ trees in your forest (i.e. set `n_estimators=500`). Assess theclassifier and plot thevariable importance for the $20$ most important variables. Compare this with yourprevious findings.<jupyter_code># Your code here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11400869274490137, 'fraction_numerical': 0.018890003343363423, 'mean_word_length': 5.567508232711306, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '543114', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1698, 'n_words': 713, 'path': 'exercises_2020/09_Exercise_Set_9.ipynb', 'repo_name': 'sroet/chemometrics', 'size': '5986'}