Smart cities should use computational systems to reduce human intervention in repetitive tasks as much as possible. Typically, solutions use adaptive applications to continuously and ubiquitously improve intelligent environments’ services, optimizing the use of resources such as electricity or water. This letter evaluates different machine learning algorithms to detect occupancy in smart spaces in the presence of anomalous readings. Additionally, it presents a low-cost wireless sensor network (WSN) to collect the data and give the occupancy inference. We collect the environment data, with the presented WSN, in our university's laboratory. To verify the robustness of algorithms, we randomly insert anomalous sensor readings in the collected data through a Bernoulli distribution process. These anomalies represent different environment events or sensor failures. With these data, we evaluate the random forest (RF), classification and regression tree (Cart), and K-nearest neighbors (k-NN) algorithms. The best performing algorithms were RF and k-NN, presenting close to 99% of accuracy in data without anomalies and 97% in data with 10% of anomalies. However, we observe an average execution time of 2.34 s to k-NN against 25.65 s to RF. Thus, considering our evaluated scenarios, we elect the k-NN as the best algorithm to detect occupation in smart spaces.