This paper provides an attempt to utilize machine learning algorithm, explicitly random-forest algorithm, to optimize the performance of dye sensitized solar cells (DSSCs) in terms of conversion efficiency. The optimization is implemented with respect to both the mesoporous TiO2 active layer thickness and porosity. Herein, the porosity impact is reflected to the model as a variation in the effective refractive index and dye absorption. Database set has been established using our data in the literature as well as numerical data extracted from our numerical model. The random-forest model is used for model regression, prediction, and optimization, reaching 99.87% accuracy. Perfect agreement with experimental data was observed, with 4.17% conversion efficiency.