Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created July 3, 2020 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save velotiotech/4c3ee4b7851ef02d114bd8cbd8c3a726 to your computer and use it in GitHub Desktop.
Save velotiotech/4c3ee4b7851ef02d114bd8cbd8c3a726 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