OctoMap is a popular 3D mapping framework which can model the data consistently and keep the 3D models compact with the octree. However, the occupancy map derived by OctoMap can be incorrect when the input point clouds are with noisy measurements. Point cloud filters can reduce the noisy data, but it is unreasonable to apply filters in a sparse point cloud. In this paper, we present a k-nearest neighbours (k-NN) based inverse sensor model for occupancy mapping. This method represents the occupancy information of one point with the average distance from the point to its k-NN in the point cloud. The average distances derived by all the points and their corresponding k-NN are assumed to be normally distributed. Our inverse sensor model is presented based on this normal distribution. The proposed approach is able to deal with sparse and noisy point clouds. We implement the model in the OctoMap to carry out experiments in the real environment. The experimental results show that the 3D occupancy map generated by our approach is more reliable than that generated by the inverse sensor model in OctoMap.