Learning State Machines from data streams and an application in network-based threat detection