Obtaining accurate and precise masses and ages for large numbers of giant stars is of great importance for unraveling the assemblage history of the Galaxy. In this paper, we estimate masses and ages of 6940 red giant branch (RGB) stars with asteroseismic parameters deduced from emph{Kepler} photometry and stellar atmospheric parameters derived from LAMOST spectra. The typical uncertainties of mass is a few per cent, and that of age is $sim$,20 per cent. The sample stars reveal two separate sequences in the age -- [$alpha$/Fe] relation -- a high--$alpha$ sequence with stars older than $sim$,8,Gyr and a low--$alpha$ sequence composed of stars with ages ranging from younger than 1,Gyr to older than 11,Gyr. We further investigate the feasibility of deducing ages and masses directly from LAMOST spectra with a machine learning method based on kernel based principal component analysis, taking a sub-sample of these RGB stars as a training data set. We demonstrate that ages thus derived achieve an accuracy of $sim$,24 per cent. We also explored the feasibility of estimating ages and masses based on the spectroscopically measured carbon and nitrogen abundances. The results are quite satisfactory and significantly improved compared to the previous studies.