susi
SUSI: Python package for unsupervised and supervised self-organizing maps (SOM)
view repo
In many research fields, the sizes of the existing datasets vary widely. Hence, there is a need for machine learning techniques which are well-suited for these different datasets. One possible technique is the self-organizing map (SOM), a type of artificial neural network which is, so far, weakly represented in the field of machine learning. The SOM's unique characteristic is the neighborhood relationship of the output neurons. This relationship improves the ability of generalization on small datasets. SOMs are mostly applied in unsupervised learning and few studies focus on using SOMs as supervised learning approach. Furthermore, no appropriate SOM package is available with respect to machine learning standards and in the widely used programming language Python. In this paper, we introduce the freely available SUpervised Self-organIzing maps (SUSI) Python package which performs supervised regression and classification. The implementation of SUSI is described with respect to the underlying mathematics. Then, we present first evaluations of the SOM for regression and classification datasets from two different domains of geospatial image analysis. Despite the early stage of its development, the SUSI framework performs well and is characterized by only small performance differences between the training and the test datasets. A comparison of the SUSI framework with existing Python and R packages demonstrates the importance of the SUSI framework. In future work, the SUSI framework will be extended, optimized and upgraded e.g. with tools to better understand and visualize the input data as well as the handling of missing and incomplete data.
READ FULL TEXT VIEW PDF
This paper presents an application of the Self-Organizing-Map classifica...
read it
The Self-Organizing Map (SOM) with its related extensions is the most po...
read it
CausalML is a Python implementation of algorithms related to causal infe...
read it
Self-Organizing Maps (SOM) are popular unsupervised artificial neural ne...
read it
In this study, a predictive model using Multi-layer Perceptron of Artifi...
read it
In this paper we explore the applicability of the unsupervised machine
l...
read it
Machine learning offers remarkable benefits for improving workplaces and...
read it
SUSI: Python package for unsupervised and supervised self-organizing maps (SOM)
With increasing computing power and increasing amount of data, artificial neural networks (ANN) have become a standard tool for regression and classification tasks. Feed-forward neural networks and convolutional neural networks (CNN) are the most common types of ANN in current research. According to the
no free lunch theorem by Wolpert and Macready (1995), a variety of possible tools is necessary to be able to adapt to new tasks.One underrepresented type of ANNs is the self-organizing map (SOM). The SOM was introduced by Kohonen (1982, 1990, 1995, 2013). It is a shallow ANN architecture consisting of an input layer and a 2-dimensional (2D) grid as output layer. The latter is fully connected to the input layer. Besides, the neurons on the output grid are interconnected to each other through a neighborhood relationship. Changes on the weights of one output neuron also affect the neurons in its neighborhood. This unique characteristic decreases overfitting of the training datasets. Further, the 2D output grid visualizes the results of the SOM comprehensibly. This plain visualization does not exist in the majority of ANNs.
In the following, we give a brief overview of the various SOM applications in different fields of research. Most SOMs are applied in unsupervised learning like clustering, visualization and dimensionality reduction. A good overview of SOMs as unsupervised learners and their applications in the research field of water resources is presented by Kalteh et al. (2008). SOMs are also applied to the scientific field of maritime environment research (Lobo, 2009). One major application of SOMs is clustering data (Vesanto and Alhoniemi, 2000) and cluster-wise regression (Muruzábal et al., 2012).
SOMs can be combined with other machine learning techniques. For example, the output of the unsupervised SOM is used by Hsu et al. (2009)
as input for a support vector regressor to forecast stock prices.
Hsu et al. (2002)present the combination of SOMs with linear regression in hydrology. SOMs can also be used for data fusion, e.g. for plant disease detection
(Moshou et al., 2005). Hagenbuchner and Tsoi (2005)add majority voting to SOMs for the application as supervised classifier. The combination of SOMs and nearest-neighbor classification is shown by
Ji (2000) for the classification of land use. Additional combinations of unsupervised SOMs and supervised algorithms used for classification are presented by Martinez et al. (2001); Zaccarelli et al. (2003); Zhong et al. (2006); Fessant et al. (2001). One example for the application of SOMs to solve non-linear regression tasks is presented by Hecht et al. (2015) in the field of robotics.Two of the most popular programming languages for machine learning applications are Python and R. Programming frameworks like scikit-learn (Pedregosa et al., 2011) in Python have simplified the application of existing machine learning techniques considerably. While in the programming language R the kohonen package (Wehrens and Kruisselbrink, 2018) provides a standardized framework for SOMs, in Python there exists no such standard SOM package, yet.
In this paper, we introduce the Python package SUpervised Self- organIzing maps (SUSI) framework for regression and classification. It is the first Python package that provides unsupervised and supervised SOM algorithms for easy usage. The SUSI framework is available freely on GitHub (Riese, 2019). This ensures the maintainability and the opportunity for future upgrades by the authors as well as any member of the community. The implementation was briefly introduced in Riese and Keller (2018b) with respect to the regression of soil-moisture (Keller et al., 2018b)
and the estimation of water quality parameters
(Keller et al., 2018a). The main contributions of this paper are:the implementation of the SUSI framework including the combination of an unsupervised SOM and a supervised SOM for regression and classification tasks that is able to perform on small as well as on large datasets without significant overfitting,
a first evaluation of the regression and classification capabilities of the SUSI framework in Sections 4.2 and 4.1,
a detailed comparison of the SUSI framework with existing Python and R packages based on a list of requirements in Section 4.3 and
an outlook into the future of the SUSI framework in Section 5.
In the following, we describe the architecture and mathematics of the unsupervised part of the SUSI framework. The grid of a SOM, the map, can be implemented in different topologies. In this paper, we use the simplest topology: the 2D rectangular grid consisting of nodes. This grid is fully connected to the input layer as each node is connected to all input features via weights. The variable naming conventions of the SUSI framework are given in Table 1. The training process of the unsupervised SOM is illustrated in Figure 1 and consists of the following steps:
Initialize the SOM.
Get random input datapoint.
Find best matching unit (BMU) (cf. Section 2.1).
Calculate learning rate (cf. Section 2.2) and neighborhood function (cf. Section 2.3).
Calculate neighborhood distance weight matrix (cf. Section 2.4).
Modify SOM weight matrix (cf. Section 2.5).
Repeat from step 2 until the maximum number of iterations is reached.
Variable | Description |
---|---|
Number of features of a datapoint | |
Number of datapoints | |
Number of rows on the SOM grid | |
Number of columns on the SOM grid | |
Number of current iteration | |
Number of maximum iterations, | |
Datapoint at iteration with | |
Label of datapoint | |
Best matching unit (BMU) of datapoint | |
with | |
Function of the learning rate | |
Start value of the learning rate | |
Neighborhood function | |
Start value of the neighborhood function | |
End value of the neighborhood function | |
Neighborhood distance weight between | |
BMU and SOM node | |
Weight of node at iteration with |
The initialization approach of a SOM mainly affects the speed of its training phase. The SOM weights of the SUSI framework are initialized randomly at this stage of development. Attik et al. (2005) and Akinduko et al. (2016)
, for example, propose more sophisticated initialization approaches like applying a principal component analysis. In the following subsections, the training of an unsupervised SOM is described in detail.
During the search for the best matching unit (BMU), the input datapoint is compared to all weights on the SOM grid. The SOM node that is the closest one to the input node according to the chosen distance metric is the BMU. Several distance metrics can be applied. The most common distance metric is the Euclidean distance defined as
(1) |
with a dimension of the vectors . Another possible choice is the Manhattan distance which is defined as the sum of the absolute distances per element:
(2) |
The Tanimoto distance as third option is defined as the distance or dissimilarity between two boolean (binary: ) vectors :
(3) |
with as the number of occurrences of and for all elements as defined in Jones et al. (2001). The Mahalanobis distance between two 1-dimensional vectors is defined as
(4) |
with the covariance matrix of the two vectors. The default distance metric of the SUSI framework is the Euclidean distance defined in Equation 1.
For a faster convergence and to prevent oscillations, decreasing learning rates are often implemented in ANNs. The learning rate of the SOM training is a function that decreases from a value with increasing number of iterations. In general, there is an infinite number of possible functions for the learning rate. In the following, we present several functions implemented into the SUSI framework. In Natita et al. (2016), different learning rates for SOMs are introduced:
(5) | ||||
(6) | ||||
(7) |
In de Sá et al. (2012), the following learning rate was applied:
(8) |
The implementation of Barreto and Araújo (2004) includes not only a start value for the learning rate but also an end value :
(9) |
In Figure 2, some examples for the behaviour of the functions are plotted. The default learning rate function of the SUSI framework is set according to Equation 9.
Similar to the learning rate, the neighborhood function is monotonically decreasing. We include the following three widely-used functions in the SUSI framework. Equivalent to Equation 6, the neighborhood function in Matsushita and Nishio (2010) is defined as
(10) |
with as initial value of the neighborhood function. In de Sá et al. (2012), the neighborhood function is implemented as
(11) |
equivalent to Equation 8. In Barreto and Araújo (2004), the neighborhood function is defined similarly to Equation 9 as
(12) |
The default neighborhood function of the SUSI framework is set according to Equation 10.
The neighborhood distance weight is a function of the number of iterations and the distance between the BMU and every other node on the SOM grid. The distance between the BMU and node is defined as the Euclidean distance (cf. Equation 1) on the map grid. In this paper, we give two examples for neighborhood distance weights. Matsushita and Nishio (2010) use a Pseudo-Gaussian neighborhood distance weight. The weight between the BMU and the node on the SOM grid is defined as
(13) |
with the neighborhood function from Equation 10 and the Euclidean distance on the SOM grid. This definition of a neighborhood distance weight is the default setting of the SUSI framework. Another possible neighborhood distance weight is the Mexican Hat (Kohonen, 1995) defined as
(14) |
again with neighborhood function of Equation 10 and Euclidean distance on the SOM grid. The implications of the chosen neighborhood distance weight definitions on the SOM are investigated in e.g. Ritter et al. (1992) and Horowitz and Alvarez (1995).
The two most commonly used approaches to adapt the SOM weights are the online and the batch mode. The weights of the SOM are adapted based on the learning rate and the neighborhood distance weight. The online mode is described in detail in Kohonen (2013). After each iteration, all weights of the SOM are adapted to the current datapoint as follows:
(15) |
with neighborhood function , learning rate , weight vector of node at iteration . In the batch mode (Kohonen and Somervuo, 2002; Matsushita and Nishio, 2010), the whole dataset consisting of datapoints is used in every iteration. Each weight is adapted as follows:
(16) |
with the neighborhood function from Equation 13 and the weight vector of node at iteration . In this first stage of development, the SUSI package provides only the online algorithm.
After reaching the maximum number of iterations , the unsupervised SOM is fully trained. New datapoints can be allocated to their respective BMU which will be used in Section 3. Note that not every node on the SOM grid has to be linked to a datapoint from the training dataset, since there can be more SOM nodes than datapoints.
To apply the SUSI framework for solving supervised regression or classification tasks, we attach a second SOM to the unsupervised SOM. The flowchart of the second, supervised SOM is illustrated in Figure 3. The two SOMs differ with respect to the dimension of the weights and their estimation algorithm. The weights of the unsupervised SOM have the same dimension as the input data. Thus, adapting these weights often changes the BMU for each input datapoint. In contrast, the weights of the supervised SOM have the same dimension as the target variable of the respective task. One has to distinguish between two cases: regression and classification. In the regression case, the weights are one-dimensional and contain a continuous number. In the classification case, the weights contain a class. By combining the unsupervised and the supervised SOM, the former is used to select the BMU for each datapoint while the latter links the selected BMU to a specific estimation. In the following, we describe the different implementations for regression and classification tasks.
The implementation of the regression SOM is described in Riese and Keller (2018b) using the example of the soil-moisture regression based on hyperspectral data. The training of the regression SOM proceeds analogous to the unsupervised SOM: first, the SOM is initialized randomly. Again, it iterates randomly through the dataset (cf. Step 1). In each iteration, the BMU is found for the current datapoint based on the trained unsupervised SOM (cf. Steps 2, 3). The BMUs do not change for the datapoints during the training since the unsupervised SOM is fully trained. Then, the neighborhood function, the learning rate and the neighborhood distance weight matrix are calculated similarly to the algorithm of the unsupervised SOM (cf. Steps 4, 5). Finally, the weights are adapted to the label of the input datapoint (cf. Step 6).
In the case of the regression SOM, the label is a continuous value and the weights of the regression SOM can be modified similarly to the process described in Section 2.5. After the training (and in the case of a 1-dimensional target variable), the regression SOM consists of a map with a continuous distribution of the regression target variable. To apply the trained regression SOM to a new dataset, the BMUs needs to be found by the unsupervised SOM. For each datapoint in the new dataset, the estimated output value of the SUSI framework is the weight of the found BMU on the regression SOM. The regression SOM is illustrated in Figure 3.
In the case of a classification task, the labels are discrete. In contrast to the commonly used majority voting approach (cf. Hagenbuchner and Tsoi, 2005), we have implemented a training process similar to the adaptation approach of the unsupervised SOM (cf. Section 2.5):
Initialize the classification SOM.
Get random input datapoint with label.
Find BMU based on trained unsupervised SOM.
Calculate learning rate and neighborhood function.
Calculate neighborhood distance weight.
Calculate class-change probability matrix.
Modify classification SOM weight matrix.
Repeat from step 2 until the maximum number of iterations is reached.
The classification SOM is illustrated in Figure 3. The initialization in step 1 contains a simple majority vote: each node is assigned to the class representing the majority of datapoints allocated to the respective node. The steps 2 to 5 are implemented similarly to the regression SOM in Section 3.1. To modify the discrete weights of the classification SOM, we introduce the class-change probability in step 6. In the regression SOM, the SOM nodes around the BMU are adapted to the current datapoint with a certain probability depending on the learning rate and the neighborhood distance weight. Since the labels are discrete in a classification task, this process needs to be adapted. In the following, we explain our proposed adaptation.
For datasets with imbalanced class distributions, meaning datasets with significantly different number of datapoints per class, we provide the possibility to re-weight the dataset. The optional class weight is defined as
(17) |
with the number of datapoints , the number of datapoints of class and the number of classes . Similar to Equation 15, we define a term that affects the modifying of the SOM weights. Since the modifications need to be discrete, we work with probabilities. The probability for a class change of node with BMU of the datapoint with label is defined as
(18) |
with the class weight (cf. Equation 17), the learning rate (cf. Section 2.2) and the neighborhood distance weight (cf. Section 2.4). To decide if a node changes its assigned class, a binary decision rule is created based on this probability. A simple threshold of e.g. would lead to a static SOM after a certain number of iterations. Therefore, we include randomization into the decision process. For every node in every iteration, a random number
is generated which is uniformly distributed between
and . The modification of the weights is then implemented based on the class change probability defined in Equation 18 as follows:(19) |
with the label linked the datapoint of the current iteration . After the maximum number of iterations is reached, the classification SOM is fully trained. Then, every node on the SOM grid is assigned to one class of the dataset. To apply the classification SOM on new data, the BMU needs to be found for each datapoint with the unsupervised SOM. This process is similar to the one in the trained regression SOM. The estimation of the classification SOM for this datapoint is equivalent to the weight of the neuron in the classification SOM at the position of the selected BMU.
For a first evaluation of the regression and classification capabilities of the introduced SUSI framework, we rely on two datasets from different domains of geospatial image analysis. The regression is evaluated in Section 4.1 with a hyperspectral dataset on the target variable soil moisture. The evaluation of the classification SOM in Section 4.2
is performed based on the freely available Salinas valley dataset for land cover classification from hyperspectral data. The results of the two different SOM applications are compared against a random forest (RF) estimator
(Breiman, 2001). Finally, the SUSI package is compared to existing SOM packages in the programming languages Python and R in Section 4.3.The performance of the regression SOM is evaluated based on the soil-moisture dataset measured during a field campaign and published in Riese and Keller (2018a). A similar evaluation is published in Riese and Keller (2018b) with a preceding version of the SOM algorithm and code. The dataset consists of 679 datapoints collected by a Cubert UHD 285 camera. One datapoint consists of 125 bands between to . A soil moisture sensor measured the reference values in a range of to soil moisture. For the validation of the estimation performance and the generalization capabilities of the SOM, the dataset is randomly divided into a training and a test subset in the ratio . The training of the estimator is performed on the training subset and the evaluation is performed on the test subset.
The regression SOM is set up with default parameters with the exception of the grid size and the number of iterations. The grid size of the SOM is . The unsupervised and the supervised SOMs are trained with
iterations each. These hyperparameters can be further optimized depending on the applied dataset. The RF regressor is set up with
estimators and the scikit-learn default hyperparameters (cf. Pedregosa et al., 2011). For the evaluation, we choose the coefficient of determination .The regression SOM achieves on the test subset. This score implies that the regression SOM is able to generalize on this dataset. Interestingly, the result for the training subset is only marginally better with . In comparison, the RF regressor results in and on the dataset. To conclude, the SOM seems to be robust regarding overfitting. In this case, the score could function as out-of-bag estimate for the dataset similar to Breiman (2001). When dealing with small datasets, the SOM provides the advantage of not necessitating on the split of the dataset.
In Figure (a)a, the distribution of the BMUs of the soil-moisture dataset is shown. No clear maximum exists, rather a random and uniform distribution is recognizable. Figure (a)a illustrates further that despite the fact that the dataset is smaller than the number of SOM nodes, the training takes advantage of the whole SOM grid. The spread over the whole SOM grid makes generalization possible. The continuous regression output for each SOM node is presented in Figure (b)b. Although the SOM nodes outnumber the input datapoints, each SOM node is linked to a soil moisture value.
The Salinas valley dataset^{1}^{1}1http://www.ehu.eus/ccwintco/index.php/Hyperspectral_Remote_Sensing_Scenes. is a freely available land cover dataset consisting of pixels collected by the 224-band AVIRIS sensor in California. The spatial resolution of this dataset is . Of the 224 bands in the range of to , the 20 water absorption bands are discarded, namely bands 108-112, 154-167, 224. The dataset consists of datapoints with reference data of 16 classes including vegetation classes and bare soil. Compared to the dataset used in the evaluation of the regression SOM in Section 4.1, this dataset is considered as large dataset. We apply a 5-fold cross-validation on this dataset for the evaluation of the classification SOM. The evaluation results are the average results over all five cross-validation combinations.
Similar to Section 4.1, the default SOM hyperparameters are used except for the grid size and the number of iterations. The grid size of the SOM is . The unsupervised SOM is trained with iterations and the supervised SOM is trained with iterations. The hyperparameters of the classification SOM can be further optimized. The RF classifier is set up with estimators and the scikit-learn default hyperparameters (cf. Pedregosa et al., 2011). For the evaluation, we choose the metrics overall accuracy (OA), average accuracy (AA) and Cohen’s kappa coefficient . The OA is defined as the ratio between the number of correctly classified datapoints and the size of the dataset. The AA is the sum of the recall of each class divided by the number of classes with the recall of a class being the number of correctly classified instances (datapoints) of that class, divided by the total number of instances of that class. Cohen’s kappa coefficient is defined as
(20) |
with the hypothetical probability of chance agreement .
The classification results of the complete dataset are shown in Figure 5. The SOM achieves a test OA of , AA and . The training OA is , the training AA is and the score on the training subsets is . In contrast, the RF classifier achieves a test OA of , AA and while the RF training metrics are all at . The RF classifier performs significantly better than the classification SOM which has not been fully optimized. Analog to the regression (cf. Section 4.1), the results for the classification SOM with respect to the training and test subsets are similar while the RF classifier shows overfitting on the training subset.
In Figure (a)a, the distribution of the BMUs of the dataset is illustrated. Although the dataset is much larger compared to Figure (a)a, not all nodes are linked to a datapoint while some nodes are linked to a significant number of datapoints. The distribution of the classification output of the SOM is shown in Figure (b)b. Nodes assigned to the same classes are closer together on the SOM grid due to the inclusion of the neighborhood during the training process.
In the following section, we compare the SUSI framework with existing Software packages. We compare it with the Python packages SOMPY (Moosavi et al., 2018), SimpSOM (Comitani, 2018), MiniSom (Vettigli, 2019), TensorFlow SOM (Gorman, 2018) and the R kohonen package (Wehrens and Kruisselbrink, 2018). All entitled packages are freely available, regularly maintained (in the last year) and include unsupervised clustering. Table 2 illustrates this comparison. So far, no supervised SOM package for Python is available that matches the defined requirements requirements (cf. Table 2). The fact that the unsupervised SOM packages are all maintained regularly implies a significant interest in Python SOM packages. Overall, the SUSI package is perfectly suited for an easy use and a variety of applications.
SUSI | SOMPY | SimpSOM | MiniSom | TensorFlow SOM | kohonen | |
---|---|---|---|---|---|---|
Simple (scikit-learn) syntax | ✓ | ✓ | ||||
Comprehensive paper or documentation | ✓ | ✓ | ||||
Well documented and structured code | ✓ | ✓ | ✓ | ✓ | ||
Unsupervised clustering | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Supervised regression | ✓ | ✓ | ||||
Supervised classification | ✓ | ✓ | ||||
Simple installation (e.g. Pypi) | ✓ | ✓ | ✓ | ✓ | ||
GPU support | ✓ | |||||
Programming language | Python 3 | Python 2 | Python 3 | Python 3 | Python 3 | R |
SOMs are applied in a variety of research areas. In this paper, we introduce the SUpervised Self-organIzing maps (SUSI) package in Python. It provides unsupervised and supervised SOM algorithms for free and easy usage. The mathematical description of the package is presented in Sections 3 and 2. We demonstrate first regression and classification results in Sections 4.2 and 4.1. Overall, the performance of the SUSI package is satisfactory, taking into account that a further optimization is possible. The regression is performed on a small dataset with datapoints while the classification SOM is applied on a large dataset with datapoints. The application to these two datasets illustrates the ability of the SUSI framework to perform on differently sized datasets. Although, the RF regressor and classifier perform better in the given tasks, the SOM performance metrics of the training and the test subset differ only slightly. This shows the robustness of the SUSI framework. Further, the performance metric based on the training dataset could function as out-of-bag estimate for the dataset. This implies that a dataset does not have to be split which improves training especially on small datasets. Finally, we compare the SUSI framework against different existing SOM frameworks in Python and R with respect to e.g. features, documentation and availability. We conclude that there is a significant interest in a standardized SOM package in Python which is perfectly covered by the SUSI framework.
In the future, the SUSI package will be extended, optimized and upgraded. The handling of missing and incomplete data, as described in Hagenbuchner and Tsoi (2005), is one example for a possible new extension. In addition, the 2D SOM grid visualizes the results of the SOM and therefore ensures to better understand the underlying dataset. This ability to learn from underlying datasets can be extended as described e.g. by Hsu et al. (2002). Furthermore, we will present applications on new datasets as well as share best practices to make the SUSI framework as valuable as possible for its users.
Recurrent self-organizing map for severe weather patterns recognition.
In: Recurrent Neural Networks and Soft Computing, IntechOpen, Rijeka, chapter 8, pp. 151–174.Connectionist Models of Neurons, Learning Processes, and Artificial Intelligence
, Vol. 2084, Springer, Berlin, Heidelberg, pp. 637–644.
Comments
There are no comments yet.