Forecasting Solar Power is an important aspect for power trading companies. It helps in energy bidding, planning, and control. The challenge in forecasting is to predict nonlinear data, which can be fulfilled by the computation technique and machine learning model. ML models have high accuracy for time-series forecasting, but their accuracy is poor for nonlinear forecasting. To enhance the ML model for nonlinear prediction, an optimization algorithm is used for training. This paper presents how the computation technique is incorporated into the machine learning model and compared it with the conventional model. CSA-ANN and SOA-ANN models are developed and forecast solar power for a-day-ahead, three-day-ahead, and a week-ahead solar power generation by considering time, irradiation, and temperature as input parameters for the model. The models are compared with ANN, DE-ANN, and PSO-ANN since these models are widely used. Upon comparison, ANN gives the best result for short-term prediction but is unable to predict midterm and long-term predictions, whereas this problem is overcome by SOA-ANN, which is done by changing its training algorithm, and its performance is measured via statistical parameters such as MAE, MSE, MAPE, and R2. The percentage improvement of SOA-ANN is obtained with these statistical parameters as 6.54%, 16.05%, 1.67%, and 3.61%. Hence, SOA-ANN gives best result as compared to other models.