You are on page 1of 20

sensors

Article
Diagnosis of Operating Conditions of the Electrical
Submersible Pump via Machine Learning
Jéssica Brasil 1 , Carla Maitelli 2, *, João Nascimento 3 , Osvaldo Chiavone-Filho 1 and Edney Galvão 2

1 Department of Chemical Engineering (DEQ), Federal University of Rio Grande do Norte (UFRN),
Natal 59078-970, Brazil
2 Department of Petroleum Engineering (DPET), Federal University of Rio Grande do Norte (UFRN),
Natal 59078-970, Brazil
3 Federal Institute of Education, Science and Technology of Rio Grande do Norte (IFRN),
Parnamirim 59143-455, Brazil
* Correspondence: carla.maitelli@ufrn.br

Abstract: In wells that operate by electrical submersible pump (ESP), the use of automation tools
becomes essential in the interpretation of data. However, the fact that the wells work with automated
systems does not guarantee the early diagnosis of operating conditions. The analysis of amperimetric
charts is one of the ways to identify fail conditions. Generally, the analysis of these histographics is
performed by operators who are often overloaded, generating a decrease in the efficiency of observing
the well operating conditions. Currently, technologies based on machine learning (ML) algorithms
create solutions to early diagnose abnormalities in the well’s operation. Thus, this work aims to
provide a proposal for detecting the operating conditions of the ESP pump from electrical current data
from 24 wells in the city of Mossoró, Rio Grande do Norte state, Brazil. The algorithms used were
Decision Tree, Support Vector Machine, K-Nearest Neighbor and Neural Network. The algorithms
were tested without and with hyperparameter tuning based on a training dataset. The results confirm
that the application of the ML algorithm is feasible for classifying the operating conditions of the ESP
pump, as all had an accuracy greater than 87%, with the best result being the application of the SVM
model, which reached an accuracy of 93%.

Keywords: artificial lift; electrical submersible pump; machine learning; classification algorithms

Citation: Brasil, J.; Maitelli, C.;


Nascimento, J.; Chiavone-Filho, O.;
Galvão, E. Diagnosis of Operating 1. Introduction
Conditions of the Electrical
Over the decades, the production system has been modified due to population growth
Submersible Pump via Machine
and the growing demand for inputs that provide longevity and quality to the life of the
Learning. Sensors 2023, 23, 279.
planet’s inhabitants. Sectors such as telecommunications, health, and transport have
https://doi.org/10.3390/s23010279
benefited significantly and quickly through the use of technologies that connect more and
Received: 17 August 2022 more people. Moreover, it can help in the agility of decision-making in corporate groups.
Revised: 14 October 2022 The notoriety in the use of techniques and topics related to Industry 4.0 is gaining
Accepted: 25 October 2022 more prominence in the oil and gas sector. This sector has witnessed great advances due
Published: 27 December 2022 to the adoption of the concepts and technologies of the digital field. These technologies
empower oil and gas facilities with detection equipment to enable real-time monitoring
of wells and other assets in an oil field. The existence of such tools with digital world
Copyright: © 2022 by the authors.
connection is essential for the industry [1].
Licensee MDPI, Basel, Switzerland. In artificial lift, the use of electrical submersible pump (ESP) has been growing in the
This article is an open access article oil industry as it is an effective and economical method. This artificial lift method helps to
distributed under the terms and maximize the production of recoverable oil, achieving higher withdrawals and handling of
conditions of the Creative Commons a greater volume of fluid [2]. The lifespan of the ESP is affected by repeated shutdowns.
Attribution (CC BY) license (https:// These sudden failures can be generated by poor management and design conditions not
creativecommons.org/licenses/by/ being specific to the artificial lift system [3].
4.0/).

Sensors 2023, 23, 279. https://doi.org/10.3390/s23010279 https://www.mdpi.com/journal/sensors


Sensors 2022, 22, x FOR PEER REVIEW 2 of 20

Sensors 2023, 23, 279 2 of 19


These sudden failures can be generated by poor management and design conditions not
being specific to the artificial lift system [3].
The ESP system comprises the electric motor, protector, gas separator or intake,
multi-stage
The ESPcentrifugal pump, power
system comprises cable, motor,
the electric motor, protector,
transformer, gasand a reliable
separator power
or intake,
source. Downhole
multi-stage sensors
centrifugal or gauges
pump, power arecable,
installed to monitor
motor, the well
transformer, andanda pump
reliableoperating
power
conditions
source. [4].
Downhole sensors or gauges are installed to monitor the well and pump operating
The electric motor is of the three-phase type and works with an alternating electric
conditions [4].
current.
The The motor
electric is driven
motor from
is of the the electrical
three-phase typecable
andthatworksleaves
withtheansurface to theelectric
alternating bottom
of the production column, where the motor is positioned. The protector allows
current. The motor is driven from the electrical cable that leaves the surface to the the con-
bottom of
traction
the and expansion
production column, where of thethe
engine’s
motor insulating
is positioned.oil, The
ensuring no contamination
protector by well
allows the contraction
and expansion of the engine’s insulating oil, ensuring no contamination
fluid. The gas separator ensures that fluid enters the pump’s first stage and removes small by well fluid. The
gas separator ensures that fluid enters the pump’s first stage and removes
amounts of gas. The multistage pump is responsible for pumping the fluids. The wellhead small amounts
of gas. The
ensures themultistage
passage of pump is responsible
the electrical cablefor topumping
the bottom the of
fluids. The wellhead
the well and supports ensuresthe
the passage of the electrical cable to the bottom of the well and supports
weight of the string. The junction box connects the surface and bottom cables. The switch- the weight of the
string.
board The junction
contains loadbox connectsand
protection thecontrol
surfaceequipment
and bottom[5]. cables.
This The switchboard
system can be seen contains
in Fig-
load protection
ure 1. and control equipment [5]. This system can be seen in Figure 1.

Figure1.1.Onshore
Figure OnshoreESP
ESPsystem
system[6].
[6].

TheESP
The ESPsystems
systemscancanbebeinstalled
installedininurban
urban areas
areas andand
thethe most
most equipment
equipment of the
of the ESPESPis
is the
in in the subsurface;
subsurface; takes
takes up little
up little space,space,
so itso
is it is very
very suitable
suitable for offshore
for offshore environments.
environments. It is
It is ideal
ideal for highfor high
flow flow
ratesrates of liquid,
of liquid, requiring
requiring low maintenance.
low maintenance. It canIt be
canused
be used in devi-
in deviated
ated wells,
wells, and corrosion
and corrosion and fouling
and fouling treatments
treatments are relatively
are relatively easy toeasy to out
carry carry
[7].out [7].
TheESP
The ESPsystem
systempump
pumphas hasits
itsperformance
performancedegraded
degradedin inthe
thepresence
presenceof ofcompressible
compressible
gas. If
gas. If the
the pump
pump isis operating
operating on on free
freegas,
gas,head
headdeterioration,
deterioration,decreased
decreasedefficiency
efficiencyand and
evengas
even gaslocking
lockingcan
cancause
causethe
theproduction
productionsystemsystemto tostop
stopand
andshorten
shortenthe thelife
lifeofofdownhole
downhole
equipment. Environments
equipment. Environments that
that have
have their
their production
production affected
affected by
by issues
issues such
such as as gas
gas high-
high-
volume wells, produced solids, high temperature and corrosive environments often lead
to multiple incidents of failure in ESP systems. This results in production losses and high
operating costs, requiring workover [8].
Sensors 2023, 23, 279 3 of 19

Despite the natural separation in the annular space or the operation of a gas separator,
the gas can eventually reach the pump, which will cause a significant reduction in its
efficiency [9]. In addition, slight cyclical changes in the motor load and electric current
arise in the pump, which significantly damages the ESP unit. Frequent system shutdowns
and restarts eventually damage the motor and the entire installation run; pump life is
severely reduced.
It is important to note that the gas inside the pump may be present in low or high
amounts. If the gas volume is considered low, the system is not harmed. Often the amount
of gas is so low that experts consider the operation to be normal gas operation. If the
amount of gas is high, gas interference can occur, which significantly reduces the pump
efficiency or gas locking that can interrupt the production of the well and, consequently,
the pump cannot drain the fluid inside it.
According to this whole context, the general objective of this work is to use a Machine
Learning (ML) classification algorithm to diagnose four operating conditions: normal
operation, normal operation with gas, gas interference and gas locking of the ESP pump.
This work has as its main motivation, the growing area of machine learning that will
provide great changes in the industrial sector. In addition, ESP is an important method for
artificial lift because it works with high liquid flow rates.
The ML algorithms used were Decision Tree, Support Vector Machine (SVM), K-
Nearest Neighbor (KNN) and Multi-Layer Perceptron (MLP) neural network using the
Python programming language in the Google Colaboratory® (Google Colab) environment.
For the operational diagnosis, real data from 24 wells that operate by electrical submersible
pump in the region of Mossoró/RN, Brazil were used, the variable used in these wells was
the electric current in a period of 24 h. The electric currents were classified by specialists in
the oil area and distributed in the four operating conditions mentioned above.
The tests carried out in the present work used ML algorithms, with and without hy-
perparameter tuning, with application of an algorithm for unbalanced data and evaluation
metrics. The complexity of this work is based on the similarity of the gas operation and
gas interference charts, the difference between them is the range of the electric current.
This situation causes difficulties in interpreting the algorithms. Despite this, the results
of this research show that the ML algorithms used in this work were able to identify the
four operating conditions of the ESP pump. The diagnostics obtained will be useful to
identify the causes of the failures and, consequently, the field engineers will be able to
apply effective solutions.

2. Theoretical Background
In this section, the concepts of machine learning classification algorithms that were
used in this article will be discussed. Parameters that were used to improve the performance
of the classification algorithms and the metric evaluated to observe how the algorithms
behaved will be highlighted.

2.1. Classification Algorithms


In this work, supervised learning by the classification method was applied, as the clas-
sification task predicts discrete responses. It is recommended that data can be categorized,
labeled or separated into specific groups or classes. Classification models identify input
data into categories. In this article, the classification algorithms used were the Decision Tree,
KNN, SVM and Multi-Layer Perceptron Neural Network (MLP) for comparison purposes,
since they are different classification methods.
The Decision Tree (DT) algorithms are most commonly used in classification, as it is a
technique that provides easily understandable modeling and simplifies the classification
process [10]. The Decision Tree is a transparent mechanism that makes it easy for users to
follow a tree structure to see how the decision is made. The central objective of the tree is to
produce a model that calculates the value of a required variable based on numerous input
variables [11].
Sensors 2023, 23, 279 4 of 19

Another well-known classification algorithm is the K-Nearest Neighbor (KNN), which


classifies unlabeled observations, assigning them to the class of the most similar labeled
examples. The characteristics of the observations are collected for the training and testing
datasets [12]. An important concept that must be realized when applying KNN is the
k-value relationship. To identify how many nearest neighbors there are around an analyzed
sample, the value of k is measured. KNN assigns the label class to most of the closest
K patterns in the data space [13].
The Support Vector Machine (SVM) was proposed by mathematician Vladimir Vapnik
and it is based on a statistical theory of learning. SVM is considered one of the most
prominent and convenient techniques to solve problems related to data classification [14]
learning and prediction [15]. The classification performed in the SVM algorithm transforms
the original training data into multidimensional data [16]. This classification technique
employs the data vectors of a hyperplane in a huge dimensional space [17].
Finally, the Neural Network (NN) system consists of a series of interconnected pro-
cessing elements, commonly called neurons. NNs receive information as inputs on one
side and provide outputs on the other side using unidirectional connections between neu-
rons in different layers [18]. The neural network Multi-Layer Perceptron (MLP) type has
more than one perceptron, established in different layers. This makes it capable of solving
non-linear problems.
Generally speaking, the applications of MLP’s are categorized as pattern classification,
data prediction and function approximation. Pattern classification implies classifying
data into predefined discrete classes, while forecasting refers to predicting future trends
according to electric current and past data [19].

2.2. Classification Parameters


Classification parameters are techniques used for machine learning algorithms to
be more assertive in their results. In this work, hyperparameters and the data balancing
technique were used. In addition, the confusion matrix was applied to visualize the results,
which also helped in the analysis of the results of the algorithms.

2.2.1. Hyperparameter Tuning


Hyperparameters are essential for ML algorithms. For a set of training algorithms,
with different hyperparameters, an ML algorithm can obtain models with significantly
different performance from the test dataset [20]. Hyperparameters will help to increase the
assertiveness of ML algorithms, the most common techniques for adjusting models with
hyperparameters are Grid Search and Random Search [21].
One of the hyperparameter techniques that helps in greater assertiveness is the Grid
Search, which divides the domain of hyperparameters into a discrete grid. Then, all
combinations of values from this grid are tested, calculating some performance metrics
using cross-validation [22]. The grid point that maximizes the average value in cross-
validation is the optimal combination of values for the hyperparameters. The exposed
methodology was used in this research.

2.2.2. Unbalanced Dataset


Unbalanced datasets in ML result in data classification problems as the data is rep-
resented in an unequal way. In many real-world applications, the nature of the problem
implies sometimes significant deviation in the class distribution of a binary or multiclass
classification problem [23].
There are data-level methods that manipulate the training data, aiming to change the
distribution of classes to a more balanced one. Techniques in this category add instances to
minority classes through duplication or generation of new samples (oversampling) [24].
Oversampling replicates the minority class data until it is numerically equal to the
majority class data [25]. In this work, due to the difference in distribution between the
classification problem [23].
There are data-level methods that manipulate the training data, aiming to change the
distribution of classes to a more balanced one. Techniques in this category add instances
to minority classes through duplication or generation of new samples (oversampling) [24].
Sensors 2023, 23, 279 Oversampling replicates the minority class data until it is numerically equal to
5 ofthe
19
majority class data [25]. In this work, due to the difference in distribution between the
operating conditions, the oversampling technique was used, which randomly duplicates
instances of
operating minority the
conditions, classes to obtain a technique
oversampling more balanced data distribution.
was used, which randomly duplicates
instances of minority classes to obtain a more balanced data distribution.
2.2.3. Confusion Matrix
2.2.3. The
Confusion Matrix
confusion matrix is a very popular measure used in solving classification prob-
lems.The
It can be applied
confusion matrixtoisbinary classification
a very popular andused
measure to multiclass
in solving classification problems
classification problems.
It[26].
canAn example of a confusion matrix for binary classification (2 × 2) is shown in
be applied to binary classification and to multiclass classification problems Figure
[26]. An
2.
example of a confusion matrix for binary classification (2 × 2) is shown in Figure 2.

Figure2.
Figure 2. Confusion
Confusion matrix
matrix for
for binary
binaryclassification
classificationproblems
problems(adapted
(adaptedfrom
from[27]).
[27]).

The “TN”
The “TN” output
output shows
shows the
the number
number of of accurately
accurately classified
classified negative
negative examples.
examples. Like-
Like-
wise,“TP”
wise, “TP” indicates
indicates the
the number
number of of accurately
accurately classified
classified positive
positive examples.
examples. The
The term
term “FP”
“FP”
shows aa false
shows false positive
positive value,
value, that
that is,
is, the
the number
number ofof real
real negative
negative examples
examples classified
classified as
as
positive; and
positive; and “FN”
“FN” isis characterized
characterizedby bythethenumber
numberofofrealrealpositive
positiveexamples
examplesclassified as
classified
negative. One of the most commonly used metrics when performing classification is pre-
as negative. One of the most commonly used metrics when performing classification is
cision. TheThe
precision. precision
precisionof of
a model
a model(via
(viaa aconfusion
confusionmatrix)
matrix)isiscalculated
calculated using
using Equation (1).
Precision isis the
Precision thepositive
positivecases
casescorrectly
correctlypredicted
predictedbybythe
theclassifier.
classifier.
TPTP (1)
𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛
precision = = TP + FP (1)
TP + FP
The recall metric is defined as the number of accurately ranked positives (TP) divided
The recall metric is defined as the number of accurately ranked positives (TP) divided
by the totalnumber
by the total numberofofpredictions
predictionsthat
thatare
areactually
actually correct.
correct. TheThe accuracy
accuracy of of
anan algorithm
algorithm is
is represented as the sum of positive predictions (TP + TN) by the total number
represented as the sum of positive predictions (TP + TN) by the total number of predictions of predic-
tions
(TP + (TP
TN ++ TN
FP ++ FN).
FP + FN). Equations
Equations (2) (3)
(2) and andshow
(3) show
howhow the metrics
the metrics of recall
of recall and and accu-
accuracy
racycalculated.
are are calculated.
TPTP
recall = (2)
(2)
𝑟𝑒𝑐𝑎𝑙𝑙 = TP + FN
TP + FN
TPTP+ TN
+ TN
accuracy = (3)
𝑎𝑐𝑐𝑢𝑟𝑎𝑐𝑦 TP = + TN + FP + FN (3)
TP + TN + FP + FN
Another metric that can be mentioned when mentioning the confusion matrix is the
Another metric that can be mentioned when mentioning the confusion matrix is the
F1-score, which is the harmonic mean of precision and recall, as seen in Equation (4). All
F1-score, which is the harmonic mean of precision and recall, as seen in Equation (4). All
these parameters were calculated in the work in question.
these parameters were calculated in the work in question.
2 [( precision)(recall )]
F1𝐹score
𝑠𝑐𝑜𝑟𝑒= = 2 [(𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛)(𝑟𝑒𝑐𝑎𝑙𝑙)] (4)
(4)
precision + recall
𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 + 𝑟𝑒𝑐𝑎𝑙𝑙
3. Methodology
3. Methodology
In this paper, the ML classification was divided into six steps: problem identification,
In this paper,
data obtaining, datathe ML classification
exploration, was dividedalgorithm
data preparation, into six steps: problem
selection identification,
and model valida-
data Initially,
tion. obtaining, data
it is exploration,
very important data
in ML preparation, algorithm
classification selection
to identify andofmodel
the focus valida-
the problem
tion.
to Initially, the
determine it isfeasibility
very important
of theinprocedure.
ML classification to identify
The second step the
wasfocus of thethe
to obtain problem
data.
Subsequently, the exploration and preparation of the data were carried out so that, finally,
the algorithm selected for this problem could be used. The last step of this classification
process (model validation) was to analyze whether the results obtained were consistent
from the validation of metrics. The steps mentioned are shown in Figure 3 [28].
to determine the feasibility of the procedure. The second step was to obtain the data. Sub-
to determine the feasibility of the procedure. The second step was to obtain the data. Sub-
sequently, the exploration and preparation of the data were carried out so that, finally, the
sequently, the exploration and preparation of the data were carried out so that, finally, the
algorithm selected for this problem could be used. The last step of this classification pro-
Sensors 2023, 23, 279 algorithm selected for this problem could be used. The last step of this classification 6pro-
of 19
cess (model validation) was to analyze whether the results obtained were consistent from
cess (model validation) was to analyze whether the results obtained were consistent from
the validation of metrics. The steps mentioned are shown in Figure 3 [28].
the validation of metrics. The steps mentioned are shown in Figure 3 [28].

Figure 3. Common steps


Figure for trying steps
Common
3. Common out a for
machine learning
tryingout project.learning
outaa machine
machine These steps were
project. usedsteps
These in the
wereused
usedin
inthe
the
Figure 3. steps for trying learning project. These steps were
development ofdevelopment
this work (adapted from [28]).
development of ofthis
thiswork
work(adapted
(adaptedfrom
from[28]).
[28]).

3.1. Obtaining Data


3.1. Obtaining Data
3.1. Obtaining Data
The second step Theinsecond
ML experimentation is getting the is
step in ML experimentation data. In this
getting thestep,
data.it In
is this
verystep, it is very
The second step in ML experimentation is getting the data. In this step, it is very
important to identify
importantwhere the datawhere
to identify is being
thecollected.
data is being In addition,
collected.the Incorrect choice
addition, of
the correct choice of
important to identify where the data is is paramount.
being collected. In case,
addition, the correct choice of®
interface used for data manipulation is paramount. In this case, the Google Colaboratory
interface used for data manipulation In this the Google ®Colaboratory
interface used for data was
manipulation isthe
paramount. In this case, thethese
Google Colaboratory ®
(Colab) environment
(Colab)was used with the used
environment Python
withlanguage. After
Python these steps,
language. Afterthe manual steps, the manual
(Colab) environment was used with
the the
helpPython language. After these steps, the manual
classification process beganprocess
classification with thebegan
help of specialists.
with of specialists.
classification
This workprocess began
analyzedofthe with the help of specialists.
This work analyzed the behavior 24 behavior of 24 wells
wells in Mossoró, RN,in Brazil,
Mossoró, RN, Brazil,
however, 4 werehowever, 4 were
This work analyzed the behavior of 24 wellsThe
in Mossoró, RN, was
Brazil, however, 4 were
discarded due to continuous motor shutdown. The classification was given from 20 wells from 20 wells
discarded due to continuous motor shutdown. classification given
discarded due
fourtotypes
continuous motorconditions
shutdown.(Figure
The classification was given from 20 wells
to identify fourtotypes
identify
of operating of operating
conditions (Figure 4): 4):
to identify four types of operating conditions (Figure 4):
i. i.
Normal Operation; Normal Operation;
i. ii. Normal
Normal Operation; with Gas;
ii. Normal Operation withOperation
Gas;
ii. iii. Normal Operation with Gas;
Gas Interference;
iii. Gas Interference;
iii. iv. GasGasInterference;
locking.
iv. Gas locking.
iv. Gas locking.

Figure 4. Classification scheme


Figure4.4. and manual
Classification selection
scheme of electric
andmanual
manual current
selection data used
ofelectric
electric in thisdata
current work.
used in
in this
this work.
work.
Figure Classification scheme and selection of current data used

The operatingThe
conditions
operatingchosen were based
conditions chosenonwere
the gas variation
based on the within the ESP
gas variation within the ESP
The operating conditions chosen were based on the gas variation within the ESP
pump. The normal
pump.operation is theoperation
The normal standardiscondition for ESP
the standard systems.
condition forNormal operation
ESP systems. Normal operation
pump. The normal operation is the standard condition for ESP systems. Normal operation
with gas was employed in this
with gas was research,
employed in because the most
this research, ESP wells
because work
the most with
ESP a small
wells work with a small
with gas was employed in this research, because the most ESP wells work with a small
amount of gas inside the pump, but continue to work normally. To visualize more extreme
conditions that could cause possible future pump stoppages, it was decided to work with
gas interference and gas locking.
The identification was performed as follows: the dataset of the 20 wells were analyzed
for 30 days and the specialist scanned these wells using an algorithm implemented in
Python language. First, an algorithm was carried out to read the datasets of the 20 wells.
amount of gas inside the pump, but continue to work normally. To visualize more extreme
amount of gas inside the pump, but continue to work normally. To visualize more extreme
conditions that could cause possible future pump stoppages, it was decided to work with
conditions that could cause possible future pump stoppages, it was decided to work with
gas interference and gas locking.
gas interference and gas locking.
The identification was performed as follows: the dataset of the 20 wells were ana-
The identification was performed as follows: the dataset of the 20 wells were ana-
lyzed for 30 days and the specialist scanned these wells using an algorithm implemented
lyzed for 30 days and the specialist scanned these wells using an algorithm implemented
Sensors 2023, 23, 279 in Python language. First, an algorithm was carried out to read the datasets of the 20 7wells. of 19
in Python language. First, an algorithm was carried out to read the datasets of the 20 wells.
After that, the specialist identified which well he wanted to analyze, and observed when
After that, the specialist identified which well he wanted to analyze, and observed when
the phenomenon began (day and time) and when it ended.
the phenomenon began (day and time) and when it ended.
After The
that,developed
the specialistalgorithm showed
identified whichthe graph
well of electric
he wanted current versus
to analyze, time of when
and observed a well
The developed algorithm showed the graph of electric current versus time of a well
for phenomenon
the 30 days and itbegan
was possible
(day and to time)
selectand
whichwhen timeit interval
ended. some operating condition was
for 30 days and it was possible to select which time interval some operating condition was
seen.The
To developed
maintain a algorithm
standard ofshowed
identification
the graph of operating
of electricconditions,
current versus 24 h time
stretches were
of a well
seen. To maintain a standard of identification of operating conditions, 24 h stretches were
selected.
for 30 daysThe andfour operating
it was possibleconditions obtained
to select which timewere trained
interval someon a test dataset,
operating using
condition wasan
selected. The four operating conditions obtained were trained on a test24 dataset, usingwere
an
ML algorithm.
seen. To maintain a standard of identification of operating conditions, h stretches
ML algorithm.
TheThe
selected. electric
fourcurrent
operating versus time graph
conditions of thewere
obtained normal operating
trained condition
on a test dataset,isusing
smooth,
an
The electric current versus time graph of the normal operating condition is smooth,
however,
ML this condition may produce a curve slightly above or below the ideal amperage
algorithm.
however, this condition may produce agraph
curveof slightly aboveoperating
or below condition
the ideal amperage
of this
Theoperation,
electric but thisversus
current generated
timedeviation from
the the curve
normal does not prevent is the system
smooth,
ofhowever,
this operation, but this generated deviation from the curve does not prevent the system
from working properly.may
this condition According
producetoaengineers in theabove
curve slightly area,orto below
classify normal
the ideal operation,
amperage
from working properly. According to engineersfrom in thethearea, todoes
classify
not normal operation,
a constant
of this patternbut
operation, of this
electric currentdeviation
generated over time or peaks with variation
curve of up to the
prevent 1 A system
(Figure
afrom
constant pattern of electric current over time or peaks with variation of up to 1 A (Figurea
5) was observed, which is considered a well with practically no electric current fluctua-
working properly. According to engineers in the area, to classify normal operation,
5)constant
was observed, which is considered a well with practically no electric current fluctua-
tions. pattern of electric current over time or peaks with variation of up to 1 A (Figure 5)
tions.
was observed, which is considered a well with practically no electric current fluctuations.

Figure5.5.Example
Figure Exampleof
ofaareal
realwell
welloperating
operatingnormally
normallyfor
for24
24h.h.
Figure 5. Example of a real well operating normally for 24 h.
Normalgas
Normal gasoperation
operationwaswasstudied
studiedasasititisisaastriking
strikingfeature
featurein
inthe
thewells
wellsanalyzed
analyzedinin
Normal gas operation was studied as it is a striking feature in the wells analyzed in
thiswork.
this work.Therefore,
Therefore,according
accordingto toengineers
engineersin inthe
thearea,
area,for
forwells
wellswith
withnormal
normaloperation
operation
this work. Therefore, according to engineers in the area, for wells with normal operation
withgas,
with gas,reference
referencestandards
standardsfor forelectrical
electricalcurrent
currentranging
rangingfrom
from11AAtoto55A.
A.This
Thiscondition
condition
with gas, reference standards for electrical current ranging from 1 A to 5 A. This condition
ofofthe
thepump
pumpoperating
operatingwith
with aalow
lowamount
amount of ofgasgasdoes
doesnotnotaffect
affectthe
theproduction
production system,
system,
ofand
the pump operatingis with a low amount of6gas does not example
affect the production system,
andthe
thewell
welldisarm
disarm isnot
nottriggered.
triggered.Figure
Figure 6presents
presentsan an exampleof ofaadataset
datasetof
ofnormal
normal
and the wellwith
disarm is notintriggered. Figure 6 presents an example of a dataset of normal
operation with gas used in the work.
operation gas used the work.
operation with gas used in the work.

Figure6.6.Example
Figure Exampleof
ofaareal
realwell
welloperating
operatingwith
withgas
gasfor
for24
24h.h.
Figure 6. Example of a real well operating with gas for 24 h.
Gas interference (Figure 7) causes instability in pump operation, generating significant
fluctuations in electric current. So, it is important to have an early diagnosis of what
is happening in the system. It was considered for this paper, based in real wells, that
ESP operations that had the variation of electric current above 5 A, would be considered
gas interference.
Gas interference (Figure 7) causes instability in pump operation, generating signifi-
cant Gas
fluctuations in electric
interference (Figurecurrent. So, instability
7) causes it is important to have
in pump an earlygenerating
operation, diagnosis of what
signifi-
is happening
cant in the
fluctuations system.current.
in electric It was considered for this paper,
So, it is important to havebased in real
an early wells, that
diagnosis ESP
of what
operations
is happeningthat
in had the variation
the system. It wasof electric current
considered for thisabove
paper,5 based
A, would be wells,
in real considered gas
that ESP
Sensors 2023, 23, 279 8 of 19
interference.
operations that had the variation of electric current above 5 A, would be considered gas
interference.

Figure 7. Example of a real well with gas interference for 24 h.


Figure 7. Example of a real well with gas interference for 24 h.
Figure 7. Example of a real well with gas interference for 24 h.
In the gas lock condition, characteristic illustrated in Figure 8, the electric current has
In the gas lock condition, characteristic illustrated in Figure 8, the electric current has
a veryIn peculiar
a very peculiar characteristic.
the gascharacteristic.
lock condition, Initially,
thethe
characteristic
Initially, electric
illustrated
electric current
current is constant
inisFigure
constant8, the
untiluntil
the the
electric beginning
current
beginning has
of
of
a a
verygas interference
peculiar is visualized.
characteristic. The
Initially, gas
the amount
electric increases,
current is and
constant
a gas interference is visualized. The gas amount increases, and it became so high that the it became
until the so high that
beginning
thea system
of
system stops,
gasstops, causing
interference
causing isthe the system
visualized.
system toThe togas
disarm.
disarm. As itAs
amount is it is a very
aincreases,
very extreme
and
extreme fault,
itfault, it is it
became so ishigh
not not
easyeasy
that
to
to
theobtain
system from real
stops, well
causing data.
the Therefore,
system to in the
disarm. data
As from
it is a the
very 20 analyzed
extreme
obtain from real well data. Therefore, in the data from the 20 analyzed wells, it was not wells,
fault, it it
is was
not not
easy
possible
to obtaintoto
possible identify
from thisproblem.
real this
identify well problem.
data. However,
Therefore,
However, asasitdata
in the itwas
was necessary
from toobtain
obtaindata
the 20toanalyzed
necessary data
wells, for
for training
ittraining
was not
and tests,
possible todatasets
identify from
this simulated
problem. wells
However, wereas used,
it was based on
necessary
and tests, datasets from simulated wells were used, based on reference [29]. reference
to obtain [29].
data for training
and tests, datasets from simulated wells were used, based on reference [29].

Figure 8. Example of a simulated 24 h gas locking well.


Figure 8. Example of a simulated 24 h gas locking well.
Figure 8. Exploration
3.2. Data Example of a simulated 24 h gas locking well.
3.2. Data Exploration
Exploring the data means doing a thorough analysis of every dataset obtained. There-
3.2. Data Exploration
Exploring the data
fore, after classifying themeans
expert,doing a thorough
the data analysisanalysis of every
in this work was dataset
basedobtained.
on viewingThere-
all
datasets collected by the expert and separating them for each operating condition within all
fore, after classifying
Exploring the data the expert,
means the
doing adata analysis
thorough in this
analysis ofwork was
every based
dataset on viewing
obtained. There-a
datasets
fore,
24 aftercollected
h interval. classifyingby the expert
expert,and
the separating
data analysis them for each
in this workoperating
was based condition within
on viewing all
a 24Ash interval.
datasets collected by
previously the expert
stated, the gasand separating
locking them for each
phenomenon operating
was not found condition within
in the wells, so
a 24
50 hAs previously
interval.
datasets stated, the
were simulated gas locking
so that phenomenon
the algorithm had datawasavailable
not foundto in the wells,
perform the so
ML 50
datasets
algorithm were
tests. simulated
As previously Tablestated, sothe
1 shows that
the the
gas algorithm
locking
distribution ofhad
phenomenondata available
operatingwas to perform
not found
conditions thethe
thatinwill ML so
wells,
be used algo-
for50
rithm tests.
datasets
training inwere Table
this 1 shows
simulated
work, the
so that
in total distribution
therethewere
algorithm of had
operating
179 datasets. conditions
data available that willthe
to perform beML
used for
algo-
training
rithm in this
tests. work,
Table in total
1 shows thethere were 179ofdatasets.
distribution operating conditions that will be used for
training
Table in this work,
1. Distribution in total there
of operating were 179 datasets.
conditions.

Types of Operating Conditions Number of Events in the Collected Data


1—Normal Operation with Gas 28
2—Gas Interference 20
3—Normal Operation 83
4—Gas Locking 50
Sensors 2023, 23, 279 9 of 19

3.3. Data Preparation


In data preparation, the information in the dataset is verified, that is, adjustments are
made at this stage so that the quality of the model is not compromised. Some examples of
adjustments are normalizations, standardizations, exclusion of outliers, among others. In
addition, it is also at this stage that there is a separation of data into training and testing.
The data preparation carried out in this work was initially based on the exclusion of some
data from the wells, as there were long periods of pump downtime. Then, the data were
interpolated so that they had the same number of points. Finally, the data were separated
into training and testing.

3.3.1. Linear Interpolation


Linear interpolation is a useful technique for fitting curves using linear polynomials.
One method for estimating the value of a function between any two known values is called
interpolation—Equation (5). In a given interval where there is a set of existing points, new
points are created so that there are more points on a curve.

( x − x1 )(y2 − y1 )
y = y1 + (5)
x2 − x1

where x1 and y1 are the first coordinates; x2 and y2 are the second coordinates; x is the
point to perform the interpolation and y the interpolated value. This formula is using
coordinates of two given values to find the best fit curve as a straight line. So, this will give
you whatever value of y is needed at a known value of x.
A standardization was applied in this work in order to leave all data with the same
number of points. The dataset ranged from 159 to 344 points, as the largest dataset had
344 points, all other datasets were adjusted to this amount. This is necessary, so that the
datasets have the same pattern. After standardization, the scale for each graph was from
0 to 75 A following [29].

3.3.2. Test and Training Set


Before selecting the algorithm, it is very important to separate the data into test and
training sets. The test set is the one that will be used as a basis for training the well data
and its proportion is much smaller than the training set. In the data mining area, generally,
70% of the data are used for training and 30% for testing [30]. The proportion of 70–30 was
the same applied in this work. Of the 179 datasets, 125 were defined as training and 54 as
testing. Table 2 shows the organization of training and testing data, based on the datasets
in Table 1.

Table 2. Distribution of testing and training data.

Types of Operating Conditions Test Data Training Data


1—Normal Operation with Gas 6 22
2—Gas Interference 5 13
3—Normal Operation 30 53
4—Gas Locking 13 37

3.4. Algorithm Selection


At the stage of algorithm selection, initially, no adjustment or manipulation was
performed to improve the performance of the algorithm. Furthermore, in this work,
algorithms with an increasing order of complexity were applied. The initial algorithms were
executed without hyperparameter tuning or balanced data. After this test, hyperparameter
tuning (Grid Search) and data balancing were applied, using the oversampling technique
in the algorithms.
In the work in question, the order of choices of the algorithms was in order of com-
plexity, the first to be tested was the Decision Tree (DT), then K-Nearest Neighbor (KNN),
Sensors 2023, 23, 279 10 of 19

Support Vector Machine (SVM) and the Multi-Layer Perceptron (MLP) Neural Network.
The choice of this set of algorithms, specifically, was in order to evaluate the distinct charac-
teristics that each one can offer for this work. All models had hyperparameter conditions
(Grid Search) evaluated. The hyperparameters implemented for each model are shown in
Table 3.

Table 3. Hyperparameters of each model based on the scikit learn library.

Method Hyperparameters Conditions


Criterion Gini and Entropy
Splitter Best and Random
DT Min_samples_leaf {1; 2; 3; 4}
Min_samples_split {2; 3; 4}
Max_leaf_nodes {2 the 100}
Metrics Euclidean and Manhattan
Neighbors {1 the 16}
KNN
Weights Uniform, Distance and Callable
Algorithm
C {0.1; 1; 10; 100; 1000}
SVM Gamma {1; 0.1; 0.01; 0.001; 0.0001}
Kernel rbf
Activation Tanh and Relu
Alpha {0.0001; 0.05}
Hidden_layer_sizes {(50; 50; 50), (50; 100; 50), (100,)}
NN
Constant, Adaptive and
Learning_rate
Invscaling
Learning_rate_init {0.0001; 0.05}
Solver Sgd and Adam

In DT, the studied hyperparameters were: the function to measure the quality of a
split in the tree (Criterion), strategy to choose the split of each node (Splitter), the minimum
number of samples needed to be in a leaf node (Min_samples_leaf), the minimum number
of samples needed to split an internal node (Min_samples_split) and the parameter to
identify if there are any nodes with any faults or impurity (Max_leaf_nodes).
In KNN, the hyperparameters used were the Euclidean and Manhattan metrics
(Metrics), the number of near neighbors used by default (Neighbors), the weight func-
tion used in the prediction (Weights), and the algorithm used to calculate the nearest
neighbors (Algorithm). In SVM, the metrics studied were the regularization parameter
(“C”), the kernel that specifies the type of kernel to be used in the algorithm and the
coefficient applied to the kernel (gamma).
In the Neural Network, the activation function was applied to the hidden layer
(Activation), the penalty parameter (Alpha), the Hidden_layer_sizes that represents the
number of neurons of the hidden layer, the activation function to the hidden layer (Activation),
the learning rate schedule for weight updates (Learning_rate), the initial learning rate used
(Learning_rate_init), and the solver for weight optimization (Solver).
After the hyperparameter tuning step, the datasets had their data balanced by the
random oversampling technique. This technique was used due to the duplication of the
minority class examples in the training dataset. Thus, all datasets were adjusted to 53 train
set according to the majority class of training data. The data were adjusted to this value, as
it was the largest number of datasets obtained by the training set algorithm, so all should
have the same amount of data.

4. Results
In the following topics, the results of this research will be exposed. The analysis of
the metrics of the results will be carried out by applying hyperparameters, in addition to
observing the behavior of unbalanced and balanced data for each chosen algorithm.
should have the same amount of data.

4. Results
In the following topics, the results of this research will be exposed. The analysis of
Sensors 2023, 23, 279 the metrics of the results will be carried out by applying hyperparameters, in addition
11 of to
19
observing the behavior of unbalanced and balanced data for each chosen algorithm.

4.1. Decision
4.1. Decision Tree
Tree (DT)
(DT)
Based on
Based on the
the scikit-learn
scikit-learn library, the Decision
library, the Decision Tree model was
Tree model was trained
trained with
with the
the Deci-
Deci-
sionTreeClassifier function. This tree model is the simplest to interpret.
sionTreeClassifier function. This tree model is the simplest to interpret. In the tests of In the tests of this
this
model, three algorithms were implemented, the first without hyperparameter
model, three algorithms were implemented, the first without hyperparameter tuning and tuning and
unbalanced data,
unbalanced data,aasecond
secondwith
with hyperparameter
hyperparameter tuning
tuning andand unbalanced
unbalanced data data
and theandthird
the
thirdhyperparameter
with with hyperparameter tuningtuning and balanced
and balanced data. data.
When applied
When appliedto tothe
theDecision
DecisionTree
Treealgorithm,
algorithm, it was
it was seen
seen thatthat
all all three
three models
models hadhadthe
the same
same result
result as shown
as shown in Figure
in Figure 9. 9.
TheThe accuracyvalue
accuracy valuewaswas91%,
91%,recall
recall84%
84%and
and F1-score
F1-score
91%. The
91%. The similar
similar values
values inin the
the parameters
parameters shows
shows that,
that, regardless
regardless of of the
the hyperparameters,
hyperparameters,
the proposed
the proposed tree
tree model
model will
will always
always have
have the
the same
same values
values ofofaccuracy,
accuracy, recall
recall and
and F1-score.
F1-score.
Balancing the
Balancing the data,
data, leaving
leaving everyone
everyone with
with the
the same
same amount
amount of of training
training datasets,
datasets, did
did not
not
affect the
affect the final
final result,
result, since
since the
the random
random oversampling
oversampling technique
technique duplicates
duplicates thethe existing
existing
datasets, so
datasets, so despite
despite the
the greater
greater number
number of of training
training data,
data, the
the behavior
behavior of of the
the electric
electric current
current
would be
would be the
thesame
sameasasthe theexisting
existingdatasets,
datasets, which
which diddidnotnot
cause any any
cause difference in theinfinal
difference the
accuracy.
final accuracy.

Figure 9.
Figure 9. Analysis
Analysis of
of the
the metrics
metrics of
of the
the three
three tests
tests in
in the
the Decision
Decision Tree.
Tree.

Although the result is similar in all cases, one of them was collected for the purpose of
Although the result is similar in all cases, one of them was collected for the purpose
interpretation, and from that all test parameters (Table 4) can be analyzed.
of interpretation, and from that all test parameters (Table 4) can be analyzed.
Table 4. Decision Tree parameters with hyperparameters and with unbalanced data.
Normal with Gas

Gas Interference

Gas Locking

Total Data
Precision

F1-Score
Normal

Recall

TN

FP

FN
TP

Normal with Gas 5 0 0 1 83% 71% 77% 6 5 44 2 1


Gas Interference 0 3 2 0 60% 100% 75% 5 3 46 0 2
Normal 2 0 28 0 93% 93% 93% 30 28 21 2 2
Gas Locking 0 0 0 13 100% 93% 96% 13 13 36 1 0

In the table, the values of true positives (TP) are the total of data that the model got
right, the true negatives (TN) are related to the sum of the correct data (diagonal of the
matrix in bold) that were 49, minus the correct data of each condition. The false positives
(FP) are the errors of the condition studied in the column, for example: two datasets of
the normal condition were confused with the normal with gas, so there are two FP for the
normal condition with gas. Finally, the false negatives (FN) are the errors of the condition
studied in the line, in the normal condition with gas only one dataset is confused with the
gas locking condition.
Sensors 2023, 23, 279 12 of 19

Analyzing what is exposed, it can be concluded that the highest number of hits were
in the normal condition, despite the algorithm having two FN in this category. Another
condition analyzed is gas locking which had 100% of hits, however its accuracy was 93% as
in a dataset of the normal gas (FP) it was confused with the lock condition.
The third most assertive condition was the normal with gas, which hit five out of six
datasets, however its accuracy was 71% thanks to the FP value. The condition where the
Decision Tree model was least correct was gas interference. Of the five datasets, only three
were successful in the condition and two were FN of the normal condition. The recall and
the F1-score were impaired, only the accuracy was 100%, because there are no FP values.

4.2. K-Nearest Neighbor (KNN)


To train the data with the KNN model, from the scikit-learn library, the Kneigh-
borsClassifier function was used. When testing this model, three algorithms were imple-
mented. Initially, a simple model with the data still unbalanced and without hyperparame-
ter adjustment, in this, the accuracy was 87%. Subsequently, hyperparameters were applied
Sensors 2022, 22, x FOR PEER REVIEW 13 of 20
and the datasets remained unbalanced. It had the highest accuracy, 91%. The latter used
hyperparameters and balanced data and had an accuracy of 81%. The criteria analyzed for
each condition mentioned are shown in Figure 10. Table 5 shows all the parameters of the
Gasalgorithm.
second Locking 0 0 0 13 100% 100% 100% 13 13 36 0 0

Figure10.
Figure 10. Analysis
Analysis of
of the
the metrics
metrics of
ofthe
thethree
threetests
testsin
inthe
theKNN
KNNmodel.
model.

Table The bestparameters


5. KNN result for with
the KNN model wasand
hyperparameters with hyperparameters
with unbalanced data. and without the data
being balanced. Balancing the data in this algorithm had worse results than without bal-
Normal with Gas

Gas Interference

ancing, in which case this method does not become applicable.


Gas Locking

Total Data
Precision

F1-Score

In the KNN model, in the same way as the DT, the normal condition and gas locking
Normal

Recall

FN
TP

TN

FP

had the best results, the difference is that the KNN was able to set all the datasets of these
two operating conditions right. However, there are five FP values for normal operation
which
Normallowers
with Gas its accuracy
3 0 to 386%. Of
0 the 50%
six datasets,
100% half
67% were6 assertive
3 in the0 normal
46 3
category with gas and of the five with gas interference, three were recognized by
Gas Interference 0 3 2 0 60% 100% 75% 5 3 46 0 the2 al-
Normal 0 0 30 0 100% 86% 92% 30 30 19 5 0
gorithm.
Gas Locking 0 0 0 13 100% 100% 100% 13 13 36 0 0

4.3. Support Vector Machine (SVM)


The best result for the KNN model was with hyperparameters and without the data
beingAs in the previous
balanced. models,
Balancing the library
the data in thisused for training
algorithm the datasets
had worse results in the without
than SVM al-
gorithm was scikit-learn and the function applied was svm.SCV.
balancing, in which case this method does not become applicable. In the tests of this model,
threeInalgorithms
the KNN model, in the same way as the DT, the normal condition and gasunbal-
were performed. It started with a simple model with the data still lock-
anced
ing hadandthewithout hyperparameter
best results, adjustment.
the difference In KNN
is that the this case
wasthe accuracy
able wasthe
to set all 80%. Later,
datasets
thethese
of application with hyperparameters
two operating conditions right.andHowever,
with datasets
thereunbalanced,
are five FP had an for
values accuracy
normal of
93%. The latter used hyperparameters and balanced data and had an accuracy of 83%. The
criteria analyzed for each condition mentioned are shown in Figure 11. Table 6 shows all
the parameters of the algorithm with the best accuracy.

Table 6. SVM parameters with hyperparameters and with unbalanced data.


Sensors 2023, 23, 279 13 of 19

operation which lowers its accuracy to 86%. Of the six datasets, half were assertive in the
normal category with gas and of the five with gas interference, three were recognized by
the algorithm.

4.3. Support Vector Machine (SVM)


As in the previous models, the library used for training the datasets in the SVM
algorithm was scikit-learn and the function applied was svm.SCV. In the tests of this
model, three algorithms were performed. It started with a simple model with the data
still unbalanced and without hyperparameter adjustment. In this case the accuracy was
80%. Later, the application with hyperparameters and with datasets unbalanced, had an
accuracy of 93%. The latter used hyperparameters and balanced data and had an accuracy
Sensors 2022, 22, x FOR PEER REVIEW
of 83%. The criteria analyzed for each condition mentioned are shown in Figure 11. 14 of 20
Table 6
shows all the parameters of the algorithm with the best accuracy.

Figure
Figure 11. Analysis of
11. Analysis of the
the metrics
metrics of
of the
the three
three tests
tests in
in the
the SVM
SVM model.
model.

TableThe application
6. SVM of with
parameters hyperparameters increased
hyperparameters and withthe accuracydata.
unbalanced of the model without hy-
perparameter by 13 percentage points, however, when using the balanced dataset there is
Normal with Gas

Gas Interference

a decrease of 10 percentage points, going from 93% accuracy with hyperparameters and
Gas Locking

Total Data
Precision

F1-Score
Normal

without balancing to 83% with hyperparameter and balancing. In this case, the balancing
Recall

TN

FP

FN
TP

method is not applicable to the model in question.


The best result, observed in the table, was the normal operation that had a 100% re-
call. In gas
Normal withlocking,
Gas 5of the
0 13 datasets
1 0studied,
83% the 71%
algorithm
77% got 126 right,
5 so 44
it generated
2 1 1
FN.GasAs in the gas locking,
Interference 1 3 the1number 0 of FN
60% was low, the
100% 75% recall5 and F1-score
3 46 were
0 92%
2
Normal 0 0 30 0 100% 94% 97% 30 30 19 2 0
and Gas
96%, respectively.
Locking 1 As
0 with 0 the models
12 mentioned
92% 100% above,
96% the
13 SVM 12reached
37 the
0 mark
1
of three sets of correct data in the category of gas interference, which was five. This gen-
eratedThetwo FN’s that of
application were confused by normal
hyperparameters gas operation
increased and of
the accuracy normal operation.
the model Fi-
without
nally, we have the
hyperparameter bynormal operation
13 percentage with however,
points, gas that hit six out
when of five
using the datasets,
balancedthe confusion
dataset there
was in the normal operation that generated 1 FN.
is a decrease of 10 percentage points, going from 93% accuracy with hyperparameters and
without balancing to 83% with hyperparameter and balancing. In this case, the balancing
4.4. Neural
method Network
is not (NN) to the model in question.
applicable
To train
The the data
best result, with the
observed MLP
in the Neural
table, was Network,
the normalfrom the scikit-learn
operation that had a library, the
100% recall.
MLPClassifier
In gas locking, function
of the 13 was used.
datasets In the the
studied, testsalgorithm
of this model,
got 12three
right,algorithms were1per-
so it generated FN.
formed.
As in theThe
gas first was the
locking, a simple
numbermodel
of FNwith
wasthelow,data
theunbalanced and without
recall and F1-score hyperparam-
were 92% and 96%,
eter tuning. In
respectively. Asthis one,
with thethe accuracy
models was 83%.
mentioned The second
above, the SVM had the application
reached of three
the mark of hyperpa-
sets
rameters
of correct and
datathe datasets
in the remained
category unbalanced, which
of gas interference, with the
was highest accuracy,
five. This 87%.two
generated TheFN’s
lat-
ter used
that werehyperparameters
confused by normal andgas
balanced dataand
operation andnormal
had anoperation.
accuracy Finally,
of 81%. we
Thehave
criteria
the
analyzed for each condition mentioned are shown in Figure 12. Table 7 shows all the pa-
rameters of the algorithm with the best accuracy.

Table 7. Parameters of the Neural Network with hyperparameters and with unbalanced data.
as

ce
Sensors 2023, 23, 279 14 of 19

normal operation with gas that hit six out of five datasets, the confusion was in the normal
operation that generated 1 FN.

4.4. Neural Network (NN)


To train the data with the MLP Neural Network, from the scikit-learn library, the MLP-
Classifier function was used. In the tests of this model, three algorithms were performed.
The first was a simple model with the data unbalanced and without hyperparameter tuning.
In this one, the accuracy was 83%. The second had the application of hyperparameters
Sensors 2022, 22, x FOR PEER REVIEW 15 of 20
and the datasets remained unbalanced, with the highest accuracy, 87%. The latter used
hyperparameters and balanced data and had an accuracy of 81%. The criteria analyzed for
each condition mentioned are shown in Figure 12. Table 7 shows all the parameters of the
Gas Locking
algorithm with the best0accuracy.
0 0 13 100% 100% 100% 13 13 36 0 0

Figure
Figure 12. Analysis of
12. Analysis of the
the metrics
metrics of
of the
the three
three tests
tests in
in the
the Neural
Neural Network.
Network.

TableThe best result


7. Parameters for Neural
of the the NN model with
Network of the MLP type was
hyperparameters with
and withhyperparameters
unbalanced data. and
without the data being balanced. Balancing the data in this algorithm had worse results
Normal with Gas

Gas Interference

than without balancing, in which case this method does not become applicable.
Gas Locking

Total Data
Precision

F1-Score
Normal

The Neural Network algorithm had the gas locking and normal operation with the
Recall

TN

FP

FN
TP

best results, as seen in the KNN and SVM models, the difference is in the number of hits.
In the case of NN, it generated one NF and five FP under normal operating conditions. In
theNormal
gas locking,
with Gas it got
5 it right
0 all
1 with 0no FP83% and FN,
83%achieving
83% an6 accuracy,
5 recall1and F1-
44 1
score of 100%. The1 Neural
Gas Interference 0 Network
4 0also excelled
0% 0%in the0%condition
5 of0 normal
49 operation
1 5
Normal 0 1 29 0 97% 85% 91% 30 29 20 5 1
withGas
gas, the algorithm
Locking 0 hit
0 five 0 of the13six datasets
100% generating
100% 100% only 13 one 13 FN. 36 0 0
However, the problem with this algorithm was the gas interference, it could not iden-
tify any
The of theresult
best five datasets.
for the NN Themodel
algorithm
of theconfused
MLP type thewas
electric
with current behavior with
hyperparameters and
normal operation and normal operation with gas, generating five FN.
without the data being balanced. Balancing the data in this algorithm had worse results It also had one FP
which was obtained thanks to the dataset of normal operation.
than without balancing, in which case this method does not become applicable. Therefore, the precision,
recallThe
andNeural
F1-score of this condition
Network algorithmwas had0%thecausing a sharp
gas locking drop
and in theoperation
normal model’s accuracy.
with the
best results, as seen in the KNN and SVM models, the difference is in the number of hits. In
4.5. case
the Limitations
of NN,ofit the Presented
generated oneMethods
NF and five FP under normal operating conditions. In the
For the it179
gas locking, gotdatasets analyzed
it right all with nothere
FP andareFN,
several that are
achieving anvisibly similar,
accuracy, recallsuch as some
and F1-score
of 100%.
of the datasets of normal
The Neural Networkwithalso
gasexcelled
and gasininterference.
the condition What really operation
of normal differentiates
witheach
gas,
operating
the condition
algorithm hit fiveisofthe
thevariation of the
six datasets electricalonly
generating current amplitude, as mentioned in
one FN.
Section 3.1. Therefore,
However, to improve
the problem the accuracy
with this algorithmofwaseachthesystem, after the interpolation
gas interference, it could nota
scale from
identify any0 of
to the
75 A was
five used soThe
datasets. that, in addition
algorithm to thethe
confused visual conditions
electric currentof each graph,
behavior with
it was possible
normal operationto identify
and normalthe amplitude
operation of thegas,
with variation of thefive
generating electric
FN. current.
It also had one FP
Even so, the algorithms still cannot differentiate the datasets from the conditions
mentioned above, as some still behave very similarly. This limitation is seen in the confu-
sion matrix data, causing a decrease in the accuracy of the methods.

5. Discussion
Sensors 2023, 23, 279 15 of 19

which was obtained thanks to the dataset of normal operation. Therefore, the precision,
recall and F1-score of this condition was 0% causing a sharp drop in the model’s accuracy.

4.5. Limitations of the Presented Methods


For the 179 datasets analyzed there are several that are visibly similar, such as some
of the datasets of normal with gas and gas interference. What really differentiates each
operating condition is the variation of the electrical current amplitude, as mentioned in
Section 3.1. Therefore, to improve the accuracy of each system, after the interpolation a
scale from 0 to 75 A was used so that, in addition to the visual conditions of each graph, it
was possible to identify the amplitude of the variation of the electric current.
Even so, the algorithms still cannot differentiate the datasets from the conditions
mentioned above, as some still behave very similarly. This limitation is seen in the confusion
matrix data, causing a decrease in the accuracy of the methods.

5. Discussion
The analysis of the confusion matrix presents the results of the classification algorithms
in a detailed way, however, they are not enough to prove that the experimental results are
Sensors 2022, 22, x FOR PEER REVIEW significant. To validate the results obtained in Section 4, tests of variation of means16 ofwere
20
used, these were: the analysis of variance test (ANOVA) [31] followed by the Tukey’s test.
The tests were performed using the Action Stat statistical software. For the tests, four
replications were performed for each model. It is important to emphasize that the guarantee
guarantee of the reliability of the statistical model is only possible when the ANOVA
of the reliability of the statistical model is only possible when the ANOVA assumptions
assumptions are met. In this work, this was confirmed with tests of normality and
are met. In this work, this was confirmed with tests of normality and variability of the
variability of the residuals. This can be seen in Figure 13.
residuals. This can be seen in Figure 13.

(a) (b)
Figure
Figure13.13.Residue
Residueanalysis. (a) Comparison
analysis. diagram
(a) Comparison of normal
diagram quantiles
of normal for model
quantiles residuals;
for model (b)
residuals;
Graph of residuals
(b) Graph versus
of residuals adjusted
versus values.
adjusted values.

ItItis is
possible
possibleto to
analyze
analyzein Figure
in Figure13a13a
thatthat
the residuals
the residualsare normally
are normallydistributed ac-
distributed
cording to the Anderson–Darling normality test (n = 16; AD = 0.201 and p-value = 0.856).
according to the Anderson–Darling normality test (n = 16; AD = 0.201 and p-value = 0.856).
Figure
Figure13b 13bproves
provesthat
thatthe
theresiduals
residualsarearewell
welldistributed
distributedalong
alongthethezero
zeroaxis,
axis,declaring
declaringthat
that
the
thedata
dataare areacceptable
acceptablefor forusing
usingANOVA.
ANOVA.InInANOVA,
ANOVA,the thep-value
p-valuewas wasverified,
verified,which
which
must
must bebe less than
less or equal
than to the
or equal to 5%
thesignificance level. level.
5% significance In the case of this
In the casework,
of thisthework,
p-valuethe
= 0.00428. Therefore, it is concluded that there is a high correlation between the data of
p-value = 0.00428. Therefore, it is concluded that there is a high correlation between the
this article and this value is very strongly against the null hypothesis.
data of this article and this value is very strongly against the null hypothesis.
With
Withthe thevalidation
validationofofthethep-value
p-valuerejecting
rejectingthe
thenull
nullhypothesis,
hypothesis,the theTukey’s
Tukey’stesttestwas
was
performed to test whether there were differences between the variables, which in this case
performed to test whether there were differences between the variables, which in this case
were
wereclassification
classificationalgorithms
algorithms(DT, (DT,KNN,
KNN,SVM SVMand andNN).
NN).The Theresults
resultsofofthis
thisanalysis
analysisare
are
shown in
shown in Table 8.Table 8.

Table 8. Results of Tukey’s test analysis.

DT KNN SVM NN
a ab a b
Sensors 2023, 23, 279 16 of 19

Table 8. Results of Tukey’s test analysis.

DT KNN SVM NN
a ab a
0.882 0.831 0.923 0.773 b
a,b Means followed by the same letters do not differ from each other at the level and 5%.

Table 8 presents the mean of the replicates of each algorithm based on groups “a” and “b”.
The best result of the averages was from the Support Vector Machine algorithm. Further-
more, the result confirms that the SVM and DT algorithms differ from the NN algorithm by
Tukey’s test at 5% probability. The KNN algorithm does not differ from any tested model.
To make it more visual, Figure 14 confirms what was seen in Table 8. All combinations
of algorithms that cross the red dashed line are related to each other. The p-value of the
SVM-NN was 0.004, showing that among the algorithms tested in this work, the Support
Vector Machine and the Neural Network are the ones that most differ from each other,
as their p-value is the furthest from 5% of the range reliable. The algorithms that have
Sensors 2022, 22, x FOR PEER REVIEW
the highest relationship are the Support Vector Machine and the Decision Tree 17 of with
20 a
p-value of 0.621.

Figure 14.
Figure 14. Differences
Differencesbetween
betweenclassification algorithms
classification (DT,(DT,
algorithms KNN, SVMSVM
KNN, and and
NN) NN)
basedbased
on confi-
on confi-
dence interval
dence interval (95%).
(95%).

After statistical
After statistical analysis,
analysis,ititwas
wasfound
foundthat
thatthe
thefour
fourmodels
modelsanalyzed
analyzed can bebe
can applied
applied to
to identify operating conditions in ESP pumps. The best results were with the SVM algorithm
identify operating conditions in ESP pumps. The best results were with the SVM algo-
rithm
due todue
thetosupport
the support vectors
vectors formed
formed bybythe
thealgorithm
algorithm that
thatshow
showthethe
data closest
data to the
closest to the
decision surface.
decision surface.Therefore,
Therefore,there
thereis is
greater precision
greater when
precision dealing
when withwith
dealing similar datasets.
similar datasets.
However, the NN had a lower accuracy than the other algorithms, as its accuracy in the
gas interference condition was lower. This can be explained because for the NN the
amount of input data for testing was low so that it was possible to make the necessary
combinations in the neurons.
As can be seen in the results of the confusion matrices, the best precision was for the
Sensors 2023, 23, 279 17 of 19

However, the NN had a lower accuracy than the other algorithms, as its accuracy in the gas
interference condition was lower. This can be explained because for the NN the amount of
input data for testing was low so that it was possible to make the necessary combinations
in the neurons.
As can be seen in the results of the confusion matrices, the best precision was for the
gas locking condition. This can be explained, because such a condition had its dataset
simulated, in this way, the characteristics are specific and the algorithm can identify them
assertively. Normal operation also has a high level of precision, as its graphs are more linear
or with very small peaks, so there is no great difficulty for ML algorithms to identify them.
Hyperparameter analyses increased the metrics of almost all models, leaving just the
same ones in the Decision Tree. However, the application to balance the training set was
not an effective method for this work.

6. Conclusions
This work presented a solution in the machine learning branch to provide a diagnosis
of operating conditions in electrical submersible pumps. The conditions studied were
normal operation, normal operation with gas, gas interference and gas locking. The
proposed study analyzed real data in the interior region of the state of Rio Grande do Norte
and simulated data for the gas locking condition.
The four operating conditions mentioned were classified, so that the data were stan-
dardized by the interpolation method and, finally, the data were divided into 70% training
and 30% testing. The validation procedure considered different classifiers, Decision Tree
(DT), Support Vector Machine (SVM), K-Nearest Neighbor (KNN), and Multi-Layer Per-
ceptron (MLP) Neural Network and a statistical study helped in the selection of the best
classifier for this work.
The use of hyperparameters in most cases helped to improve the accuracy of the
system. Regarding the equilibrium state of the training datasets, no major differences were
observed in the results. This is explained by the duplication of training data that must have
generated confusion in the algorithm, impairing the correct identification of the datasets,
since most of the graphs are similar to each other and what is changed is the amplitude of
the electric current.
The results showed that any of the evaluated classifiers can solve the problem and
facilitate the work of a field engineer and, consequently, reduce the time spent in the
process of diagnosing pump operating conditions. It is worth mentioning that for the
gas interference condition the Neural Network had the lowest precision. The models that
produced an accuracy rate greater than 90% were the Decision Tree, the KNN model and
SVM. The best accuracy was the SVM algorithm with 93%, recall 84% and F1-score 92%.
The hyperparameters used in the SVM model were gamma = 0.0001, kernel = rbf, and
C = 10.
Data analysis by machine learning is growing nowadays, and in this work it was
possible to identify operating conditions of the ESP system with a high level of assertiveness.
In addition, the parameter used to identify the conditions of the aforementioned lift method
was the electric current, which has a noisy and often unstable signal. The use of this
parameter made the work innovative.
As future work, it is recommended to evaluate more operating conditions such as sand
influence, insufficient well flow, frequent stopping and restarting of the pump, frequent
load change due to emulsification, among others. In addition, it is indicated to analyze
other variables that would assist the electric current, such as frequency, pump suction
pressure and gas oil ratio (GOR).

Author Contributions: Conceptualization, J.B., C.M. and J.N.; data curation, J.B., C.M. and J.N.;
formal analysis, J.B., C.M., J.N. and E.G.; funding acquisition, E.G.; investigation, J.B., C.M., O.C.-F.
and E.G.; methodology, J.B., C.M., J.N. and O.C.-F.; project administration, C.M., O.C.-F. and E.G.;
resources, C.M. and O.C.-F.; software, J.B. and J.N.; supervision, J.B., C.M., J.N., O.C.-F. and E.G.;
validation, J.B., C.M., J.N., O.C.-F. and E.G.; visualization, J.B., C.M., J.N., O.C.-F. and E.G.; writing—
Sensors 2023, 23, 279 18 of 19

original draft, J.B., C.M., J.N., O.C.-F. and E.G.; writing—review and editing, J.B., C.M., J.N., O.C.-F.
and E.G. All authors have read and agreed to the published version of the manuscript.
Funding: This study was financed in part by Post-graduation Program in Chemical Engineering.
Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.
Data Availability Statement: The data present in this study are available on request from the
J.B. author.
Acknowledgments: Post-graduation Program in Chemical Engineering, Petroleum Automation
Laboratory and PRH-26.
Conflicts of Interest: The authors declare no conflict of interest.

References
1. Albar, A.; Asfoor, H.; Goz, A.; Ansari, N. Combining the power of IoT and big data to unleash the potential of digital oil field. In
Proceedings of the International Petroleum Technology Conference, Beijing, China, 26–28 March 2019. [CrossRef]
2. Ratcliff, D.; Gomez, C.; Cetkovic, I.; Madogwe, O. Maximizing oil production and increasing ESP run life in a brownfield using
real-time ESP monitoring and optimization software: Rockies field case study. In Proceedings of the SPE Annual Technical
Conference and Exhibition, New Orleans, LA, USA, 30 September–2 October 2013. [CrossRef]
3. Gindy, M.E.; Abdelmotaal, H.; Botros, K.; Ginawi, I.; Sayed, E.; Edris, T. Monitoring & Surveillance Improve ESP Operation and
Reduce Workover Frequency. In Proceedings of the Abu Dhabi International Petroleum Exhibition and Conference, Abu Dhabi,
United Arab Emirates, 9–12 November 2015. [CrossRef]
4. Takács, G. Electrical Submersible Pumps Manual: Design, Operations, and Maintenance; Gulf Professional Publishing: Houston, TX,
USA, 2009.
5. Bates, R.; Cosad, C.; Fielder, L.; Kosmala, A. Taking the Pulse of Producing Wells—ESP Surveillance. Oilfield Rev. 2004, 16, 16–25.
6. Oliva, G.B.; Galvão, H.L.; dos Santos, D.P.; Maitelli, A.L.; Costa, R.O.; Maitelli, C.W. Gas Effect in ESP System Stage by
Stage Analysis. In Proceedings of the SPE Artificial Lift Conference—Latin America and Caribbean, Salvador, Bahia, Brazil,
27–28 May 2015. [CrossRef]
7. Al-Bimani, A.S.; Armacanqui, S.; Al-Barwani, B.; Al-Hajri, S.; Sipra, I.; Al-Riyami, H. Electrical Submersible Pumping System:
Striving for Sustainable Run-Life Improvement in Oman Oil Fields. In Proceedings of the IPTC 2008: International Petroleum
Technology Conference, Kuala Lumpur, Malaysia, 3–5 December 2008. [CrossRef]
8. Gupta, S.; Saputelli, L.; Nikolaou, M. Applying big data analytics to detect, diagnose, and prevent impending failures in electric
submersible pumps. In Proceedings of the SPE Annual Technical Conference and Exhibition, Dubai, United Arab Emirates,
26–28 September 2016. [CrossRef]
9. Barbosa, T.S. Ambiente para Avaliação de Controladores Fuzzy Aplicados ao Método de Elevação Artificial por Bombeio
Centrífugo Submerso. Master’s Thesis, Programa de Pós Graduação em Ciência e Engenharia de Petróleo. Universidade Federal
do Rio Grande do Norte, Natal, Brazil, July 2011.
10. Brodley, C.E.; Utgoff, P.E. Multivariate versus Univariate Decision Trees; Technical Report 92-8; University of Massachusetts: Amherst,
MA, USA, 1992.
11. Kesavaraj, G.; Sukumaran, S. A study on classification techniques in data mining. In Proceedings of the 2013 Fourth International
Conference on Computing, Communications and Networking Technologies (ICCCNT), Tiruchengode, India, 4–6 July 2013;
pp. 1–7. [CrossRef]
12. Zhang, Z. Introduction to machine learning: K-nearest neighbors. Ann. Transl. Med. 2016, 4, 218. [CrossRef] [PubMed]
13. Soofi, A.A.; Awan, A. Classification techniques in machine learning: Applications and issues. J. Basic Appl. Sci. 2017, 13, 459–465.
[CrossRef]
14. Nizar, A.H.; Dong, Z.Y.; Wang, Y. Power utility nontechnical loss analysis with extreme learning machine method. IEEE Trans.
Power Syst. 2008, 23, 946–955. [CrossRef]
15. Xiao, H.; Peng, F.; Wang, L.; Li, H. Ad hoc-based feature selection and support vector machine classifier for intrusion detec-
tion. In Proceedings of the 2007 IEEE International Conference on Grey Systems and Intelligent Services, Nanjing, China,
18–20 November 2007.
16. Chandra, M.A.; Bedi, S.S. Survey on SVM and their application in image classification. Int. J. Inf. Technol. 2021, 13, 1–11. [CrossRef]
17. Ahmad, I.; Abdulah, A.B.; Alghamdi, A.S. Towards the designing of a robust intrusion detection system through an optimized
advancement of neural networks. In Advances in Computer Science and Information Technology; Kim, T., Adeli, H., Eds.; Springer:
Berlin/Heidelberg, Germany, 2010; pp. 597–602. [CrossRef]
18. Goh, A.T. Back-propagation neural networks for modeling complex systems. Artif. Intell. Eng. 1995, 9, 143–151. [CrossRef]
19. Guo, Z.X.; Wong, W.K.; Li, M. Sparsely connected neural network-based time series forecasting. Inf. Sci. 2012, 193, 54–71.
[CrossRef]
Sensors 2023, 23, 279 19 of 19

20. Wang, B.; Gong, N.Z. Stealing hyperparameters in machine learning. In Proceedings of the 2018 IEEE Symposium on Security
and Privacy (SP), San Francisco, CA, USA, 20–24 May 2018; pp. 36–52. [CrossRef]
21. Mantovani, R.G.; Rossi, A.L.D.; Vanschoren, J.; Bischl, B.; de Carvalho, A.C.P.L.F. Effectiveness of random search in SVM
hyper-parameter tuning. In Proceedings of the 2015 International Joint Conference on Neural Networks (IJCNN), Killarney,
Ireland, 12–17 July 2015; pp. 1–8. [CrossRef]
22. Ghawi, R.; Pfeffer, J. Efficient hyperparameter tuning with grid search for text categorization using KNN approach with BM25
similarity. Open Comput. Sci. 2019, 9, 160–180. [CrossRef]
23. Chawla, N.V.; Bowyer, K.W.; Hall, L.O.; Kegelmeyer, W.P. SMOTE: Synthetic minority over-sampling technique. J. Artif. Intell.
Res. 2002, 16, 321–357. [CrossRef]
24. Galar, M.; Fernandez, A.; Barrenechea, E.; Bustince, H.; Herrera, F. A review on ensembles for the class imbalance problem:
Bagging-, boosting-, and hybrid-based approaches. IEEE Trans. Syst. Man Cybern. Part C Appl. Rev. 2012, 42, 463–484. [CrossRef]
25. Weiss, G.M.; Mccarthy, K.; Zabar, B. Cost-sensitive learning vs. sampling: Which is best for handling unbalanced classes with
unequal error costs? In Proceedings of the International Conference on Data Mining, Bronx, NY, USA, 7 February 2007.
26. Kulkarni, A.; Chong, D.; Batarseh, F.A. Foundations of data imbalance and solutions for a data democracy. In Data Democracy;
Elsevier: Amsterdam, The Netherlands, 2020; pp. 83–106. [CrossRef]
27. De Castro, L.N.; Ferrari, D.G. Introdução a Mineração de Dados, 1st ed.; Saraiva Educação SA: São Paulo, Brazil, 2017.
28. Nascimento, J.; Maitelli, A.; Maitelli, C.; Cavalcanti, A. Diagnostic of Operation Conditions and Sensor Faults Using Machine
Learning in Sucker-Rod Pumping Wells. Sensors 2021, 21, 4546. [CrossRef] [PubMed]
29. Han, G.; Chen, M.; Zhang, H.; Ling, K. Real-Time Monitoring and Diagnosis of Electrical Submersible Pump. In Proceedings of
the SPE Annual Technical Conference and Exhibition, Houston, TX, USA, 28–30 September 2015. [CrossRef]
30. Géron, A. Hands-on machine learning with Scikit-Learn and TensorFlow: Concepts, tools, and techniques to build intelligent systems,
1st ed.; O’Reilly Media: Sebastopol, CA, USA, 2017.
31. Sthle, L.; Wold, S. Analysis of variance (ANOVA). Chemom. Intell. Lab. Syst. 1989, 6, 259–272. [CrossRef]

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual
author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to
people or property resulting from any ideas, methods, instructions or products referred to in the content.
Reproduced with permission of copyright owner. Further reproduction
prohibited without permission.

You might also like