The number of IoT devices at the edge of the network is increasing rapidly. Data from IoT devices can be analysed locally at the edge, or they may be sent to the cloud. Currently, the decision to deploy a task for execution at the edge or in the cloud is not decided as the data are received. Instead the decision is usually based on pre-defined system design and corresponding assumptions about locality and connectivity. However, the mobile environment has rapid, sometimes unpredictable changes and requires a system that can dynamically adapt to these changes. An intelligent platform is required that can discover available resources (both nearby and in the cloud) and autonomously orchestrate a seamless and transparent task allocation at runtime to help the IoT devices achieve their best performance given the available resources. We propose a new platform, DEFT (Dynamic Edge-Fabric environmenT), that can automatically learn where best to execute each task based on real-time system status and task requirements, along with learned behavior from past performance of the available resources. The task allocation decision in this platform is powered by machine learning techniques such as regression models (linear, ridge, Lasso) and ensemble models (random forest, extra trees). We have implemented this platform on heterogeneous devices and run various IoT tasks on the devices. The results reveal that choosing proper machine learning approaches based on the tasks properties and priorities can significantly improve the overall performance of selecting resources (either from the edge or cloud) dynamically at runtime.