1 Introduction

Resistance spot welding (RSW) is the leading technique for joining metal sheets in many industrial fields, especially in the automotive industry, because of its automatability, easy implementation, and cost-effectiveness [1]. The process involves the simultaneous action of electric and mechanical energies. At the beginning of welding, two or more overlapped sheets are pressed together by two Cu-based electrodes. Then, a high current flows through the sheets for a short time (hundreds of ms). The heat generated by the Joule effect locally melts the sheet faying interface, and a weld nugget, i.e., the joint, forms at the end of solidification [2]. Nowadays, just one car can contain between 4000 and 7000 spot welds [3, 4] and a modern production line performs about 7 million welds daily [5].

Resistance spot welds can be classified, based on their quality, as normal, cold, and burn-through welds [1]. A normal weld is a compliant joint. A cold weld has a weld nugget smaller than the minimum size required, while a burn-throw is a weld affected by a severe ejection of molten materials, known as expulsion [6]. Both cold and burn-through welds have limited strength under static and/or dynamic loading conditions. Generally, the main causes leading to non-compliant spot welds can be attributed to [1, 7,8,9,10]:

  • electrodes (electrode wear, electrode misalignment, inappropriate electrode shape, dimensions, and material);

  • process parameters (improper welding time, current, and electrode force);

  • materials (incompatible metals in dissimilar joining, resistance shunting, sheet gap, edge proximity, and non-orthogonal electrode-sheet contact).

The quality of resistance spot welds can be checked through destructive and non-destructive tests [11]. Destructive tests are time- and cost-consuming [12], and do not ensure the identification of every non-compliant joint since they are performed a sample basis. Non-destructive tests could be potentially performed on every weld, but they do not always can accurately assess weld quality [1, 13]. Industry 4.0 and its key technologies, such as the Internet of Things (IoT) and Artificial Intelligence (AI), offer new ways to facilitate quality checks of RSW welds through the online prediction of quality indicators [14]. Recently, artificial neural networks (ANNs) have been used to predict the nugget size [15] and the failure load of spot welds [16] by analyzing the electric power and the dynamic resistance signals acquired during the joining process. Wan et al. [17] predicted the same quality indicators (i.e., nugget size and failure load) from the dynamic resistance signal. A random forest algorithm was applied by Xing et al. to dynamic resistance signals to classify high-quality welds from non-acceptable ones [18]. The electrode displacement signals recorded during the welding process were exploited by Zhang et al. to build a decision tree and classify spot weld quality based on the failure load of the joints [19]. Convolutional neural networks and multilayer perception algorithms have been applied to the signals of the main welding processes, including electric current, dynamic resistance, electrode force, and electrode displacement, to predict the nugget geometry [20]. Convolutional neural networks have also been used on infrared thermal videos to predict the weld nugget size [21]. The failure load of RSW welds has been predicted with an explainable boosting machine algorithm on welding process parameters (welding current, welding time, welding force) [22].

Although the literature has provided some useful tools for predicting the nugget size and/or failure load, literature has yet to consider the effect of electrode wear on the quality assessment of the RSW process. The conditions of the electrodes is the more important factor affecting the quality of spot welds in the industrial field [23]. Indeed, up to 60% of defective spot welds can be caused by worn electrodes [24]. During the welding process, the combined effects of high mechanical pressure, elevated temperature, and atomic diffusion between the electrodes and sheets lead to a deterioration of the electrode state over time [25]. Specifically, the electrode undergoes irreversible deformation, which causes an increase in the contact area with the sheet and, thus, a decrease in the electric current density. In addition, the electrode contact surface wears, leading to an increase in the irregularity of the electric current distribution during the process [26, 27]. As a result, the quality of spot welds reduces with electrode deterioration, making the monitoring of weld quality more challenging. As a mitigation solution, automotive manufacturers typically perform around 20% more welds than required to deal with the uncertainty of electrode wear [24]. Several technical and economic advantages could be achieved if electrode wear were monitored in real-time on assembly production lines: fewer spots could be realized increasing productivity; improper spot welds due to electrode deterioration could be eliminated or significantly reduced; electrodes could be replaced or dressed only when necessary according to the predictive maintenance paradigm [28,29,30]. In this way, the number of redundant spot welds can be minimized and manufacturers can reduce the uncertainty of the process and gain competitiveness [31, 32].

Traditional works [8, 25, 26, 33] have explored the characteristics of electrode wear and their impact on spot weld properties providing valuable insights. Statistical process control techniques have been developed based on the electrode displacement signals for monitoring the welding process during electrode wear [34]. The electrode displacement signal was also used to monitor the electrode wear through a moving range chart [35] or to feed an artificial neural network to predict the electrode contact area, commonly used as a wear indicator [36]. Fan et al. investigated the relationship between the dynamic resistance signal and the electrode tip radius. They found that the average value of the signal during the nugget growth stage has a strong relation with the electrode contact radius [37]. Zhou et al. [24] used the dynamic resistance signal to evaluate electrode wear through similarity techniques among the signals of the welding parameters. The work available at [38] assessed inline electrode wear occurring during the welding process without the need for extra sensors. The tests conducted demonstrate a correlation between the deformed contact area and the change in electrode length. The study reveals that this alteration in electrode length is discernible in real-time process data, making it a suitable criterion for characterizing electrode wear. In the work [39], an adaptive control scheme employing fuzzy Proportional-Integral (PI) control is examined and developed to compensate the effect of electrode wear on the electric current. Within each control cycle, features from the dynamic resistance and welding power serve as inputs for the fuzzy controller. By using current closed-loop feedback control, the fuzzy PI controller output manages the full bridge inverter on and off switching to maintain a steady welding current. Simulation and experimental outcomes demonstrate that this approach offers several advantages compared to traditional PID control methods. The study [40], instead, investigated the effect of electrode wear by means of electrical-thermal–mechanical simulations. The model validity was confirmed by comparing simulated temperature and voltage results with experimental measurements. Findings show that electrode wear leads to an increase in resistance and temperature at the electrode tip rather than a decrease. To address this, it is recommended to lower welding parameter values instead of increasing them. Consistently, maintaining a controlled temperature rise at the electrode tip is crucial for ensuring welding quality in the presence of electrode wear. Heilmann et al. [41] studied the electrode wear in RSW of aluminum sheets. Specifically, they proposed mitigating electrode wear by mechanically disrupting the oxide layer before welding. This study explored the impact of both translational and rotational movements of the electrode on wear, and the findings indicate that oxide layer disruption occurs even at low movements. However, achieving a uniform and extensive destruction is crucial for effectively reducing wear. More recently, Zhao et al. [42] investigated the degradation process of electrodes in baked hardening (BH) 220 steel. They identified several analytical relationships between the weld number and different nugget features, mechanical properties, and electrode characteristics. Noteworthy examples include the relationships between the weld number and the maximum displacement of the weld sample in mechanical tests, peak load, failure energy, and electrode diameter, with an adjusted coefficient of determination exceeding 0.90.

Although many studies have studied electrode wear in RSW, car manufacturers are still coping with the uncertainty associated with the electrode degradation process, forcing them to perform up to 20% of redundant welds. Previous literature on electrode wear mainly addressed qualitative approaches that associate changes in welding signals with electrode wear to detect the condition of worn electrode [24, 34, 35, 37], quantitative approaches that compute electrode wear characteristics to provide more detailed information about the electrode state [36, 38, 42], and studies oriented toward compensating for electrode wear by controlling process parameters [39,40,41]. No work is focused on the prediction of the electrode wear effect on the quality of RSW, and manufacturers currently lack real-time support for assessing the compliance of their welds.

In contrast to the previous studies, the aim and novelty of this work are to develop a machine learning tool capable of predicting the quality class of resistance spot welds considering the effect of electrode wear in real-time. To the best of the authors' knowledge, this is the first time a predictive tool for assessing electrode wear effect on spot weld quality has been developed. This tool allows for an automatic assessment of the weld quality class based on the electrode displacement and force signals acquired during welding. This enables the automatic detection of low-quality welds, providing crucial insights for maintenance operations. By proactively replacing or dressing the electrode before it starts producing low-quality welds, redundant welds can be avoided or drastically reduced. Eliminating these unnecessary additional welds results in time, energy, and resource savings for manufacturers, thereby contributing to a substantial enhancement in the sustainability of the manufacturing process.

2 Methodology

The methodology involves conducting two different experimental campaigns to detect the influence of electrode wear on the quality of RSW welds. Data acquired from the experiments are processed to create the work dataset. Specifically, the shear tension strength values of the spot welds are used to create the class variable, whereas data from sensors are processed through feature extraction and feature selection processes to identify predictors. Different machine learning algorithms are applied to the dataset, and the most performing algorithm is chosen as the final quality classifier of the spot weld. A schematic summary of the methodology is depicted in Fig. 1.

Fig. 1
figure 1

Methodology adopted to develop a machine learning tool to predict the effect of electrode wear on the quality of RSW

Two experimental campaigns were conducted using different electrodes, materials, and process parameters involving, overall, more than 2000 welds. In each campaign, the effect of electrode wear on resistance spot weld quality was detected through periodic shear-tension tests. The resulting failure loads were used to create the weld quality classes. A threshold for the relative failure load was set according to the literature to differentiate compliant and non-compliant welds, determining the weld quality classes. During the experiments, electrode displacement and force signals were recorded with sensors directly embedded in the RSW machine. Several features were extracted from sensors, and only the most informative features were selected as predictors of weld quality classes. Some machine learning classification algorithms were applied to the collected data. The most performing algorithm was selected as the final classifier for weld quality.

2.1 Experimental campaigns

A medium-frequency direct current RSW machine (Fig. 2), equipped with a control unit TE700 (Tecna), was used to conduct the experimental welding campaigns. During the welding process, electrode displacement was measured with a magnetostrictive linear position sensor mod. Temposonics R-series (position resolution of 2 μm), while a certified piezoelectric surface strain sensor mod. 9232A (Kistler Italia) measured the electrode force. Both signals were acquired with a sampling rate of 40 kHz using a NI-9862 CAN interface module (National Instruments) and controlled with LabVIEW software.

Fig. 2
figure 2

RSW machine adopted during the experiments

Two experimental campaigns were conducted using different electrode face diameters, material thicknesses, and process parameters to weld two overlapped steel sheet coupons. The material of the welding sheets and electrodes were the same for both experimental campaigns. The welding sheets were made of Zn-galvanized DP590 steel, a material commonly used in the automotive industry [3, 8, 36], while the electrodes were made of Cu-Cr-Zr alloy with a truncated cone shape. In the first campaign, the steel sheet size was 200 mm × 300 mm × 1 mm and the electrodes had a face diameter of 6 mm. In the second campaign, the steel sheet size was 200 mm × 250 mm × 0.8 mm, and the electrodes had a face diameter of 5 mm. The two electrode face diameters were chosen according to the AWS D8.9 standard [43]. The decision to investigate two different material thicknesses and, consequently, two electrode diameters in the experimental campaigns aimed at broadening the applicability and generalizability of the developed tool. The bottom electrode was always fixed, while the top electrode moved to clamp the sheet stack. Both electrodes were cooled with a water flow of 4 l/min. Each experimental campaign started and concluded on the same day within the laboratory environment, with an ambient temperature of approximately 20 °C. The electrodes were inserted into the machine and were not replaced until the end of the campaign, ensuring constant positioning, alignment, and any other boundary conditions throughout the process. The process parameters are shown in Table 1, chosen according to the recommendations of the AWS D8.9 standard [43]. More in details, based on the material and thickness of the sheets, the standard provides values for the electrode diameter, electrode force, and weld time. The electric current value was set as the maximum value before metal expulsion occurred. The RSW machine was set in ‘current constant’ mode, with the controller TE700 maintaining the set values of the electric current throughout the experiments.

Table 1 Process parameters adopted in the two experimental campaigns

In each experimental campaign, several spot welds were sequentially performed with constant process parameters to induce electrode degradation. The spot welds were realized on overlapped sheet coupons with edge distance and weld spacing recommended by the AWS D8.9 standard [43], as schematically shown in Fig. 3.

Fig. 3
figure 3

Edge distance and weld spacing adopted in the experiments according to the AWS D8.9 standard: a 1st and b 2nd campaign

An example of overlapped sheets coupon before and after welding is shown in Fig. 4.

Fig. 4
figure 4

Example of overlapped sheets coupon before and after welding during the experiments

The extent of electrode degradation over time was indirectly evaluated through the periodic assessment of the weld failure load obtained from shear-tension tests. The failure load was the peak load reached during the test. The mechanical tests were conducted based on JIS Z 3136 standard [44]. The shear tension tests were carried out with a crosshead speed of 10 mm/min using a standard testing machine. The specimen size for the shear tension test and an example of coupon after test are displayed in Figs. 5 and 6, respectively.

Fig. 5
figure 5

Specimen geometry for the shear tension tests

Fig. 6
figure 6

Example of coupons after shear tension tests

The experimental welding procedure for the first experimental campaign is described in the following:

  1. 1.

    unused electrodes were mounted in the RSW machine;

  2. 2.

    the electrodes were clamped against the sheet stack to set the zero point for the electrode displacement;

  3. 3.

    three shear-tension samples were welded and three corresponding shear tension tests were immediately performed to determine the weld failure load when the electrodes are unused;

  4. 4.

    135 spot welds were performed in succession on the overlapped coupons;

  5. 5.

    three shear-tension samples were welded and tested to determine the weld failure load at the current level of electrode degradation;

  6. 6.

    points 4 and 5 are cyclically repeated up to approximately 1200 spot welds.

The same procedure was repeated in the second experimental campaign with an inspection frequency of 90 spot welds (point 4), instead of 135. For both experimental campaigns, the inspection frequencies comply with the AWS D8.9 standard [43], which recommends detecting the weld strength for electrode wear assessment at least every 200 welds.

An example of electrode before and after the experimental campaign is displayed in Fig. 7.

Fig. 7
figure 7

Example of electrode before and after the experiments

2.2 Definition of the class label

The failure load has been used to build the class label because it determines whether the spot weld is compliant or not. Since the joint size is different in the two experiments, the failure loads are also different. Therefore, the failure load values have been normalized with respect to the initial value to establish a general relationship:

$${F}_{rel,i}= \frac{Fmax,i}{Fmax,initial}, \quad \forall i\in n$$
(1)

\({F}_{rel,i}\) is the relative failure load, \(Fmax,initial\) is the failure load when the electrode is unused, \(Fmax,i\) is the failure load of the i-th inspection, and \(n\) is the number of the inspected spot welds.

According to the literature [8, 33, 36], the electrode can be considered worn and to be replaced or dressed when the mechanical strength of spot welds decreases by 20% compared to that obtained with unused electrodes. This means that each spot weld can be assigned to one of the following two classes:

  • positive class (1) for the non-compliant spot weld (worn electrodes),

  • non-positive class (0) for the compliant spot weld.

Because of this, the class label \(y\) can be defined as follows:

$$\left\{\begin{array}{l}y=0,\quad if\ {F}_{rel,i} >0.8 \\ y=1, \quad otherwise.\end{array}\right.$$
(2)

2.3 Feature extraction from sensors

Data acquired from sensors during the experimental campaigns, namely the electrode displacement signal and the electrode force signal, have been processed to extract informative features for the class variable. Following the approach of Panza et al. [36], the time interval for the analysis of the electrode displacement signal includes the current flow and an electrode hold time of 200 ms (sufficient time for the curve to flatten out). Therefore, the time interval is 700 ms and 580 ms for the first and second experimental campaigns. The time interval for the analysis of the force signal only concerns the current flow, that is, 500 ms and 380 ms for the first and second campaigns.

2.3.1 Electrode displacement

The electrode displacement signals corresponding to the weld specimens for the shear tension tests have been analyzed and processed. For example, Fig. 8 displays the electrode displacement curves obtained at the beginning (1st weld), middle (692nd weld), and end (1245th weld) of the first experimental campaign.

Fig. 8
figure 8

Electrode displacement curves obtained at the beginning, middle, and end of the 1st experimental campaign

As the deterioration process advances, the electrode requires a longer stroke to clamp the sheet stack due to the axial contraction of the electrode, resulting from its plastic deformation and wear. Initially, the electrode displacement ranges from approximately − 50 to − 100 μm from the first spot weld to the 1200th, as shown in Fig. 8. The amplitude of the displacement curves decreases with the number of spot welds. The wear of the electrode tip leads to an uneven distribution of contact resistance between the electrode and the sheet. During welding, this causes localized heating on the electrode tip surface, and oxidation may occur over time. The enlargement of the contact area results in a decrease in the electric current density, while wear and oxidation of the contact surface lead to an irregular electric current distribution through the electrodes and the sheets. Consequently, the thermal power developed at the faying interface of the sheets decreases and becomes non-uniform over time [45]. As a result, less metal is melted, and the welded joint volumetrically expands less than it did at the beginning of the endurance test. Figure 8 illustrates how the amplitude of the displacement curves, measured as the distance between the start and the peak value of the electrode displacement, decreases from about 150 to 75 μm. For the same reason, the slope of the electrode displacement curve reduces, particularly in the final cooling (hold) stages [36].

These effects have been considered to extract quantitative features from the displacement curves and relate them to the class variable. Data have been arranged in a vector:

$${D}^{i}= \left[{d}_{1}^{i},\ldots ,{d}_{j}^{i},\ldots ,{d}_{N}^{i}\right] (\mu m)$$
(3)

\({D}^{i}\) is the electrode displacement signal vector corresponding to the i-th spot weld; \({d}_{1}^{i}\) is the first displacement value during the i-th spot weld; N is the total number of electrode displacement values considered for each inspected spot weld.

Accordingly, the following features have been computed:

  • Maximum displacement value \({d}_{max}^{i}\):

    $${d}_{max}^{i}={\text{max}}\left({D}^{i}\right) \left(\mu m\right)$$
    (4)
  • Time in correspondence of the maximum displacement \({d}_{{\text{max}}\_time}^{i}\):

    $${d}_{{\text{max}}\_time}^{i}={\text{index}}({d}_{\mathit{max}}^{i})\cdot 0.01 \left(s\right)$$
    (5)
  • Difference between the maximum displacement value and the last value \({d}_{{\text{max}}\_last}^{i}\):

    $${d}_{{\text{max}}\_last}^{i}={d}_{max}^{i}- {d}_{N}^{i} \left(\mu m\right)$$
    (6)
  • Difference between the maximum displacement value and the first value \({d}_{{\text{max}}\_first}^{i}\):

    $${d}_{{\text{max}}\_first}^{i}={d}_{max}^{i}- {d}_{1}^{i} \left(\mu m\right)$$
    (7)
  • Difference between the maximum displacement value and the last value divided by the corresponding time interval \({d}_{{\text{slope}}\_{\text{aftermax}}}^{i}\):

    $$\begin{aligned}&{d}_{{\text{slope}}\_{\text{aftermax}}}^{i}\\ &\quad =\frac{{d}_{{\text{max}}\_last}^{i}}{\left[index\left({d}_{N}^{i}\right)-index\left({d}_{max}^{i}\right)\right]\cdot 0.01}\ \left(\frac{\mu m}{s}\right)\end{aligned}$$
    (8)
  • Median of the absolute deviations from the displacement data median \({d}_{median\_abs}^{i}\):

    $${d}_{median\_abs}^{i}=median\left(\left|{d}_{j}^{i}-{\text{median}}\left({D}^{i}\right)\right|\right) \left(\mu m\right)$$
    (9)
  • Standard deviation of the displacement values \({d}_{std}^{i}\):

    $${d}_{std}^{i}= \sqrt{\frac{1}{N-1} \sum\nolimits_{j=1}^{N}{\left({d}_{j}^{i}-{d}_{mean}^{i}\right)}^{2}} \left(\mu m\right)$$
    (10)

Such features underwent a feature selection process to identify the more informative features of the class variable. The process is detailed in Sect. 2.4.

2.3.2 Electrode force

The electrode force signals have also been examined to extract explanatory features of the class variable. For example, Fig. 9 displays the electrode force curves recorded at the beginning (1st weld), middle (692nd weld), and end (1245th weld) of the first experimental campaign.

Fig. 9
figure 9

Electrode force curves relating to the beginning, the middle, and the end of the 1st experiment

The electrode force is achieved by applying a specific pressure, regulated by the control unit TE700 of the RSW machine. Electrode force provides valuable insights into the process, as it is directly linked to how electrodes interact with the work sheets. As can be observed in Fig. 9, it shows a rapid growth when the welding current is applied, reaching its peak before the current stops. The initial increase is attributed to the thermal expansion of the weld nugget caused by the Joule effect (similar to the displacement). Then, heat increases with welding time and the electrode force falls when the weld zone becomes softer and consequently less resistance is encountered [46].

It turns out that the same considerations highlighted for the electrode displacement curves also hold for the electrode force signals, and they were used to extract quantitative features from the curves. As for the electrode displacement, data recorded from the electrode force sensor can be arranged in a vector:

$${F}^{i}= \left[{f}_{1}^{i},\ldots ,{f}_{j}^{i},\ldots ,{f}_{N}^{i}\right] (kN)$$
(11)

where \({F}^{i}\) is the electrode force signal vector corresponding to the i-th spot weld; \({f}_{1}^{i}\) is the first force value during the i-th spot weld, N is the total number of electrode force values considered for each inspected spot weld.

The extracted features from the electrode force signal are:

  • Time in correspondence of the maximum force \({f}_{{\text{max}}\_time}^{i}\):

    $${f}_{{\text{max}}\_time}^{i}={\text{index}}({f}_{\mathit{max}}^{i})\cdot 0.01 ({\text{s}})$$
    (12)
  • Maximum force value divided by the corresponding time \({f}_{{\text{max}}\_{\text{over}}\_{\text{time}}}^{i}\):

    $${f}_{{\text{max}}\_{\text{over}}\_{\text{time}}}^{i}=\frac{{f}_{{\text{max}}}^{i}}{{f}_{{\text{max}}\_time}^{i}}\, \left(\frac{{\text{kN}}}{{\text{s}}}\right)$$
    (13)
  • Difference between the maximum force and the last value divided by the corresponding time interval \({f}_{{\text{slope}}\_{\text{aftermax}}}^{i}\):

    $$\begin{aligned}&{f}_{{\text{slope}}\_{\text{aftermax}}}^{i}\\ &\quad=\frac{{f}_{{\text{max}}}^{i}- {f}_{N}^{i}}{\left[index\left({f}_{N}^{i}\right)-index\left({f}_{max}^{i}\right)\right]\cdot 0.01}\ \left(\frac{{\text{kN}}}{{\text{s}}}\right)\end{aligned}$$
    (14)
  • Difference between the maximum force and the first value divided by the corresponding time interval \({f}_{{\text{slope}}\_{\text{befmax}}}^{i}\):

    $${f}_{{\text{slope}}\_{\text{beforemax}}}^{i}=\frac{{f}_{{\text{max}}}^{i}- {f}_{1}^{i}}{index\left({f}_{max}^{i}\right)\cdot 0.01}\ \left(\frac{{\text{kN}}}{{\text{s}}}\right)$$
    (15)
  • Median of the absolute deviations from the force data median \({f}_{median\_abs}^{i}\):

    $$f_{median\_abs}^{i} = median\left( {\left| {f_{j}^{i} {\text{ - median}}\left( {F^{i} } \right)} \right|} \right)(kN)$$
    (16)
  • Standard deviation of the force values \({f}_{std}^{i}\):

    $${f}_{std}^{i}= \sqrt{\frac{1}{N-1} \sum\nolimits_{j=1}^{N}{\left({f}_{j}^{i}-{f}_{mean}^{i}\right)}^{2}} (kN)$$
    (17)
  • Coefficient of variation of the force values \({f}_{variations}^{i}\):

    $${f}_{variations}^{i}=\frac{{f}_{std}^{i}}{{f}_{mean}^{i}}$$
    (18)
  • Skewness of the force values to measure the asymmetry data around its mean \({f}_{skew}^{i}\):

    $${f}_{skew}^{i}=\frac{\frac{1}{N}\sum_{j=1}^{N}{\left({f}_{j}^{i}-{f}_{mean}^{i}\right)}^{3}}{{\left(\sqrt{\frac{1}{N}\sum_{j=1}^{N}{\left({f}_{j}^{i}-{f}_{mean}^{i}\right)}^{2}}\right)}^{3}}$$
    (19)
  • Difference between the 75th and 25th percentiles of the force data \({f}_{iqrs}^{i}\):

    $${f}_{iqrs}^{i}={{F}^{i}}_{0.75}-{{F}^{i}}_{0.25}\,(kN)$$
    (20)

2.4 Feature selection

The electrode displacement and force features were subjected to a feature selection process. The Minimum Redundancy Maximum Relevance (MRMR) algorithm was used for this purpose, aiming to identify a set of features that are both maximally dissimilar from one another and highly effective in representing the response variable [47]. The algorithm identifies the best set \(S\) of features that maximizes \({V}_{S}\), the relevance of \(S\) concerning the response variable \(y\), and minimizes \({W}_{S}\), the redundancy of \(S\).

\({V}_{S}\) and \({W}_{S}\) are defined using the mutual information \(I\):

$${V}_{S}= \frac{1}{\left|S\right|}\sum_{x\epsilon S}I(x,y)$$
(21)
$${W}_{S}= \frac{1}{{\left|S\right|}^{2}}\sum_{x,z \epsilon S}I(x,z)$$
(22)

\(\left|S\right|\) Is the cardinality of \(S\), \(x\) and \(z\) are two generic features belonging to the feature set, i.e., the extracted features in Sect. 2.3. For each feature, the algorithm computes the mutual information quotient \({MIQ}_{x}\), which is used to select the most important features.

$${MIQ}_{x}= \frac{{V}_{x}}{{W}_{x}}$$
(23)

\({V}_{x}\) and \({W}_{x}\) are the relevance and redundancy of a feature:

$${V}_{x}= I(x,y)$$
(24)
$${W}_{x}= \frac{1}{\left|S\right|}\sum_{z \epsilon S}I(x,z)$$
(25)

\({MIQ}_{x}\) Can be used to rank features through an importance score. In this way, the feature selection process can be quantitively performed. The MRMR algorithm was implemented in MATLAB. More information are in MATLAB documentation [48].

2.5 Classification algorithms

A classification approach has been adopted to develop a practical data-driven tool capable of automatizing decisions about the quality compliance of the spot welds based on electrode wear. The features selected in Sect. 2.4 were used as predictors of the spot weld quality class using machine learning algorithms. Specifically, five state-of-the-art machine learning algorithms have been applied to the dataset: logistic regression, support vector machine, k-nearest neighbors, random forest, and artificial neural network [49].

Logistic regression (LR) is an extension of linear regression to deal with classification problems. The method aims to identify a fitting model that represents the connection between an output variable and a group of input factors. Instead of fitting a straight line or hyperplane (as in linear regression), the logistic regression model uses a sigmoid function to map any real input number into binary output values. Because the sigmoid function is interpretable as a probability function, every output greater than 0.5 will be classified as 1, and any output less than 0.5 will be classified as 0 [50].

Support Vector Machine (SVM) is considered as a large margin classifier because its decision boundary is achieved by the hyperplane that has the largest distance to the nearest training-data point of any class. Instead of relying only on the sigmoid function, SVM can adopt different Kernel functions, such as linear, polynomial, radial basis function, etc. In this way the separation between data classes is widened even for non-linear problems. Unlike LR, it works as a discriminant, not as an estimator of probability [49]

K-Nearest Neighbors (KNN) algorithm relies on the idea that similar data are close to each other. It assigns the class label to a sample by computing the most frequent label among the nearest k samples. The distance between samples is usually computed with the Euclidean distance. If k = 1, then the sample is assigned to the class of that single nearest neighbor [51].

Random Forest (RF) extends the decision tree classifier by creating multiple decision trees and assigning the class selected by most trees to a sample. Each decision tree assigns a class based on a series of decision rules applied to some explanatory features. The first decision rule is applied at the root node and splits the dataset into two subsets of data representing the branches of the tree. New decision rules are applied at other splitting nodes along the branches until the leaf node is reached, which contains the algorithm prediction. The decision rule is selected at each splitting node to maximize purity, which refers to the node ability to divide all data into a single class [49].

Artificial Neural Network (ANN) algorithm can make predictions on a class variable by considering the values of the input explanatory features. The network consists of multiple layers, each containing various computation units, referred to as activations units or neurons. The first layer of the network is made up of the input feature vector. The second layer, known as the first hidden layer, is created by multiplying the input feature vector by a weight matrix. The result is then added to a bias vector and an activation function is applied. This process can be repeated to create additional hidden layers until the output layer is reached, which contains the algorithm prediction. Common choices for the activation function are the sigmoid function, the rectified linear unit (ReLU), and the tanh function [49].

All the aforementioned models have been applied to the dataset created in this work. The accuracy of each model has been optimized by tuning one or more hyperparameters. Each algorithm has been applied using the leave-one-out cross validation (LOOCV) technique. It is a special type of cross validation in which the number of folds equals the number of instances in the dataset. It means that the algorithms are applied using, for every run, one sample as a test set and all the others as a training set [52].

2.6 Model selection

The last step of the methodological framework is the selection of the more performing classification algorithm. The assessment procedure relies on the following definitions:

  • True Positive (TP)—the algorithm correctly predicts the positive class;

  • True Negative (TN)—the algorithm correctly predicts the non-positive class;

  • False Positive (FP)—the algorithm predicts the positive class when it is non-positive;

  • False Negative (FN)—the algorithm predicts the non-positive class when it is positive.

According to these definitions, the performance of the algorithm can be assessed by computing the accuracy of the classifier, expressed as the ratio between the correct predictions and the total predictions:

$$A=\frac{TP+TN}{TP+TN+FP+FN}$$
(26)

It is a proper metric to evaluate the overall performance of the algorithms. The model with the highest accuracy is considered as the final spot weld quality classifier.

3 Results and discussion

In this section the results obtained from the application of the methodology are presented and discussed. The first step involved the execution of two different experimental campaigns in which the quality of spot welds was periodically investigated through shear-tension tests. The latter were used to build the class variable based on the relative failure load as previously discussed in Sect. 2.2. The trend of the relative failure load as a function of the number of welds is displayed in Fig. 10.

Fig. 10
figure 10

Relative failure load acquired during the experimental campaigns and class label definition

As outlined in the methodological Sect. 2.2, any failure load exceeding 80% of the failure load obtained with a new electrode, i.e., a relative failure load greater than 0.8, was categorized as class ‘0’. These welds are considered compliant because they exhibit acceptable mechanical strengths. On the contrary, any failure load equal to or less than 80% of the failure load obtained with a new electrode, i.e., relative failure load equal to or less than 0.8, was categorized as class ‘1’. These welds are non-compliant, characterized by low mechanical strength due to the electrode deterioration and, hence, are deemed not acceptable. The machine learning algorithm will automatically predict the weld quality class (‘0’ or ‘1’) based on data from sensors.. It is noticeable that the created classes are fairly balanced. Most data belonging to the class ‘1’ occur after a high number of welds, starting around 600 welds, because of the electrode wear process.

The conducted tests provide a broad guideline. Up to approximately 600 welds, the electrode consistently produces compliant welds (class ‘0’) with limited variability in the relative failure load. Between 600 and 1000 welds, the number of non-compliant (class ‘1’) welds begins to increase, although a significant number remains compliant. During this phase, the welding process becomes unstable due to electrode degradation, characterized by an enlarged variability in the relative failure load. Beyond 1000 welds, the variability in the relative failure load remains high, but the majority of spot welds produced are non-compliant. This behavior aligns with findings in previous literature [26, 33, 36, 53] and provides general recommendations: if a company cannot tolerate any non-compliant welds, the electrode should be redressed or replaced at the first instance of non-compliance. Alternatively, if the company is willing to accept some non-compliant welds and compensate them with redundant welds, the limit for electrode replacement can be set at 1000 welds.

Several features were extracted from sensors for each inspected weld, as explained in Sect. 2.3. Overall, 16 features have been extracted, 7 regarding the electrode displacement and 9 regarding the electrode force. Figure 11 displays the scatter plots of the features extracted from the electrode displacement signals and the corresponding Pearson correlation coefficients.

Fig. 11
figure 11

Scatter plots of the features extracted from the electrode displacement signals; the plots represented from a) to g) refer to the features defined from Eq. (4) to Eq. (10)

As outlined in Sect. 1, the electrode degradation leads to a decrease in electric current density, resulting in a smaller weld nugget and, consequently, diminished mechanical strength. The decreased size of the weld nugget also implies a restriction on its thermal expansion during welding. This limitation is evident in two key features of each detected spot weld: the reduced difference between the maximum displacement value and the last recorded (\({d}_{{\text{max}}\_last}^{i}\), Eq. (6), Fig. 11c) and the diminished slope of the displacement curve in the declining phase (\({d}_{{{\text{slope}}}_{{\text{aftermax}}}}^{i}\), Eq. (8), Fig. 11e). These two features exhibit the highest correlation between the electrode displacement with the relative failure load (which defines the weld quality classes) with a Pearson correlation coefficient of 0.63 and 0.60, respectively. Conversely, the difference between the maximum displacement value and the first value recorded from the sensor (\({d}_{{\text{max}}\_first}^{i}\), Eq. (7), Fig. 11d) is the feature with the lowest correlation, close to 0.22. This feature shows a strong non-linearity with the relative failure load, not captured by the computation of the Pearson correlation coefficient. This non-linearity arises from the simultaneous competition between the factor influencing the maximum displacement value -the thermal expansion of the weld nugget- and the initial electrode displacement—the axial wear of the electrode. In fact, as explained previously, the electrode undergoes with the progression of the deterioration process an axial contraction due to plastic deformation and wear, necessitating a longer stroke to clamp the sheet stack. Similarly, a correlation coefficient of less than 0.25 is observed for the maximum displacement value in the spot weld (\({d}_{max}^{i}\), Eq. (4), Fig. 11a), making it a non-informative feature of the relative failure load. However, the time at which this maximum displacement value occurs (\({d}_{{\text{max}}\_time}^{i}\), Eq. (5), Fig. 11b), has a better correlation coefficient, equals to -0.46. This is primarily due to the progression of electrode degradation, causing the nugget to take longer to form, and its thermal expansion to occur later. Therefore, higher values of this feature correspond to lower values of the relative failure load. A similar correlation coefficient, but with an opposite sign, is observed for the median of the absolute deviations from the displacement data median (\({d}_{median\_abs}^{i}\), Eq. (9), Fig. 11f). This metric, related to the amplitude of the electrode displacement curve, shows higher values correspond to higher relative failure loads. Similar information is provided by the standard deviation of the displacement values (\({d}_{std}^{i}\), Eq. (10), Fig. 11g), which exhibits a positive correlation with the relative failure load, equal to 0.44.

Figure 12 shows the scatter plots and the Pearson correlation coefficients of the features extracted from the electrode force signals.

Fig. 12
figure 12

Scatter plots and correlation coefficients of the features extracted from the electrode force signals; the plots represented from a) to i) refer to the features defined from Eq. (12) to Eq. (20)

As previously mentioned, electrode wear results in reduced weld nugget thermal expansion. The most important features, in terms of Pearson correlation, are the time when the peak is reached (\({f}_{{\text{max}}\_time}^{i}\), Eq. (12), Fig. 12a) with a coefficient of -0.65, and the velocity of achieving such a maximum (\({f}_{{\text{max}}\_{\text{over}}\_time}^{i}\), Eq. (13), Fig. 12b), with a correlation coefficient of 0.54. These two features suggest that as the degradation process progresses and, consequently, the thermal expansion of the nugget decreases, there is a slower instantaneous velocity at the point of maximum force and a delayed attainment of the maximum force during welding.

A group of four features has similar absolute coefficients, ranging between 0.36 and 0.30. The average slope before reaching the peak value (\({f}_{{\text{slope}}\_{\text{beforemax}}}^{i}\), Eq. (15), Fig. 12d), unlike the feature \({f}_{{\text{max}}\_time}^{i}\), calculates the average velocity of force growth between the initial value of the vector \({F}^{i}\) (Eq. (11) and the peak. The other three features of this group are related to the variability of the force values along the welding (\({f}_{{\text{std}}}^{i}\), Eq. (17), Fig. 12f), (\({f}_{{\text{variations}}}^{i}\), Eq. (18), Fig. 12g) and to the skewness (\({f}_{{\text{skew}}}^{i}\), Eq. (19), Fig. 12h), which measures the asymmetry of the curves.

The less important features, with low correlation, include the slope after maximum (\({f}_{{\text{slope}}\_{\text{sftermax}}}^{i}\), Eq. (14), Fig. 12c) with a coefficient of -0.10 and other two indicators of statistical dispersion: the median absolute deviation (\({f}_{{\text{median}}\_{\text{abs}}}^{i}\), Eq. (16), Fig. 12e), with a correlation index of 0.17, and the interquartile range (\({f}_{{\text{iqrs}}}^{i}\), Eq. (20), Fig. 12i), with a coefficient of 0.16.

Features extracted from the electrode force signals are generally more scattered with lower correlation coefficients than the features extracted from the electrode displacement signals. However, the features related to the time corresponding to the maximum force (\({f}_{{\text{max}}\_time}^{i}\), Eq. (12)) and to the maximum force value divided by the corresponding time (\({f}_{{\text{max}}\_{\text{over}}\_{\text{time}}}^{i}\), Eq. (13)) have a modulus of correlation coefficients higher than 0.50.

After feature extraction, a feature selection process has been performed with the MRMR algorithm, as explained in Sect. 2.4. This algorithm computes an importance score for each extracted feature to identify the most dissimilar features capable of predicting the class variable effectively. In this way, a ranking can be established to select the most informative features. The Pareto chart has been built based on the feature importance scores to show the results of the feature selection process, as shown in Fig. 13.

Fig. 13
figure 13

Pareto chart of the feature importance scores calculated with the MRMR algorithm

The difference between the maximum displacement value and the last recorded value during the spot weld \({d}_{{\text{max}}\_last}^{i}\) is clearly the most informative feature of the relative failure load, with the highest importance score of 0.1765. The second most important feature is the time in correspondence of the maximum displacement \({d}_{{\text{max}}\_time}^{i}\) with an importance score of 0.0646. Next, the maximum force value divided by the corresponding time \({f}_{{\text{max}}\_{\text{over}}\_{\text{time}}}^{i}\) is ranked third with an importance score of 0.0425. The average descending slope after the maximum displacement value \({d}_{{\text{slope}}\_{\text{aftermax}}}^{i}\) also shows a non-negligible contribution with an importance score of 0.0265. Finally, the time in correspondence of the maximum force \({f}_{{\text{max}}\_time}^{i}\) gives very little contribution to the prediction of the class variable, with an importance score of 0.0083. All the other extracted features have a negligible importance score.

It should be noted that all the selected features have a Pearson correlation coefficient higher than 0.5. Moreover, the selected features exhibit a very different trend with the relative failure load, with the exception of \({d}_{{\text{max}}\_time}^{i}\) and \({d}_{{\text{slope}}\_{\text{aftermax}}}^{i}\). This demonstrates that the feature selection process adopted in this work can identify the most dissimilar, but informative, features of the class variable.

The five selected features identified in Fig. 13 were used to feed the classification algorithms described in Sect. 2.5. LR, SVM, KNN, and RF algorithms were implemented in Python open-source library Scikit-learn [54], whereas the ANN algorithm was implemented in Keras [55]. SVM, KNN, RF, and ANN have been optimized to achieve the highest accuracy by tuning one or more hyperparameters. For LR, instead, the number of maximum iterations the algorithm performs to achieve convergence has been varied. Despite this, the algorithm accuracy remained stable at 0.855 for every number of iterations implemented from 20 to 1000. Thus, the number of iterations has been set equal to 20. The process of hyperparameters optimization for the other algorithms is shown in Fig. 14. Specifically, Fig. 14a) depicts the graph bar of the accuracy of SVM for different types of Kernel functions, Fig. 14b) the variation of KNN accuracy when the number of nearest neighbors is varied, Fig. 14c) the performance of RF algorithm for different numbers of decision trees, Fig. 14d) the accuracy achieved by the selected ANN architecture for different values of batch size. The ANN architecture was selected by varying the number of hidden layers and the number of neurons, as detailed thereafter.

Fig. 14
figure 14

Hyperparameters optimization of machine learning algorithms: a SVM; b KNN; c RF; d ANN

Various Kernel functions have been applied to SVM algorithm, Fig. 14a): linear, polynomial of second and third degree, radial basis function, and sigmoid function. The highest accuracy, 0.870, has been achieved with the linear Kernel. For the KNN algorithm, different values of K, representing the number of nearest neighbors, have been tested. K varied from 1 to 20, significantly affecting the algorithm performance. As shown in Fig. 14b), K = 5 provides the highest accuracy, 0.884. The RF algorithm has been tested by implementing a varied number of decision trees, ranging from 3 to 100, Fig. 14c). RF exhibits the optimal performance as the number of decision trees is 10, equal or exceeds 50, with a classification accuracy of 0.855. The number of decision trees implemented in RF has been chosen 10 to streamline the computational process. The optimization of the ANN has involved more hyperparameters than the other algorithms due to its complexity. Four hyperparameters were varied: the number of hidden layers, the number of neurons, the batch size, and the number of epochs. The number of layers ranged from 1 to 3, the implemented neurons was 4, 8, and 12, the batch size was 16, 32, and 64, the number of epochs varied from 100 to 1000. The most efficient ANN architecture has been obtained with 1 hidden layer and 8 neurons. For this configuration, the accuracy for different batch sizes and the number of epochs is displayed in Fig. 14d). The highest accuracy, 0.899, has been obtained with a batch size of 64 and the number of epochs set to 300.

Finally, the accuracy of each classification algorithm has been compared to select the most performing model, Fig. 15.

Fig. 15
figure 15

Comparison among the accuracy of the examined Machine Learning algorithms

Overall, all the models are satisfying with an accuracy between 0.8 and 0.9. ANN shows the highest accuracy, 0.899, and it has been selected as the final weld quality classifier.

As detailed in Sect. 1, in contrast to previous studies, this research provides direct support to manufacturers in evaluating the impact of electrode wear on spot weld quality. By collecting data from electrode displacement and force sensors, these data can be processed and used by an ANN algorithm for a real-time prediction of the weld quality class with an accuracy close to 90%. This tool provides manufacturers with more precise information about spot welds falling into the non-compliant category due to the electrode degradation process.

4 Conclusions

This work introduces a machine learning-based tool for assessing the effect of electrode wear on the quality of resistance spot welds. Two experimental campaigns, differing in material thickness, electrode tip diameter, and process parameters, were conducted to indirectly detect the electrode wear effect on weld quality.

The relative failure load of the spot weld, expressed as the ratio between the actual failure load and the failure load at the beginning of the experimental campaigns, was used to define the class variable. Data were allocated to two classes based on a threshold value of 0.8, as recommended in the literature. Predictors of the class labels were computed from data collected during the welding process by electrode displacement and electrode force sensors directly embedded in the RSW machine. Different features were extracted applying several statistics to the collected signals. The most dissimilar features capable of predicting weld quality effectively were selected through a MRMR algorithm. Five different classification algorithms were applied to the dataset created in this work, with each model optimized by tuning its hyperparameters. Finally, the most performing algorithm, an artificial neural network, was selected, achieving the highest accuracy of 0.899 and serving as the final weld quality classifier.

This work provides both theoretical and practical contributions to the field of electrode wear assessment in RSW. The main theoretical finding is that the electrode displacement signal during welding provides valuable information correlated with the electrode degradation process. Specifically, the difference between the maximum electrode displacement value during welding and the electrode displacement value at the end of welding is the most informative predictor of the relative failure load of the joint. This is pointed out by the high Pearson correlation coefficient and the highest importance score calculated during the feature selection process. This outcome validates and expands previous discussions in the literature. A prior study found that the electrode displacement signal could be employed to predict the electrode contact area, which serves as a reliable electrode wear indicator [36]. More in detail, the average electrode descent speed, calculated as the difference between the maximum displacement value and the last value divided by the corresponding time interval (Eq. 8), was found to be the most correlated feature with the electrode contact area. In this work, the difference between the maximum displacement value and the last value (Eq. 6) emerges as the most informative feature with the relative failure load. This strengthens the electrode displacement as a highly informative signal for the electrode wear process.

From a practical standpoint, a predictive tool for the weld quality class is developed by leveraging a machine learning algorithm. This tool automatically assess weld quality (class ‘0’ for compliant welds, ‘1’ for non-compliant welds) based on the electrode displacement and electrode force signals acquired during welding. This facilitates the automatic detection of low-quality welds, providing valuable insights for maintenance operations. Proactively replacing or dressing the electrode before it produces low-quality welds helps avoid or significantly reduce redundant welds, leading to savings in time, energy, and resources for manufacturers, contributing significantly to the sustainability of the manufacturing process. Manufacturers can be supported during their operations with a real-time informative tool. Furthermore, this study offers guidance on the timing for electrode dressing or replacement. If a company does not tolerate non-compliant welds, it is advisable to redress or replace the electrode at the first occurrence of non-compliance, around 600th weld in this study. On the other hand, if the company would accept some non-compliant welds, compensating with redundant welds, the threshold for electrode replacement/dressing can be established at 1000 welds.

Future research could focus on quantifying the resource savings achieved through the utilization of the developed tool, balancing the savings in time, energy, and resources due to the avoided redundant welds against the cost of acquiring and operating sensors in the machine. Future research could also enhance the data-driven capabilities of the developed tool by considering other types of welding defects beyond electrode wear. Identifying predictors of defects such as resistance shunting, sheet gap, edge proximity, non-orthogonal electrode-sheet contact, etc., would contribute to improving the monitoring of the RSW process.