1 Introduction

Coronavirus disease (COVID-19) is a severe respiratory syndrome, which first recognized in Wuhan, China in December 2019 (Kucharski et al. 2020). The initial symptoms of COVID-19 are dry caught, fever, and tiredness which are common for a number of respiratory diseases. Then, aches and pains, sore throat, loss of smell and taste would be presented. In the next stages of the disease, serious symptoms such as pneumonia and sever respiratory diseases and even heart failure would be occurred. Several research papers are published on COVID-19 from different views such as the transmission speed, drug and vaccine production, general health and psychological problems, however, consumer behaviour has received less attention.

With the advent of internet, knowledge-based economies such as online shopping was emerged long time ago. Machine learning methods could be used to extract implicit knowledge from the online shopping sites’ logs (Ahmadi 2020). Industries and businesses use the knowledge to better understand the consumer behavior, and opportunities and threats correspondingly. However, with the outbreak of COVID-19, online shopping attracted more attention. We have to stay at home and observe self-Isolation and social distancing because the transmission speed of the disease is very high. In particular, for elderly and people with background disease such as respiratory diseases, heart (Ivanov 2020) conditions, hypertension, diabetes, multiple sclerosis (MS), and cancer, we have to pay special attention and provide specific facilities. These conditions considerably affect the consumers shopping behavior.

Nowadays, big projects such as Siri Apple, Eco Amazon, Google, Facebook, and Microsoft employ machine learning techniques to automatically analyze their consumers shopping behavior and provide appropriate service for them (Wu et al. 2019). However, using machine learning methods is not restricted to projects with huge research budgets. Small and Medium Enterprises (SMEs) could benefit from these methods to improve their efficiency as well. Beside the spread of COVID-19, different important reasons could be presented to show the appropriateness of machine learning methods for SMEs (Zeng et al. 2019). For example, considering urban traffic management issues, using online tools for online shopping and online marketing is on the rise (McDonald et al. 2019). In addition, online catalogs helps price and quality comparison (Ballestar et al. 2019). The required time for buying a product could be reduced considerably as well. Recognizing the consumer behaviors and providing proper service in a very short time is an important issue in any e-commerce application (Souri et al. 2019). Sometimes users try to buy a product, however, they cannot add the selected product to their shopping cart or they have problem with paying for it. Therefore, consumers leave the website without buying. This is an important issue for many e-commerce retailers (Vanneschi et al. 2018).

In a successful e-commerce application, understanding consumer behavior requires identifying reasons that encourage consumers to buy from the websites, however, identifying consumer behavior and encouraging factors is difficult (Agrawal et al. 2018). Machine learning techniques use data analytic tools to discover behavioral patterns of consumers (Patil and Rao 2019). Increasing consumer satisfaction with online shopping, and improving the accuracy of consumer need prediction have always been the main challenges in e-commerce. Machine learning and data mining methods such as classification, clustering, association rule mining, and pattern recognition techniques have been effectively employed in previous researches for predicting influential factors on e-commerce (Khodabandehlou and Rahman 2017). Problems raised with COVID-19 added the importance of paying attention to consumer satisfaction during online shopping. Therefore, a model to predict consumer behaviour in online shopping is proposed using machine learning techniques. Contributions of the method proposed could be summarized as follows:

  • A predictive model is presented to anticipate consumer behavior in online shopping in an e-commerce environment in COVID-19 era.

  • The accuracy of predicting consumer behaviors in online shopping is increased through Bagging and Boosting of the classifiers.

The rest of the paper is organized as follows: Sect. 2 provides related works published about the prediction of customer behavior. Section 3 presents the proposed method for predicting consumer behavior. Section 4 provides experimental data, experimental setup and results. Finally, Sect. 5 concludes the paper.

2 Related work

In this section, a number of research studies reported before on consumer behavior are reviewed. A thorough review has been conducted by Maria Nicola et al. (2020) on socio-economic implications of COVID-19 on world economy, including agriculture, petroleum and oil, manufacturing industry, real estate and housing sector, education sector, financial industry, pharmaceutical industry, sports industry, hospitality, tourism and aviation, family dynamics, domestic violence and home video-gaming. COVID-19 has influenced the people life from different aspects, in particular, in their shopping behaviour. Increased demands for essential goods such as food, groceries, and healthcare services encountered retailers and service providers with more chances for serving consumers at home (Change 2020). Understanding the behaviour of consumers for food stockpiling is studies by Wang et al. (2020). They showed that the scale of food reserve is almost twice during COVID-19. In addition, they concluded that the women with higher education level and higher income level are more willing to buy more food and in particular more fresh food. On the other hand, demands for non-necessary goods such as clothes, shoes, and home appliances are dropped, and caused the retailers to be faced with decrease in their sales 2019 (Pantano et al. 2020). Therefore, there is a need for models to predict consumer behaviors to plan for surviving in this market accordingly.

Two models are presented by Yoon (2020) to predict GDP growth in Japan including gradient boosting and random forest. Between two models studied, the gradient boosting was more accurate than random forest model. He claims that machine learning models are encouraging techniques in macroeconomic forecasting. A theoretical mapping is proposed in Barua (2020) to show the relationship between macroeconomic impact of the COVID-19 and affected economies. AD-AS model is introduced that considers essential features required in determining policies to cope with such economic shocks. They conclude that any action would be taken before economic depression occurs, because it would be too late if we decide to wait for COVID-19 to end and then think about its problems and solutions.

A formal modeling is performed in Souri et al. (2019a, b) to investigate the correctness of Knowledge Creation Process (KCP) in the social networks and social systems. Human behaviour in social relationships is studied and the correctness of the proposed user relationship management approach is discussed.

In Büşra Altunan et al. (2019) a dataset of Turkish statistical community is used to determine the default risk of individuals regarding to their characteristics. The dataset includes 22,745 samples with 14 attributes. Several classifiers were examined including j48, Bayesian network, Naive Bayesian, artificial neural network, logistic regression, and random forest. Their results were compared based on accuracy, performance, ROC curve and mean squared error. Finally, the most appropriate classification algorithm for risk detection is determined. Experiments performed on a real dataset indicate that consumer priorities for specific products plays a significant role in making decision for the e-commerce application (Souri et al. 2020).

Qiu et al. (2015), proposed a framework to predict the behavior of consumers in an e-commerce environment. The framework, which is called the “consumer modeling process”, is a two-step process. Relationships of products are examined and employed to predict consumer incentives, namely the construction of a candidate product set. Then, consumer priorities for the product characteristics are learned and ultimately used to identify the candidates. When a product is shipped to a consumer behavior system, the program can return products that are likely to be purchased for that consumer in the upcoming purchases. In another study conducted by Chinchilla and Ferreira (2016), the results described the use of machine learning methods to investigate the behavior of a fashion company's consumers on the Instagram. Clustering methods and associative rules are used in the cross-industry standard process to extract descriptive models. They concluded that appropriate information extracted using the proposed descriptive model could be used in marketing strategies.

A prediction model of supply chain is presented by Ivanov (2020), which is based on the simulation data. He determined specific characteristics that form epidemic coronavirus as a unique supply chain distraction risk. He also showed the effectiveness of simulation results to inspect and anticipate the influence of the disease on supply chain profits. Two software are employed: anyLogistix simulation and optimization software. Both temporary and permanent effects of COVID-19 on supply chain and management insights are considered. From the simulation results, Ivanov revealed that scheduling of closing and opening of the services at diverse levels might be an important factor determining the influence of COVID-19 on supply chain performance. Zhang et al. (2020) proposed a novel two-stage ensemble machine learning model to predict stuck price. They ensembled support vector regression and adaptive neurofazzy inference system. They studied stock exchange of Shanghai and Shenzhen during 2012 to 2017. Their experiments demonstrate that the proposed model has superior prediction results than single and two stage models studies and compared with their model. As can be concluded from the researches reviewed above consumer behavior is an important factor in determining the future success of e-commerce applications and predicting consumer behavior could be of great help for both retailers and supply chain industry managers.

3 Methods

Stability of a long-term sale depends heavily on consumer behavior and his/her needs, instead of having just great products. In particular, in the current situation of COVID-19 pandemic, consumer behavior is changing every day. Therefore, predicting consumer behavior could be of crucial importance for future business planning. An e-commerce company with the capability of anticipating consumers’ shopping behavior will gain several advantages such as increasing consumer purchase rates, increasing sales and consumer satisfaction, and greater competition (Souri et al. 2017).

In this paper, two approaches are taken to predict consumer behavior: statistical approach and machine learning approach. In statistical approach, correlation between different features are calculated and analyzed. In machine learning approach, a predictive model is proposed to anticipate consumer behavior in online shopping. The research process followed in this paper is illustrated in Fig. 1. The methods, are examined to predict consumer behavior based on the data collected from online purchase at DigiKala site (www.digikala.com). DigiKala is one of the largest and successful online shopping sites in middle east. The well-known classification methods of machine learning are compared and the best practice with the highest accuracy is identified.

Fig. 1
figure 1

Research process

In the rest of this section, first data preprocessing is presented. Then, correlation analysis explained briefly. After that, the proposed machine learning method for predicting consumer behavior is presented. At the end of the section, evaluation criteria employed to assess the proposed method are provided.

3.1 Preprocessing

In the first step, the data should be preprocessed to reduce the implementation time and improve the results. For this purpose, we normalized the data so that the attributes are normalized as follows. The general formula is:

$$ {{newValue}} = { }\frac{{{{origionalValue}} - {{oldMin}}\left( {{{newMax}} - {{NewMin}}} \right) + {{newMin}}}}{{{{oldMax}} - {{oldMin}}}} $$
(1)

In this paper, the desired range for normalization is considered as [0, 1], therefore, the Eq. (1) would be changes to the following equation:

$$ {{newValue}} = { }\frac{{{{origionalValue}} - {{oldMin}}}}{{{{oldMax}} - {{oldMin}}}} $$
(2)

3.2 Correlation Analysis

The data employed in this paper is constructed of 11 features where the “Effective” that is the 11th features, is the impact of COVID-19 on consumer purchase volume (the structure of the dataset is explained in Sect. 4.1 in detail). After normalizing the data, we calculated the correlation between the features to find the feature that has higher correlation with “Effective” feature. Pearson correlation is calculated from the following equation:

$$ \rho_{X,Y} = {{corr}}\left( {X,Y} \right) = \frac{{{{cov}}\left( {X,Y} \right)}}{{\sigma_{X} \sigma_{Y} }} = \frac{{E\left[ {\left( {X - \mu_{X} } \right)\left( {Y - \mu_{Y} } \right)} \right]}}{{\sigma_{X} \sigma_{Y} }} $$
(3)

where \(\rho_{X,Y}\) is the Pearson correlation between X and Y that are two variables we are interested to calculate their correlation. \(\mu_{X}\) and \(\mu_{Y}\) are expected values of X and Y, and \(\sigma_{X}\) and \(\sigma_{Y}\) are standard deviations of X and Y. Standard deviation should be finite and positive to make Pearson correlation valid. E is expected value operation, cov is covariance operator, and corr is correlation coefficient.

The feature “Effective” accepts two values: ‘yes’ and ‘no’. The value ‘yes’ indicates that COVID-19 influenced consumers’ purchase behavior and the value ‘no’ indicates that COVID-19 did not influence consumers’ purchase behavior. The correlation results are provided in Sect. 4.2.

3.3 Classification

Classification methods are usually used to design both description and prediction models. In this research study, we examined five classification methods namely: support vector machine (SVM), decision tree (DT), Sequential Minimal Optimization (SMO), artificial neural network (ANN), and Naïve Bayes (NB). Ensemble meta-algorithms, Boosting and Bagging are also examined with the above classifiers to improve the accuracy of the proposed method. Ensemble methods use a number of classification algorithms to achieve a better predictive performance than each of the classification algorithms. Boosting and Bagging are ensemble methods that convert weak classifiers to strong classifiers through reducing bias and variance. Bagging is a statistical approximation method that uses a statistical quantity, such as an average, to be estimated from multiple random samples of your data. It is a beneficial method when there is a small amount of data and we are interested in a stronger approximation of a statistical measure. Boosting works as Bagging, however uses weighted average. In training stage, they generate N training datasets from the original dataset through random sampling with replacement. In Boosting, the samples are weighted and some of the samples has more chance to influence the classification results. However, in Bagging all the samples has same chance to be participated in training process. Bagging improves the accuracy of the weak classifiers via training the learners in parallel. On the other hand, Boosting trains weak classifiers sequentially, where each classifier tries to improve the results of its predecessor. Bagging and Boosting reduce the bias and variance of a single classifier and improve the accuracy of prediction. In order to predict the consumer behavior, individual classifiers and their ensembles with Bagging and Boosting are examined in this paper, and the results are provided in Sect. 4.2.

3.4 Evaluation Criteria

The results of applying the model on the dataset are evaluated through accuracy, precision, recall, and F-Measure criteria calculated from confusion matrix values. A confusion matrix for a typical two-value classification problem is presented in Table 1.

Table 1 A typical confusion matrix for a binary classification problem

Four important criteria to evaluate classification performance are accuracy, precision, recall, and F-Measure. Accuracy is one of the important classification evaluation criteria that could be calculated from Eq. 4:

$$ {{AC}} = \frac{{{{TN}} + {{TP}}}}{{{{TN}} + {{FN}} + {{TP}} + {{FP}}}} $$
(4)

Precision and recall refer to quality and quantity of the results. In other words, precision indicates the ratio of the relevant results to irrelevant ones, and recall indicates the overall percentage of relevant results retrieved. Precision and recall are measured through the Eqs. 5and 6, respectively.

$$ {{Percision}} = \frac{{{{TP}}}}{{{{TP}} + {{FP}}}} $$
(5)
$$ {{Recall}} = \frac{{{{TP}}}}{{{{TP}} + {{FN}}}} $$
(6)

F-Measure deals with the accuracy of a test and is calculated based on precision and recall as follows:

$$ {{F - Measure}} = \frac{{{{Precision}}*{{Recall}}*2}}{{{{Precision}} + {{Recall}}}} $$
(7)

F-measure is the harmonic mean of the precision and recall of the model developed. The maximum value of F-measure is 1, which means the best precision and recall. Its minimum value is 0, which means that one of the prescription and recall is 0.

4 Results

In this section, first a description of the dataset is provided. Then, the results of the proposed method on the consumers' online shopping dataset is presented. The results are obtained and compared based on the evaluation criteria explained in Sect. 3.4.

4.1 Experimental data and experimental setup

The dataset is obtained from DigiKala online shopping site (www.digikala.com). Each record of the dataset is composed of 11 features, where the 11th feature with is the class label. The decryption of the data is presented in Table 2. Gender, age, education level, and job are the demographic features. Next four features are about probable consumers’ diseases. The last two features are about the number of purchase in two months before and after the COVID-19 pandemic (before and after 20 March 2020).

Table 2 Description of the dataset records

The computer used in this experiment is a CPU Intel(R) Core (TM) i74700 HQ CPU @ 2.40 GHz. RAM is 8.00 GB. The system is 64-bit Windows 8 operating system. Correlation analysis is performed in Python anaconda Ver 2020.20 with seaborn library Ver 0.10.0, and machine learning models are constructed and evaluated in Weka Ver 3.8.1. Anaconda is an open source and free version of Python and R programming language. It is widely used for research computing with machine learning algorithms. It works with almost all operating systems including Windows and Linux.

4.2 Experimental Results

Correlation analysis calculates the statistical relationship between two variables. The correlation analysis explained in Sect. 3.2 is applied on the dataset and the results in Fig. 2 is obtained. Among the demographic features, Gender has the least correlation and Age has the most correlation with Effective feature. This indicates that Gender feature has the least impact on increasing the number of purchases during the COVID-19 era. As can be concluded, the older the Age, the greater the interest in online shopping.

Fig. 2
figure 2

Correlation between all the features

Among the four diseases studied, Cancer, Diabetes, Respiratory disease, and MS, three of them has almost the same correlation with Effective feature; with the correlation of 0.23, 0.23, and 0.24. This means they have almost the same influence on increasing the number of purchase in an online shopping. However, Diabetes has 0.32 correlation with Effective features that means people with Diabetes has more online purchases than people with the other diseases.

As for NP-BP and NP-AP features, during the four months of study, number of purchase before 20 of March has a weak correlation with Effective feature. However, in the next two months the number of purchase are increased and the correlation of 0.67 between NP-AP and Effective features is obtained.

After correlation analysis, with the aim of predicting consumers’ online shopping behavior, five machine learning models including DT, SVM, SMO, NB, and ANN, are created and their results are compared. First, the machine learning classification methods examined individually. Then, individual classifiers and their ensembles with Boosting and Bagging are experienced. tenfold cross validation is performed for validating the results. the results of classification through each single classifier are presented in Fig. 3. Among the five classifiers examined, DT has gained the higher accuracy and SMO presented the lower accuracies. The same explanation is true for recall, precision and F-Measure.

Fig. 3
figure 3

Percentage of classification results obtained from individual classifiers

In supervised learning, Bagging tries to improve the accuracy of the weak classifiers through training the learners in parallel. However, Boosting trains weak classifiers sequentially, where each classifier tries to improve the results of its predecessor. Bagging and Boosting reduce the bias and variance of a single estimate and improve the accuracy of prediction.

In our experiments, Bagging improved the results of three classifiers, DT, SVM, and SMO, while depressed the results of the other two classifiers, NB and ANN. Overall, the best classification results are obtained through DT ensembles with Bagging. Figure 4, presents the results of Bagging ensembles.

Fig. 4
figure 4

Percentage of classification results obtained from each of the classifiers ensembles with Bagging

Boosting does not improve the results of neither single DT nor DT ensembles with Bagging. However, the results of SVM, SMO and NB is improved via Boosting for all criteria. For ANN, Bagging achieved same results as individual ANN (Fig. 5).

Fig. 5
figure 5

Percentage of classification results obtained from each of the classifiers ensembles with Boosting

Although, we expect Bagging and Boosting increase the accuracy of the base classifier, in some cases single classifier has achieved same or even better results. For example, in the case of NB, single NB obtained better results than NB ensembles with Bagging, with 83.3% and 82.6% accuracy, respectively. With ANN, Bagging achieved even worst accuracy than single ANN, with 93.3% and 92.6% accuracy. In addition, ANN ensembles with Boosting achieved same results as single ANN with 93.3% accuracy. Overall, DT ensembles with Bagging achieved the best results among the 15 variations of classifiers ensembles with Bagging and Boosting with 95.3% accuracy, as summarized in Table 3.

Table 3 The results of individual classifiers and their ensembles with Bagging and Boosting

5 Conclusion

The impact of COVID-19 on consumer behavior is research in this paper. A prediction model is proposed to anticipate consumer behavior in online shopping in the COVID-19 pandemic. Five classification models are examined, where Decision tree achieved the best result of 94.6% accuracy. Then, ensembles meta-algorithms, Bagging and Boosting, are used to improve the accuracy of the classifiers. Again, decision tree obtained best results, where DT ensembles with Bagging gained superior results of 95.3% accuracy in compare to other base classifiers ensembles with Bagging and Boosting examined. In addition, correlation analysis is performed to find the most influential features on predicting consumer behavior. Age and Diabetes have found as features that have more impact on consumers’ online purchase behavior. As future research, meta-heuristic algorithms could be examined to gain higher accuracies in consumer behavior prediction. Different classifiers could also be used for the prediction for better accuracy. In addition, a dataset with more features affecting from COVID-19 pandemic could be employed to construct prediction models.