Extreme learning machines (ELMs), single hidden-layer feedforward neural networks, are renowned for their speed and efficiency in classification and regression tasks. However, their generalization ability is often undermined by the random generation of hidden layer weights and biases. To address this issue, this paper introduces a Hierarchical Learning-based Chaotic Crayfish Optimization Algorithm (HLCCOA) aimed at enhancing the generalization ability of ELMs. Initially, to resolve the problems of slow search speed and premature convergence typical of traditional crayfish optimization algorithms (COAs), the HLCCOA utilizes chaotic sequences for population position initialization. The ergodicity of chaos is leveraged to boost population diversity, laying the groundwork for effective global search efforts. Additionally, a hierarchical learning mechanism encourages under-performing individuals to engage in extensive cross-layer learning for enhanced global exploration, while top performers directly learn from elite individuals at the highest layer to improve their local exploitation abilities. Rigorous testing with CEC2019 and CEC2022 suites shows the HLCCOA’s superiority over both the original COA and nine renowned heuristic algorithms. Ultimately, the HLCCOA-optimized extreme learning machine model, the HLCCOA-ELM, exhibits superior performance over reported benchmark models in terms of accuracy, sensitivity, and specificity for UCI breast cancer diagnosis, underscoring the HLCCOA’s practicality and robustness, as well as the HLCCOA-ELM’s commendable generalization performance.