Difficulty: Beginner
Estimated Time: 10 minutes

from sklearn.datasets import fetch_20newsgroups from sklearn.feature_extraction.text import CountVectorizer,TfidfTransformer from sklearn.naive_bayes import MultinomialNB from sklearn.pipeline import Pipeline

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

categories = ['alt.atheism','soc.religion.christian','comp.graphics','sci.med'] twenty_train = fetch_20newsgroups(subset='train', categories=categories,shuffle=True,random_state=42)

print(type(twenty_train.data)) print(type(twenty_train.target))

text_clf = Pipeline([('vect',CountVectorizer()), ('tfidf',TfidfTransformer()), ('clf',MultinomialNB())]) text_clf.fit(twenty_train.data,twenty_train.target)

docs_new = ['God is Love','Nvidia card','Disbelieves in God']

predicted = text_clf.predict(docs_new) print(predicted) for doc,category in zip(docs_new,predicted): print('%r => %s'%(doc,twenty_train.target_names[category]))

newsgroup 2

This tab will not be visible to users and provides only information to help authors when creating content.

Creating Katacoda Scenarios

Thanks for creating Katacoda scenarios. This tab is designed to help you as an author have quick access the information you need when creating scenarios.

Here are some useful links to get you started.

Running Katacoda Workshops

If you are planning to use Katacoda for workshops, please contact [email protected] to arrange capacity.

Debugging Scenarios

Below is the response from any background scripts run or files uploaded. This stream can aid debugging scenarios.

If you still need assistance, please contact [email protected]