<jupyter_start><jupyter_text>1. Split the data into test and train 2. tfidf3. multinomialNB()<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(df['text'], df['author'], random_state = 0)
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(X_train)
tfidf_transformer = TfidfTransformer()
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
clf = MultinomialNB().fit(X_train_tfidf, y_train)

# predict the text writing style 
print(clf.predict(count_vect.transform(["It never once occurred to me that the fumbling might be a mere mistake."])))

print(clf.predict(count_vect.transform(["How lovely is spring As we looked from Windsor Terrace on the sixteen fertile counties spread beneath, speckled by happy cottages and wealthier towns, all looked as in former years, heart cheering and fair."])))

print(clf.predict(count_vect.transform(["<NAME> needed fresh bodies because his life work was the reanimation of the dead."])))


model = MultinomialNB()
X_train, X_test, y_train, y_test, indices_train, indices_test = train_test_split(features, labels, df.index, test_size=0.33, random_state=0)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
from sklearn.metrics import confusion_matrix
conf_mat = confusion_matrix(y_test, y_pred)
fig, ax = plt.subplots(figsize=(10,10))
sns.heatmap(conf_mat, annot=True, fmt='d',
            xticklabels=category_id_df.author.values, yticklabels=category_id_df.author.values)
plt.ylabel('Actual')
plt.xlabel('Predicted')
plt.title('Confusion Metric for Multinomial Nieve Bayes Classifer \n')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10775862068965517, 'fraction_numerical': 0.007389162561576354, 'mean_word_length': 7.08457711442786, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '311581', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 580, 'n_tokens_neox': 555, 'n_words': 139, 'path': 'TextClassification.ipynb', 'repo_name': 'khanmbjob/python', 'size': '1630'}