Fog computing, also known as Edge computing, is an emerging computational paradigm, increasingly utilized in Internet of Things (IoT) applications, particularly those that cannot be served efficiently using Cloud computing due to limitations such as bandwidth, latency, Internet connectivity. At present, the norm is the static allocation of tasks by developers of an application, where some IoT applications are allocated to be performed on the Cloud, some on the Fog, and some on a hybrid Cloud-Fog. The applications are pre-programmed and predefined to be run on a platform, and this is unchangeable at run-time. IoT gateways, which are devices that bridge the IoT local network and the Internet, are in a position to make dynamic adjustments and allocation decision between platforms based upon real-time conditions such as an IoT applications' performance. However, currently there is no (or very little) intelligence embedded into IoT gateways. This paper proposes cognitive IoT gateways powered by cognitive analytics and machine learning to improve the performance of IoT applications. These IoT devices are able to automatically learn and decide when and where to run an application, be that on the Cloud or on the Fog. The dynamic task sharing and platform interchanging will enable the IoT applications to be optimized for multiple objectives including task performance.