Energy Consumption Prediction for Fused Deposition Modelling 3D Printing Using Machine Learning

: Additive manufacturing (AM) technologies are growing more and more in the manufacturing industry; the increase in world energy consumption encourages the quantiﬁcation and optimization of energy use in additive manufacturing processes. Orientation of the part to be printed is very important for reducing energy consumption. Our work focuses on deﬁning the most appropriate direction for minimizing energy consumption. In this paper, twelve machine learning (ML) algorithms are applied to model energy consumption in the fused deposition modelling (FDM) process using a database of the FDM 3D printing of isovolumetric mechanical components. The adequate predicted model was selected using four performance criteria: mean absolute error (MAE), root mean squared error (RMSE), R-squared (R2), and explained variance score (EVS). It was clearly seen that the Gaussian process regressor (GPR) model estimates the energy consumption in FDM process with high accuracy: R 2 > 99%, EVS > 99%, MAE < 3.89, and RMSE < 5.8.

Additive manufacturing (AM) is widely applied in a broad spectrum of domains, including architecture, mechanics, aeronautics, chemical industry, education, food, social culture, and medicine [4,5]. Indeed, the importance of additive manufacturing importance has grown during the COVID-19 pandemic; several medical tools have been created to mitigate disruptions in the global medical field [6].
AM is a generic term for a group of processes which can be classified according to machine architecture into seven categories [7,8], Table 1 summarized the different AM processes and associated technologies and materials.
As is evident, the range of techniques and materials is very wide. This subsector of additive manufacturing is growing rapidly in the industrial world, with compound annual growth rates of 24.5% [9,10], because additive manufacturing methods are more efficient and more flexible than conventional manufacturing methods, such as subtractive manufacturing and formative manufacturing. Therefore, attention is increasingly focused on the energy consumption of additive manufacturing (AM) systems. Much research has been conducted on energy consumption modeling for the AM process [10][11][12]. However, an efficient model for predicting energy consumption in the FDM process is still absent, in particular regarding the usage of machine learning (ML) for estimating energy use in the FDM process based on part orientation. Table 1. Brief description of different additive manufacturing processes [7,8].

AM Process Type Brief Description Material Used Technologies
Vat photopolymerization photopolymers are exposed to repeated forms of radiation corresponding to cross sections of the part under construction. Thermal energy is used to merge materials by melting as the material is being deposited.

Metals
Laser metal deposition (LMD), electron beam metal deposition, wire arc additive manufacturing (WAAM) In this work, we mainly focus on energy consumption prediction in the fused deposition modelling (FDM) process. This process is one of the most frequently applied additive manufacturing methods. In fact, FDM printers largely simplify and accelerate the production process, providing users with an efficient manufacturing environment with better material utilization and reduced time consumption. The FDM principle is based on the extrusion of molten thermoplastic filaments layer by layer to form three-dimensional parts [13]. The FDM method includes numerous printing parameters, such as percentage infill, infill style, layer thickness, printing speed, and printing temperature, which affect the quality of the final product [14][15][16].
The aim of the current study is to model the experimental results of energy consumption for the FDM 3D printing of isovolumetric mechanical components using several ML algorithms. The simulation results provide the expected results and demonstrate the predictive accuracy of the Gaussian process regressor (GPR) method versus other ML methods used. With our developed GPR model, we can select the appropriate orientation of the part to be printed in order to reduce energy consumption. This prediction can be used to encourage engineers as they develop intuition for novel designs with FDM technology.
In this paper, the Section 2 presents a literature overview on energy consumption estimation in 3D printing. The Section 3 is devoted to the presentation of experimental data extracted from [11]. The Section 4 is dedicated to the methodologies of the ML algorithms used to model the energy consumption use of 3D printing isovolumetric mechanical components, while the prediction results and discussion are presented in the Sections 5 and 6. The Section 7 presents conclusions.

Literature Review
A significant number of research studies investigated the estimation and the optimization of energy use in AM Processes by following various modeling approaches, such as mathematical and mechanical modeling, based on the process's physics and artificial intelligence modeling.
A prediction model of energy consumption and printing time based on the working states of machine components and process parameters was proposed [17].The proposed model has certain limitations in the printing phase; the prediction model did not take into account the time needed for the empty travel, acceleration, and deceleration of the nozzle movement.
A data fusion method was suggested based on the convolutional neural network and long short-term memory CNN-LSTM model for AM energy consumption prediction [18]. For validating the proposed model, a case study was carried out using an SLS system. The CNN-LSTM-developed model does not predict accurately; this may be due to a significant loss of information during the convolution feature extraction process because the sliced images are less informative.
An energy consumption prediction model for AM systems was developed that incorporates clustering techniques and deep learning to integrate the multi-source data collected using the Internet of Things [19]. For validating the approach, a case study is conducted on the basis of actual data collected on the SLS process, which demonstrated the merits of the proposed approach.
In [20], authors presented the implementation of a tool to predict the energy flows occurring in direct metal laser sintering. A model for assessing energy and material consumption for binder jetting was developed [21]. A comparative study on energy consumption made at the process level for conventional and additive manufacturing processes was presented [22].
In [23], authors developed an approach based on the NC codes to estimate the material usage, time, and energy consumption of 3D-printed models. They validated their approach with two experiments, both of which present deviations of around 9% and 11% from the theoretical values.
A deep learning algorithm (ANN) was applied to predict the part mass, support material mass, and build time of voxelized objects for an AM process [24]. The results of the model were compared to results generated afterwards. This prediction model had low accuracy, with determination coefficients of 46.8% for part mass, 30.1% for support material mass, and 22.5% for build time.
A model and an energy profiler was developed to simulate the energy cost of the printing process [11]. From the obtained results, they suggested a cross-layer energy optimization solution, called 3DGates; it was assessed over 338 benchmarks on a 3D printer and realized a 25% reduction in energy consumption.
In [25], researchers built an energy consumption model and calculated the amount of energy used in wire-based additive-subtractive hybrid manufacturing and powderbased hybrid additive-subtractive manufacturing. They observed that the wire-based and powder-based methods used similar amounts of energy.
Potential environmental implications of AM were described in [26], such as energy use, waste, lifecycle impact, and occupational health, noting that AM technologies use more energy than conventional manufacturing technologies.
A mathematical model was developed for estimating the energy consumption of stereolithography processes [2].The obtained results were validated experimentally, the effects of different parameters on the total energy consumption was studied, and an optimization method was proposed to minimize energy consumption based on an optimal combination of parameters.
In [27], the operating procedure was analyzed and the impact of printing parameters on the energy consumption and particulates emissions was studied. The power profile analysis illustrated that print bed heating and temperature maintenance consume significant amount of energy during the FDM process.
Based on the abovementioned works, it is evident that a large amount of research has been performed on the estimation and optimization of the energy consumption of 3D printing processes. However, little work has been done to develop an efficient model based on part orientation to predict and minimize energy use in the FDM process. In this work, 12 ML models are used to select the most efficient model for obtaining the best prediction of energy consumption. This paper has three main aims: 1. Predict the energy use of FDM printed parts; 2.
Assess the impact of printing parameters on energy consumption; 3.
Optimize energy consumption based on the orientation of the part to be printed.

Design of Experiment Data
The data used in this research were retrieved from the experiment reported in [16]. We applied the machine learning algorithms to predict the energy consumption and compared it with the actual experimental results reported by the authors in [16]. The experiment was conducted using a Prusa i3 MK3S 3D printer. Electrical energy consumption was assessed for printing 68 different isovolumetric mechanical components with multiple orientations (total of 184 model files); these components were selected from Mechanical Components Benchmark (MCB) [28]. The experimental setup included four Adafruit INA260 sensors to measure the current consumption of the 3D printer, Arduino MKR WiFi 1010 to collect the electric current data from the current sensors, and a Raspberry Pi board to read the serial data coming from the Arduino board.
Many parameters affect the energy consumption in FDM 3D printing, including printing orientation of the model, stl surface area, number of facets, extrusion speed, extrusion temperature, sliced X', sliced Y', sliced Z', sliced volume, sliced volume including support, total filament, percentage infill (20%), layer thickness, expected print time, and number of layers.
Extrusion speed and temperature are among the most important parameters affecting FDM printing; they have been used as recommended by the manufacturer [16]. Since extrusion speed, extrusion temperature, percentage infill, and layer thickness are constant parameters, they do not affect the learning phase, so we will not take these as input data.
The range of input parameters used is shown in Table 2 [28]. Number of layers  The experimental data are used in this research to train machine learning algorithms to predict energy consumption in the FDM process.

Methodology
In this work, we aim to propose a model for predicting energy consumption in the FDM process. For this, before training the different algorithms that we will present afterwards, it is necessary to prepare and perform some processing on the dataset: - The first step is data cleaning, in which we eliminate the useless information to keep only the input and output parameters used in our study, which are shown in Table 2. -In the second step, we will transform the data into a format or structure that would be more appropriate for model development and also data exploration in general. In our case, we have used standard scaler.
After data processing, we train each algorithm using different parameters until we find the optimal parameter values for our data, as shown in Figure 1.   The experimental data are used in this research to train machine learning algorithms to predict energy consumption in the FDM process.

Methodology
In this work, we aim to propose a model for predicting energy consumption in the FDM process. For this, before training the different algorithms that we will present afterwards, it is necessary to prepare and perform some processing on the dataset: - The first step is data cleaning, in which we eliminate the useless information to keep only the input and output parameters used in our study, which are shown in Table 2.
-In the second step, we will transform the data into a format or structure that would be more appropriate for model development and also data exploration in general. In our case, we have used standard scaler.
After data processing, we train each algorithm using different parameters until we find the optimal parameter values for our data, as shown in Figure 1. In this section, we will review the different machine learning algorithms that we have used to find the best model to predict energy consumption in the FDM process, using as input the data shown in Table 2. Then we will present the statistical indicators used to measure performance. In this section, we will review the different machine learning algorithms that we have used to find the best model to predict energy consumption in the FDM process, using as input the data shown in Table 2. Then we will present the statistical indicators used to measure performance.

Linear Regression
The mathematical formula for linear regression [29,30] is defined by the following equation: This linear regression model is formed by the mean function; it is a linear equation that combines a set of input values (X) with the output (Y) that represents the predicted value. The β 0 value is obtained for E(Y | X = x) with X = 0 and the intercept β 1 is calculated by changing the values of X. The variance is assumed to be a positive value, usually unknown.
The observed value and the estimated value are related by the following formula: where e i is the error calculated in estimation, which depends directly on the unknown parameters.

RANSACRegressor (Random Sample Consensus)
RANSAC is a random sampling algorithm which was first introduced by Fischler and Bolles [31]. This algorithm gives a fit to the model by excluding outliers; RANSAC is able to smooth and interpret training data containing gross errors. The presence of outliers has an impact on the parameters of the training model, so it is preferable to remove outliers from the training. The objective of RANSCAN is to fit the model with outliers while efficiently exploring the parameter space to maximize an objective function C (3). In the standard RANSAC formula, the maximized objective function C is the support size for a given model. In other words, the support is the number of points that have residual errors below a predefined threshold t (4), and the group of points is called the consensus set. The goal of the method is to maximize the cardinal of this group (3).

Ridge Regression
This approach was introduced by Hoerl-Kennard [32]. It aims to optimize Formula (5): It is a linear regression with quadratic constraint on the coefficients. This regression is used more when we have variables that are highly correlated. The solution can be expressed as follows: where β * is the estimator of β, matrix αI is a named bias factor, and it is possible to choose an α for which the matrix (X X + αI) is invertible. This is especially useful when there are several variables. The goal of Hoerl-Kennard is to make the matrix (X X + αI) invertible; the higher the value of α, the more robust the model coefficients.

Lasso Regression
This is a regression technique with coefficient constraint. It is used when the variables have a high correlation. This method is very effective, especially with a database that has a large dimension [33]. Lasso regression aims at optimizing Problem (7): For a single variable, this regression acts on one variable, and lasso must minimize the following formula: That is, we must find β with E(β) = 0 In other words: And :

Gaussian Process Regressor (GPR)
The Gaussian process regressor formula is given by (13) with the input X = [x 1 , x 2 , . . . , x n ], the output Y = [y 1 , y 2 , . . . , y n ], and for any element {(x i , y i ) | i = 1, . . . , n},y i = f (x i ). The main idea of GPR is to apply a Gaussian process (GP) to represent f(x), which we will call latent variables. Input X allows us to index these latent variables so that { f (x 1 ), . . . , f (x k )} is a Gaussian distribution correlated between all elements. m m(x) is the mean of f(x) and, for the covariance, is described by the following equation: E( ) represents the expectation. The function of the mean is especially important when there is a region with unobserved inputs with a value of zero.
The Gaussian process regressor is given by: with: ε ∼ N 0, σ 2 and σ 2 are the variance of the noise. For the covariance, there are some specific parameters that are independent and give the distribution of f(X) and named hyperparameters θ i , and it usually uses the exponential squared Covariance (15).
Note that the covariance function decreases rapidly at input pairs x and x', which are distant, which expresses a low correlation between f(x) and f(x'). Therefore, θ 1 is a hyperparameter that represents the maximum correlation and θ 2 is a positive value defining the rate of decline for the correlation of points that are not close to each other.

Elastic Net Regressor
The elastic net regression model was introduced by [34] in order to solve the criticisms on the lasso, whose set of selection variables may be too dependent on the data and therefore unstable. The solution is to combine the regression penalties of ridge regression and lasso to exploit the best aspects of both methods. Elastic net aims to minimize Function (16): with:ŷ =β 0 + x 1β1 + · · · + x nβn is the predicted value for the input X of n elements. β i is the predicted coefficient. 0 ≤ α ≤ 1 and λ ≥ 0 where α is the mixing parameter between ridge regression (α = 0) and the lasso (α = 1).
Here, α determines the influence of ridge regression relative to lasso. There are two parameters to adjust: λ (penalty) and α. Elastic net must minimize the following function [34]: where λ 1 and λ 2 are the lasso and ridge regression penalties, respectively. Elastic net combines the advantages of lasso and ridge, which are shrinkage and sparsity, respectively.

Random Forest Regressor
This approach has a set of regression trees, and a sample of the training is processed each time first. In other words, each sample produces a regression tree. For the prediction of the test data, the average of the predictions of each tree is calculated; each tree gives us a prediction, and the prediction result is the average of the values (18).
The algorithm of this approach is the following: Step 1: From the dataset, we choose N records at random.
Step 2: For each N records, we create a regression tree.
Step 3: For each tree, we repeat steps 1 and 2.
Step 4: For a problem of a record E, we take the average of the other predictions of the other trees to estimate the Y value of the output.

SVM
SVM was introduced by Vapnik [35]. The SVM regression method is given by Formula (19), in which ϕ(x) is a nonlinear mapping function of the input x into a feature space and the two respective parameters b and ω represent the weight vector and a coefficient, respectively, both of which are to be calculated from the data. By performing a linear regression in a high dimensional feature space with nonlinear mapping, the two parameters b and ω are estimated by minimizing Sum (20), in which C is a constant and positive value that determines the tradeoff between the complexity of the model and the sum with a condition of having an error greater than ε. ||ω|| 2 is the Euclidean norm of the regression vector ω, and Lε is a loss function that calculates the empirical risk R (20).

Multi-Output Regression-SVR
This regression method [36] was introduced by Pérez-Cruz et al. [37]. This method is more generalized than standard SVR. Considering the {ϕ 1 , ϕ 2 , . . . , ϕ N } time series and for the multi-step prediction and modeling, this amounts in other words to finding in training the relation between the value of the previous observation x and the current observation y with: x = [ϕ t , ϕ t−1 , . . . , ϕ t−d+1 ] ∈ R d and y = [ϕ t+1 , ϕ t+2 , . . . , ϕ t+H ] ∈ R H ; i.e., for (x i , y i ) n i=d , the M-SVR aims to find a w j regressor and also find b j (j = 1, . . . , H) for each output by minimizing: with: u i = e i = e T i e i and where C is a parameter that determines the relationship between the regressor w j and the error e i and ϕ(.), a nonlinear function to the feature space x. L(u) is a quadratic cost function that is independent at epsilon: This approach is called support vector regression and was developed to perform regression [36]. The specificity of this method is that the training is performed only on a subset of the data. This is done given the cost for building the model; the SVR takes only the training data that are not close (with respect to a threshold e).
Multi-output regression is widely used, especially the objective is to make simultaneous predictions of several values in output. SVRs are more efficient than time series because the latter do not provide reassuring results for non-linear data.

Regression Chain
This method is based on the classical chain classification method. RC has the advantage of chaining models to a single target variable while creating regression models for each of the variables, which allows us to build in sequential order a chain of targets. The first target variable related to the regression model to be built is chosen independently from the other target variables. In the prediction process, these target values become inputs to the training set to predict the next target variable. That is, for X as input and for Y as output with three target variables Y (y1, y2, and y3) in the first regression, we fit the first model M1 for the variable y1 taking X as input (25). The second iteration concerns the second model, M2, which will be adjusted for the target variable y2 based on the training set, which is X and y1 (26), so model M3 is adjusted in the same way while having X and y1 and y2 as inputs (27).

KNeighbors Regressor
KNeighborsRegressor it is a supervised technique in machine learning. It is based on the neighbors; the KNN consists of performing a regression for the continuous labels. This method is based on the measure of similarity between the nearest elements. This measure is obtained by using the Euclidean distance between the nearest values (28).
The value of K is calculated in training. It must not be very small in order to not overfit the regression model and to avoid noise in the model. In other words, the value of K is determined in order to obtain the best model.

DecisionTreeRegressor
This is a supervised machine learning technique used for both classification and regression. This approach is based on the decision tree [21]. It is useful to train the data in a tree-like way and to make predictions.

Evaluation Metrics
In order to evaluate the performance of the approaches used, four statistical indicators were calculated: MAE (mean absolute error), RMSE (root mean square error), R 2 Square (coefficient of determination), and ESV (explained variance score):

•
Mean absolute error (MAE) is the mean of the absolute value of the errors; this indicator represents the average of the absolute difference between the actual and predicted values in the database. It measures the average of the residuals in the data set (29).
y − predicted value y − mean value • Root mean squared error (RMSE); this measure represents the root mean square error of the squared difference between the original and predicted values of the model (30).
• R-Squared expresses the ratio of the variance of the variable explained by the model with the original value (31).
Explained variance score (EVS); this metric expresses the rate representing the variance of the current value (true value) and the estimated value (32).

Results
In this article, we used twelve algorithms to find the most effective model for predicting energy consumption from the input ( Table 2). Figure 2 shows a graphical comparison between the actual energy values and the predicted energy for each part and according to its different orientations using these algorithms.  Figure 2 shows that some models predict results closer to the actual values. Table 3 presents the statistical performance indicators for each model in terms of MAE, RMSE, R 2 , and explained variance   Figure 2 shows that some models predict results closer to the actual values. Table 3 presents the statistical performance indicators for each model in terms of MAE, RMSE, R 2 , and explained variance   From Figure 3 and Table 3, it is clear that the GPR model achieves the highest precision, having 99.16% as the explained variance value. For the R-squared, it is 99.14%. The respective values of MAE and RMSE are 3.88 and 5.79. It can be seen that these values are the best in comparison with the other models.

Discussion
The benefits of artificial intelligence and machine learning algorithms in 3D printing are wide-ranging. In our case, before each printing, we will predict the printing energy depending on the part's orientation. Figure 4 illustrates a graphical comparison between From Figure 3 and Table 3, it is clear that the GPR model achieves the highest precision, having 99.16% as the explained variance value. For the R-squared, it is 99.14%. The respective values of MAE and RMSE are 3.88 and 5.79. It can be seen that these values are the best in comparison with the other models.

Discussion
The benefits of artificial intelligence and machine learning algorithms in 3D printing are wide-ranging. In our case, before each printing, we will predict the printing energy depending on the part's orientation. Figure 4 illustrates a graphical comparison between the actual energy values and the predicted energy for each part and according to its different orientations using the GPR model. It is clear that the two curves perform in a similar manner, so we can use the GPR model to find the best part orientation for printing, which will use less energy. To assess the performance of our approach, four parts from the database were selected at random. For each part (Table 4), we will predict the energy needed for printing according to the three orientations (0, 90, and 180).
From the results shown in Table 4: o For part number one, if we print it following orientation 180 instead of printing it following 0, we will lose about 70 Wh of energy.
o For part number two, if we print it following orientation 90 instead of printing it following 0, we will lose about 50 Wh of energy. o For part number three, if we print it following orientation 90 instead of printing it following 0, we will lose about 7 Wh of energy. o For part number four, if we print it following orientation 90 instead of printing it following 0, we will lose about 90 Wh of energy.
These pertinent results confirm the capacity of our model based on the GPR algorithm to predict energy consumption in the FDM process with high accuracy. To assess the performance of our approach, four parts from the database were selected at random. For each part (Table 4), we will predict the energy needed for printing according to the three orientations (0, 90, and 180).

Conclusions
In this research, twelve machine learning algorithms are used to model and predict energy consumption in the FDM process using a database of the FDM 3D printing of isovolumetric mechanical components (r3DIM benchmark). The most effective model is chosen based on four performance criteria: mean absolute error (MAE), root mean squared error (RMSE), R-squared (R2), and explained variance score (EVS From the results shown in Table 4: o For part number one, if we print it following orientation 180 instead of printing it following 0, we will lose about 70 Wh of energy. o For part number two, if we print it following orientation 90 instead of printing it following 0, we will lose about 50 Wh of energy. o For part number three, if we print it following orientation 90 instead of printing it following 0, we will lose about 7 Wh of energy. o For part number four, if we print it following orientation 90 instead of printing it following 0, we will lose about 90 Wh of energy.
These pertinent results confirm the capacity of our model based on the GPR algorithm to predict energy consumption in the FDM process with high accuracy.

Conclusions
In this research, twelve machine learning algorithms are used to model and predict energy consumption in the FDM process using a database of the FDM 3D printing of isovolumetric mechanical components (r3DIM benchmark). The most effective model is chosen based on four performance criteria: mean absolute error (MAE), root mean squared error (RMSE), R-squared (R2), and explained variance score (EVS). The GPR model outperformed these models with a high degree of accuracy and had the following performances: 99.16% as the value of explained variance and 99.14% for R-squared; the respective values of MAE and RMSE are 3.88 and 5.79, respectively. With our model, before each printing, we will be able to predict the printing energy according to different part orientations, and after the comparison between the predicted energies, we can decide the best orientation to use to minimize energy use in the printing phase.