Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leetcode-notes/9296c9790c9e8d92392922a1d1f20ab1 to your computer and use it in GitHub Desktop.
Save leetcode-notes/9296c9790c9e8d92392922a1d1f20ab1 to your computer and use it in GitHub Desktop.
#predicting the streaming kafka messages
consumer = KafkaConsumer('twitter-stream',bootstrap_servers=\['localhost:9092'])
print("Starting ML predictions.")
for message in consumer:
X_new_counts = count_vect.transform([message.value])
X_new_tfidf = tfidf_transformer.transform(X_new_counts)
predicted = load_model.predict(X_new_tfidf)
print(message.value+" => "+fetch_train_dataset(categories).target_names[predicted[0]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment