Modeling viscosity of crude oil using k-nearest neighbor algorithm

Mohammad Reza Mahdiani, Ehsan Khamehchi, Sassan Hajirezaie, Abdolhossein Hemmati-Sarapardeh

Abstract view|337|times       PDF download|197|times Supplements download|27|times


Oil viscosity is an important factor in every project of the petroleum industry. These processes can range from gas injection to oil reservoirs to comprehensive reservoir simulation studies. Different experimental approaches have been proposed for measuring oil viscosity. However, these methods are often time taking, cumbersome and at some physical conditions, impossible. Therefore, development of predictive models for estimating this parameter is crucial. In this study, three new machine learning based models are developed to estimate the oil viscosity. These approaches are genetic programing, k-nearest neighbor (KNN) and linear discriminant analysis. Oil gravity and temperature were the input parameters of the models. Various graphical and statistical error analyses were used to measure the performance of the developed models. Also, comparison study between the developed models and the well-known previously published models was conducted. Moreover, trend analysis was performed to compare the predictions of the models with the trend of experimental data. The results indicated that the developed models outperform all of the previously published models by showing negligible prediction errors. Among the developed models, the KNN model has the highest accuracy by showing an overall mean absolute error of 8.54%. The results show that the new developed models in this study can be potentially utilized in reservoir simulation packages of the petroleum industry.

Cited as: Mahdiani, M.R., Khamehchi, E., Hajirezaie, S., Hemmati-Sarapardeh, A. Modeling viscosity of crude oil using k-nearest neighbor algorithm. Advances in Geo-Energy Research, 2020, 4(4): 435-447, doi: 10.46690/ager.2020.04.08


Oil viscosity, machine learning, k-nearest neighbor, genetic programming, linear discriminant analysis

Full Text:

PDF Supplements


Abbruzzo, A., Tambur, E., Varrica, D., et al. Penalized linear discriminant analysis and discrete adaboost to distinguish human hair metal profiles: The case of adolescents residing near mt. Etna. Chemosphere 2016, 153: 100-106.

Abubakar, A., Al-Wahaibi, Y., Al-Wahaibi, T., et al. Effect of low interfacial tension on flow patterns, pressure gradients and holdups of medium-viscosity oil/water flow in horizontal pipe. Exp. Therm. Fluid Sci. 2015, 68: 58-67.

Affenzeller, M., Wagner, S., Winkler, S., et al. Genetic Algorithms and Genetic Programming: Modern Concepts and Practical Applications. Boca Raton, USA, Crc Press, 2009.

Al-Khafaji, A.H., Abdul-Majeed, G.H., Hassoon, S.F., et al. Viscosity correlation for dead, live and undersaturated crude oils. J. Pet. Res. 1987, 6(2): 1-16.

Al-Maamari, R.S., Houache, O., Abdul-Wahab, S.A. New correlating parameter for the viscosity of heavy crude oils. Energy Fuels 2006, 20(6): 2586-2592.

Al-Sarkhi, A., Pereyra, E., Sarica, C., et al. Positive frictional pressure gradient in vertical gas-high viscosity oil slug flow. Int. J. Heat Fluid Flow 2016, 59: 50-61.

Alomair, O., Elsharkawy, A., Alkandari, H. A viscosity prediction model for kuwaiti heavy crude oils at elevated temperatures. J. Pet. Sci. Eng. 2014, 120: 102-110.

Baraldi, P., Cannarile, F., Di Maio, F., et al. Hierarchical k-nearest neighbours classification and binary differential evolution for fault diagnostics of automotive bearings operating under variable conditions. Eng. Appl. Artif. Intell. 2016, 56: 1-13.

Barati-Harooni, A., Najafi-Marghmaleki, A. An accurate rbf-nn model for estimation of viscosity of nanofluids. J. Mol. Liq. 2016, 224: 580-588.

Barrufeta, M.A., Dexheimerb, D. Use of an automatic data quality control algorithm for crude oil viscosity data. Fluid Phase Equilib. 2004, 219(2): 113-121.

Beal, C. The viscosity of air, water, natural gas, crude oil and its associated gases at oil field temperatures and pressures. Trans. AIME 1946, 165(1): 94-115.

Beggs, D.H., Robinson, J.R. Estimating the viscosity of crude oil systems. J. Pet. Technol. 1975, 27(9): 1140-1141.

Bennison, T. Prediction of heavy oil viscosity. Paper Presented at IBC Heavy Oil Field Development Conference, 1998.

Chen, C.-H., Huang, W.-T., Tan, T.-H., et al. Using k-nearest neighbor classification to diagnose abnormal lung sounds. Sensors 2015, 15(6): 13132-13158.

Chen, S.-H. Genetic Algorithms and Genetic Programming in Computational Finance. Berlin, Germany, Springer, 2012.

Cios, K.J., Pedryc, W., Swin, R.W. Data Mining: A knowledge Discovery Approach. Berlin, Germany, Springer, 2007.

Close, M.E., Abraham, P., Humphries, B., et al. Predicting groundwater redox status on a regional scale using linear discriminant analysis. J. Contam. Hydrol. 2016, 191: 19-32.

Croft, G.D., Patzek, T.W. The future of california’s oil supply. Paper SPE 120174 Presented at SPE Western Regional Meeting, San Jose, California, 24-26 March, 2009.

Daridon, J.L., Orlandi, E., Carrier, H. Measurement of bubble point pressure in crude oils using an acoustic wave sensor. Fluid Phase Equilib. 2016, 427: 152-160.

De Ghetto, G., Paone, F., Villa, M. Pressure-volume-temperature correlations for heavy and extra heavy oils. Paper SPE 30316 Presented at SPE International Heavy Oil Symposium, Calgary, Alberta, Canada, 19-21 June, 1995.

Degiorgis, G., Maturano, S., Garay, M., et al. Oil mixture viscosity behavior: Use in pipeline design. Paper SPE 69420 Presented at SPE Latin American and Caribbean Petroleum Engineering Conference, Buenos Aires, Argentina, 25-28 March, 2001.

Dehaghani, A.H.S., Badizad, M.H. Experimental study of iranian heavy crude oil viscosity reduction by diluting with heptane, methanol, toluene, gas condensate and naphtha. Petroleum 2016, 2(4): 415-424.

Deng, H., Miao, D., Lei, J. Artificial Intelligence and Computational Intelligence. Berlin, Germany, Springer, 2011.

Dutt, N.V.K. A simple method of estimating the viscosity of petroleum crude oil and fractions. Chem. Eng. J. 1990, 45(2): 83-86.

Egbogah, E.O., Ng, J.T. An improved temperature-viscosity correlation for crude oil systems. J. Pet. Sci. Eng. 1990, 4(3): 197-200.

Elsharkawy, A.M., Alikhan, A.A. Models for predicting the viscosity of middle east crude oils. Fuel 1999, 78(8): 891-903.

Ershadnia, R., Amooie, M.A., Shams, R., et al. Non-newtonian fluid flow dynamics in rotating annular media: Physics-based and data-driven modeling. J. Pet. Sci. Eng. 2020, 185: 106641.

Everett, J., Weinaug, C.F. Physical properties of eastern kansas crude oils. Kansas Geological Survey, 1955.

Faradonbeh, R.S., Armaghani, D.J., Monjezi, M., et al. Genetic programming and gene expression programming for flyrock assessment due to mine blasting. Int. J. Rock Mech. Min. Sci. 2016, 88: 254-264.

Galdames, P. Managing continuous k-nearest neighbor queries in mobile peer-to-peer networks. Lowa State, Lowa State University, 2008.

Gandomi, A.H., Sajedi, S., Kiani, B., et al. Genetic program-ming for experimental big data mining: A case study on concrete creep formulation. Autom. Constr. 2016, 70: 89-97.

Glaso, O. Generalized pressure-volume-temperature correla-tions. J. Pet. Technol. 1980, 32(5): 785-795.

Gnanadesikan, R. Discriminant Analysis and Clustering. Washington, USA, National Achademy Press, 1988.

Hemmati-Sarapardeh, A., Aminshahidy, B., Pajouhandeh, A., et al. A soft computing approach for the determination of crude oil viscosity: Light and intermediate crude oil systems. J. Taiwan Inst. Chem. Eng. 2016, 59: 1-10.

Hemmati-Sarapardeh, A., Khishvan, M., Naseri, A., et al. Toward reservoir oil viscosity correlation. Chem. Eng. Sci. 2013, 90: 53-68.

Hemmati-Sarapardeh, A., Majidi, S., Mahmoudi, B., et al. Experimental measurement and modeling of saturated reservoir oil viscosity. Korean J. Chem. Eng. 2014, 31(7): 1253-1264.

Hien, N.T., Tran, C.T., Nguye, X.H. Genetic programming for storm surge forecasting. Ocean Eng. 2020, 215: 107812.

Hossain, M.S., Sarica, C., Zhang, H.-Q., et al. Assessment and development of heavy oil viscosity correlations. Paper SPE 97907 Presented at SPE International Thermal Operations and Heavy Oil Symposium, Calgary, Alberta, Canada, 1-3 November, 2005.

Hosseinifar, P., Jamshidi, S. A new correlative model for viscosity estimation of pure components, bitumens, size-asymmetric mixtures and reservoir fluids. J. Pet. Sci. Eng. 2016, 147: 624-635.

Hu, J., Peng, H., Wang, J., et al. Knn-p: A knn classifier optimized by p systems. Theor. Comput. Sci. 2020, 817: 55-65.

Huang, J., Perry, M. A semi-empirical approach using gradient boosting and kk-nearest neighbors regression for gefcom2014 probabilistic solar power forecasting. Int. J. Forecast. 2016, 32(3): 1081-1086.

Ilieva, P., Kilzer, A., Weidner, E. Measurement of solubility, viscosity, density and interfacial tension of the systems tristearin and CO2 and rapeseed oil and CO2 . J. Supercrit. Fluids 2016, 117: 40-49.

Ilyin, S., Arinina, M., Polyakova, M., et al. Asphaltenes in heavy crude oil: Designation, precipitation, solutions, and effects on viscosity. J. Pet. Sci. Eng. 2016, 147: 211-217.

Kartoatmodjo, T., Schmidt, Z. Large data bank improves crude physical property correlations. Oil Gas J. 1994, 92(27): 51-55.

Kaydani, H., Mohebbi, A., Hajizadeh, A. Dew point pressure model for gas condensate reservoirs based on multi-gene genetic programming approach. Appl. Soft Comput. 2016, 47: 168-178.

Kaye, S.E. Offshore california viscosity correlations. COFRC, 1985.

Khamehchi, E., Mahdiani, M.R. Optimization Algorithms, in Gas Allocation Optimization Methods in Artificial Gas Lift. Berlin, Germany, Springer, 2017.

Khamehchi, E., Mahdiani, M.R., Amooie, M.A., et al. Modeling viscosity of light and intermediate dead oil systems using advanced computational frameworks and artificial neural networks. J. Pet. Sci. Eng. 2020, 193: 107388.

Khamehchi, E., Mahdiani, M.R., Suratgar, A.A. Optimizing and stabilizing the gas lift operation by controlling the lift gas specific gravity. J. Pet. Sci. Technol. 2019, 9(3): 46-63.

Khamehchi, E., Mohammad, Z., Mahdiani, M.R. A robust method for estimating the two-phase flow rate of oil and gas using wellhead data. J. Pet. Explor. Prod. Technol. 2020, 10(6): 2335-2347.

Khan, S.A., Al-Marhoun, M.A., Duffuaa, S.O., et al. Viscosity correlations for saudi arabian crude oils. Paper SPE 15720 Presented at Society of Petroleum Engineers, Bahrain, 7-10 March, 1987.

Kleinhans, A., Hornfischer, B., Gaukel, V., et al. Influence of viscosity ratio and initial oil drop size on the oil drop breakup during effervescent atomization. Chem. Eng. Process. 2016, 109: 149-157.

Labedi, R. Improved correlations for predicting the viscosity of light crudes. J. Pet. Sci. Eng. 1992, 8(3): 221-234.

Labedi, R.M. Pvt correlations of the african crudes. Colorado, Colorado School of Mines, 1982.

Langdon, W.B. Genetic Programming and Data Structures: Genetic Programming + Data Structures = Automatic Programming. Berlin, Germany, Springer, 2012.

Langdon, W.B., Poli, R. Foundations of Genetic Programming. Berlin, GER, Springer, 2002.

Larose, D.T., Larose, C.D. Discovering Knowledge in Data: An Introduction to Data Mining. Hoboken, USA, John Wiley & Sons, 2014.

Li, H., Li, Q., Liu, R. Consistent model specification tests based on kk-nearest-neighbor estimation method. J. Econom. 2016, 194(1): 187-202.

Li, Z., Hao, K., Lei, C., et al. Pet viscosity prediction using jit-based extreme learning machine. IFAC-PapersOnLine 2018, 51(18): 608-613.

Mahdiani, M.R., Khamehchi, E. A new method for building proxy models using simulated annealing. Middle-East J. Sci. Res. 2014, 22(3): 324-328.

Mahdiani, M.R., Khamehchi, E. Preventing instability phe-nomenon in gas-lift optimization. Iran. J. Oil Gas Sci. Technol. 2015a, 4(1): 49-65.

Mahdiani, M.R., Khamehchi, E. Stabilizing gas lift optimiza-tion with different amounts of available lift gas. J. Nat. Gas Sci. Eng. 2015b, 26: 18-27.

Mahdiani, M.R., Khamehchi, E. A novel model for predicting the temperature profile in gas lift wells. Petroleum 2016, 2(4): 408-414.

Mahdiani, M.R., Kooti, G. The most accurate heuristic-based algorithms for estimating the oil formation volume factor. Petroleum 2016, 2(1): 40-48.

McLachlan, G.J. Discriminant Analysis and Statistical Pattern Recognition. Hoboken, USA, John Wiley & Sons, 2004.

Mehrotra, A.K. Generalized one-parameter viscosity equation for light and medium liquid hydrocarbons. Ind. Eng. Chem. Res. 1991, 30(6): 1367-1372.

Miadonye, A., Singh, B., Puttagunta, V.R. One-parameter correlation in the estimation of crude oil viscosity. SPE 1992.

Mucherino, A., Papajorgji, P.J., Pardalos, P.M. Data Mining in Agriculture. Berlin, Germany, Springer, 2009.

Naseri, A., Nikazar, M., Mousavi Dehghani, S.A. A correlation approach for prediction of crude oil viscosities. J. Pet. Sci. Eng. 2005, 47(3-4): 163-174.

Naseri, A., Yousefi, S., Sanaei, A., et al. A neural network model and an updated correlation for estimation of dead crude oil viscosity. Braz. J. Pet. Gas 2012, 6(1): 31-41.

Norouzi, M., Panjalizadeh, H., Rashidi, F., et al. Dpr polymer gel treatment in oil reservoirs: A workflow for treatment optimization using static proxy models. J. Pet. Sci. Eng. 2017, 153: 97-110.

Omole, O., Falode, O.A., Deng, A.D.A. Prediction of nigerian crude oil viscosity using artificial neural network. Pet. Coal. 2009, 51(3): 181-188.

Papadopoulos, A.N. Nearest Neighbor Search: A Database Perspective. Berlin, Germany, Springer, 2006.

Parsi, M., Vieira, R.E., Torres, C.F., et al. On the effect of liquid viscosity on interfacial structures within churn flow: Experimental study using wire mesh sensor. Chem. Eng. Sci. 2015, 130: 221-238.

Petrosky, J., Farshad, F.F. Viscosity correlations for gulf of mexico crude oils. Paper SPE 29468 Presented at SPE Production Operations Symposium, Oklahoma, USA, 2-4 April 1995.

Poli, R., Langdon, W.B., McPhee, N.F., et al. A Field Guide to Genetic Programming. Lulu. com, 2008.

Promchan, J., G ¨unther, D., Siripinyanond, A., et al. Elemental imaging and classifying rice grains by using laser ablation inductively coupled plasma mass spectrometry and linear discriminant analysis. J. Cereal Sci. 2016, 71: 198-203.

Sadeghi, M.B., Ramazani S.A., A., Taghikhani, V., et al. Ex-perimental investigation of rheological and morphological properties of water in crude oil emulsions stabilized by a lipophilic surfactant. J. Dispersion Sci. Technol. 2013, 34(3): 356-368.

Sakthipriya, N., Doble, M., Sangwai, J.S. Fast degradation and viscosity reduction of waxy crude oil and model waxy crude oil using bacillus subtilis. J. Pet. Sci. Eng. 2015, 134: 158-166.

Salehinia, S., Salehinia, Y., Alimadadi, F., et al. Forecasting density, oil formation volume factor and bubble point pressure of crude oil systems based on nonlinear system identification approach. J. Pet. Sci. Eng. 2016, 147: 47-55.

Shetty, N., Deshannavar, U.B., Marappagounder, R., et al. Improved threshold fouling models for crude oils. Energy 2016, 111: 453-467.

Svrcek, W.Y., Mehrotra, A.K. One parameter correlation for bitumen viscosity. Chem. Eng. Res. Des. 1998, 66(4): 323-327.

Talebkeikhah, M., Amar, M.N., Naseri, A., et al. Experimental measurement and compositional modeling of crude oil viscosity at reservoir conditions. J. Taiwan Inst. Chem. Eng. 2020, 109: 35-50.

Tanveer, M., Shubham, K., Aldhaifallah, M., et al. An efficient regularized k-nearest neighbor based weighted twin support vector regression. Knowledge-Based Syst. 2016, 94: 70-87.

Trifonov, M.I., Lalyko, L.B. Iterative fisher linear discriminant analysis. Patent, U.S., 2010.

Wen, J., Zhang, J., Wei, M. Effective viscosity prediction of crude oil-water mixtures with high water fraction. J. Pet. Sci. Eng. 2016, 147: 760-770.

Whitson, C.H., Brul ´e, M.R. Phase Behavior. Texas, USA, Society of Petroleum Engineers Inc., 2000.

Xu, Y. K-nearest neighbor-based weighted multi-class twin support vector machine. Neurocomputing 2016, 205: 430-438.

Xu, Y., Ayala-Orozco, C., Chiang, P.-T., et al. Understanding the role of iron (iii) tosylate on heavy oil viscosity reduction. Fuel 2020, 274: 117808.

Zhang, J., Yuan, H., Zhao, J., et al. Viscosity estimation and component identification for an oil-water emulsion with the inversion method. Appl. Therm. Eng. 2017, 111: 759-767.


  • There are currently no refbacks.

Copyright (c) 2020 The Author(s)

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Copyright ©2018. All Rights Reserved