The biosorption of lead and cobalt from an aqueous solution is studied using Rafsanjan pistachio shell (RPS) as a biosorbent. The amount of removed metal depends on four factors including pH of the aqueous solution, initial concentration of metal (C0), biosorbent dosage (DB), and temperature (T). An efficient set of experiments is obtained in a lab-scale batch study. Feed-forward neural network (FFNN) and genetic programming (GP) methods are used for process modeling. The FFNN formula is further improved using the grey wolf optimization (GWO) algorithm and it converges to the test observations with regression index (R2) of 0.9932 and 0.9908 for Pb(II) and Co(II). The GP formula also gives an R2 value of 0.9657 and 0.9518 for Pb(II) and Co(II) adsorptions respectively. Using the grey wolf optimization (GWO) method proves that at pH ¼ 5, C0 ¼ 10.2 mg/l, DB ¼ 0.8 g/l, and T ¼ 25 C, the adsorption of Pb(II) and Co(II) together can be maximized up to 81.5% and 69.4%, respectively.