Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Machine Learning for Materials (Lecture 5)

Aron Walsh
February 05, 2024

Machine Learning for Materials (Lecture 5)

Slides linked to https://github.com/aronwalsh/MLforMaterials. Updated for 2025.

Aron Walsh

February 05, 2024
Tweet

More Decks by Aron Walsh

Other Decks in Science

Transcript

  1. Aron Walsh Department of Materials Centre for Processable Electronics Machine

    Learning for Materials 5. Classical Learning Module MATE70026
  2. Module Contents 1. Introduction 2. Machine Learning Basics 3. Materials

    Data 4. Crystal Representations 5. Classical Learning 6. Artificial Neural Networks 7. Building a Model from Scratch 8. Accelerated Discovery 9. Generative Artificial Intelligence 10. Recent Advances
  3. Distance in High Dimensions Minkowski distance is a convenient expression:

    Image from C. Fu and J. Yang, Algorithms 14, 54 (2021)
  4. Distance in High Dimensions • Euclidean – straight line between

    points. Use when data is dense & continuous; features have similar scales • Manhattan – distance following gridlines. Use when data has different scales or grid-like structure • Chebyshev – maximum separation in one dimension. Use to emphasise the largest difference; highlight outliers in feature space Distinction between distance measures
  5. k-Nearest Neighbours (k-NN) Supervised ML model that labels a datapoint

    based on the properties of its neighbours ? What is the most likely colour of the unknown point? “Discriminatory Analysis” E. Fix and J. Hodges (1951) Euclidean distance in n-dimensions is a common metric to determine k-NN (𝑝1 − 𝑞1 )2+ ⋯ + (𝑝𝑛 − 𝑞𝑛 )2
  6. k-Nearest Neighbours (k-NN) k refers to the number of nearest

    neighbours to include in the majority vote Here k = 5. The limit of k = 1 uses the closest neighbour only “Discriminatory Analysis” E. Fix and J. Hodges (1951) ? 𝒚 = 𝑚𝑜𝑑𝑒(𝑘) Predicted label Nearest neighbours Most common value
  7. k-Nearest Neighbours (k-NN) Components required to build a model 1.

    Feature space: how the object/data is defined in multi-dimensional space, e.g. materials properties such as density or hardness 2. Distance metric: method used to measure similarity between data points in feature space, such as Euclidean or Manhattan distance 3. Training data: a set of labelled examples with known features and corresponding class labels
  8. k-Nearest Neighbours (k-NN) k-NN can be used for classification (majority

    vote) or regression (neighbour weighted average) problems k is a hyperparameter (too small = overfit; large = underfit) Image from https://kevinzakka.github.io/2016/07/13/k-nearest-neighbor
  9. k-Nearest Neighbours (k-NN) k-NN can be used for classification (majority

    vote) or regression (neighbour weighted average) problems k is a hyperparameter (too small = overfit; large = underfit) Image from https://kevinzakka.github.io/2016/07/13/k-nearest-neighbor
  10. Model Assessment Classification metrics: true positives (TP), true negatives (TN),

    false negatives (FN), false positives (FP) Metric Formula Interpretation Accuracy (TP+TN)/(TP+TN+FP+FN) Overall model performance Precision TP/(TP+FP) Proportion of true positive out of all positive predictions Recall/ Sensitivity TP/(TP+FN) Proportion of actual positives correctly identified Specificity TN/(TN+FP) Proportion of actual negatives correctly identified F1 score 2TP/(2TP+FP+FN) Harmonic mean of precision and recall (for imbalanced classes)
  11. k-Nearest Neighbours (k-NN) Where a k-NN model may struggle: 1.

    Imbalanced data – if there are multiple classes that differ in size, the smallest class may be overshadowed. Addressed by appropriate weighting 2. Too many dimensions – identifying nearest neighbours and calculating distances can be costly. It may be optimal to apply dimension reduction techniques* first *Principal Component Analysis (PCA) is popular for this purpose (see Exercises)
  12. k-NN Application: Microscopy Classification of mixed mineral samples from microscopy

    (SEM-EDS) datasets C. Li et al, J. Pet. Sci. Eng. 200, 108178 (2020) F1 ∊ [0,1]
  13. k-NN Application: Vibrational Spectra Dating of historical books based on

    near-infrared spectral signatures F. Coppola et al, J. Am. Chem. Soc. 145, 12305 (2023) Important features from 3000 NIR spectra k-NN Random Forest Partial Least Squares Three Models:
  14. k-Means Clustering Unsupervised model that groups data into clusters, where

    k is the number of clusters identified Datapoints within a cluster should be similar “Sur la division des corps matériels en parties” H. Steinhaus (1957) Place n observations into k sets S = {S1 …Sk }
  15. k-Means Clustering Main components of a k-means model 1. Initialisation:

    Choose the number of clusters k to identify. Centroids can be distributed randomly 2. Distance metric: Similar to k-NN, a distance measure is required to define the similarity or dissimilarity, e.g. Euclidean or Manhattan 3. Assignment: Each point is assigned to the nearest centroid. The mean of all points in each cluster is calculated. This process iterates until convergence
  16. k-Means Clustering Unsupervised model groups data into clusters, where k

    is the number of clusters identified An iterative algorithm is used to minimise cluster variance Animation from https://freakonometrics.hypotheses.org/19156 Place n observations into k sets S = {S1 …Sk } Minimise within cluster sum of squares (WSS) J = ∑|xi -μk |2 centroid of cluster k
  17. k-Means Clustering Unsupervised model groups data into clusters, where k

    is the number of clusters identified Note the linear (piecewise straight) cluster boundaries Image from https://freakonometrics.hypotheses.org/19156 Place n observations into k sets S = {S1 …Sk } Minimise within cluster sum of squares (WSS) J = ∑|xi -μk |2 centroid of cluster k
  18. k-Means Clustering k is a hyperparameter. How many clusters to

    choose? As k increases, the similarity within a cluster increases, but in the limit of k = n, each cluster is only one data point A. Makles, Stata Journal 12, 347 (2012) A scree plot shows how within-cluster scatter decreases with k The kink at k = 4 suggests the optimal number
  19. k-Means Clustering The strength of k-means is simplicity, but it

    has limitations: 1. No dual membership – even if a data point falls at a boundary, it is assigned to one cluster only 2. Clusters are discrete – no overlap or nesting is allowed between clusters Extended techniques such as spectral clustering compute the probability of membership in each cluster
  20. k-Means Application: Microscopy Clustering in STEM images of multicomponent (Mo–V–Te–Ta)

    metal oxides A. Belianinov et al, Nature Commun. 6, 7801 (2015) Original data k-means (k=4, Euclidean distance) k-means (k=4, Angle metric) Two representations of the local atomic environment are used for grouping into clusters
  21. Decision Trees Supervised tree-like model splits data multiple times according

    to feature values (decision rules) Split according to feature values Hyperparameter Can be used for classification or regression problems J. N. Morgan and J. A. Sonquist, J. Am. Stat. Assoc. 58, 302 (1963), etc. Root node Decision Node Leaf node Tree depth
  22. Decision Trees An interpretable model. Each prediction can be broken

    down into a sequence of decisions CART is a common training algorithm (e.g. in scikit-learn) Image from https://christophm.github.io/interpretable-ml-book
  23. Decision Trees An interpretable model. Each prediction can be broken

    down into a sequence of decisions Tree to assign class N Pseudo-code 6 decisions are made leading to 4 terminal nodes
  24. Decision Trees Main steps to build a decision tree model

    1. Feature selection: Identify the relevant features from the data that contribute to decision-making 2. Splitting criteria: Determine the best feature and test combination at each node using metrics such as information gain 3. Tree building: Recursively apply splitting criteria to grow child nodes, stopping when a predefined condition is met (e.g. maximum depth)
  25. Decision Trees A simple model that is applicable to many

    problems, but with limitations 1. Instability – a slight change in training data can trigger changes in the split and a different tree. Vulnerable to overfitting 2. Inaccuracy – the “greedy” method of using the best binary question first may not lead to the best overall model There are many extensions of simple decision trees…
  26. Ensemble Models Combine predictions from multiple models through majority voting

    or averaging An ensemble formed by majority voting yields higher accuracy than the separate models Model 1 60% Accurate Model 2 40% Accurate Model 3 60% Accurate Ensemble 80% Accurate Increased predictive power comes at the cost of reduced interpretability (a step towards “black boxes”)
  27. From 木 to 林 to 森 Random Forests Ensemble of

    independent decision trees Figure from D. W. Davies et al, Chem. Mater. 31, 7221 (2019) Gradient Boosted Regression Ensemble of coupled decision trees 𝐲 = ෍ 𝑖=1 𝑛 γ 𝑖 tree 𝑖 (𝐱) Decision trees can be combined for more powerful classification & regression models Model Error Model Complexity
  28. Random Forests Model built from an ensemble of decision trees.

    Hyperparameters: no. trees, max depth, samples… Decision Forests: T. K. Ho, IEEE Trans. Pattern Anal. Mach. Intell. 20, 832 (1995) Correct predictions can be reinforced, while (uncorrelated) errors are canceled out Bagging Method Each tree is generated from a random subset of training data and a random subset of features (bootstrap aggregation)
  29. Gradient Boosted Regression (GBR) Algorithm that combines “weak learners” (decision

    trees) to build the best model XGBoost: T. Chen and C. Guestrin, arXiv 1603.0275 (2016) “When in doubt, use XGBoost” Kaggle competition winner Owen Zhang GBR Approach 1. Use a weak learner (tree1 ) to make predictions 2. Iteratively add trees to optimise the model (following the error gradient); scikit default of n = 100 𝐲 = γ1 tree1 𝐱 + γ2 tree2 𝐱 + ⋯ γn tree𝑛 (𝐱)
  30. GBR Application: Band Gaps Predictions of metal oxide band gaps

    from a dataset of 800 materials (GLLB/DFT; Castelli 2015) Solid-state energy scale (SSE) D. W. Davies et al, Chem. Mater. 31, 7221 (2019) Gradient boosted regression (GBR) Models use compositional information only (no structure)
  31. GBR Application: Band Gaps Predictions of metal oxide band gaps

    from a dataset of 800 materials (GLLB/DFT; Castelli 2015) Model hyperparameters D. W. Davies et al, Chem. Mater. 31, 7221 (2019) 20 most important features (from 149 generated using Matminer)
  32. GBR Application: Steel Multivariable optimisation of steel strength and plasticity

    using 63,000 samples K. Song, et al, Comp. Mater. Sci. 174, 109472 (2020)
  33. GBR Application: Steel Multivariable optimisation of steel strength and plasticity

    using 63,000 samples K. Song, et al, Comp. Mater. Sci. 174, 109472 (2020)
  34. Class Outcomes 1. Describe the k-nearest neighbour model 2. Describe

    the k-means clustering model 3. Explain how a decision tree works and their combination in ensemble methods 4. Assess which types of model could be suitable for a particular problem Activity: Metal or insulator?