<jupyter_start><jupyter_text>count_vect = CountVectorizer(stop_words='english')X_train_counts = count_vect.fit_transform(train_data['clean_text'])X_train_counts.shape tfidf_transformer = TfidfTransformer()X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)X_train_tfidf.shape text_clf = Pipeline([('vect', CountVectorizer()),                     ('tfidf', TfidfTransformer()),                     ('clf', MultinomialNB()),                    ]) text_clf = text_clf.fit(train.clean_text, train.target_label) predicted = text_clf.predict(test.clean_text)np.mean(predicted == test.target_label)<jupyter_code>vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(train_data.clean_text)
tf_idf = pd.DataFrame(data = X.toarray(), columns=vectorizer.get_feature_names())
tf_idf<jupyter_output><empty_output><jupyter_text>tf_idf_featured = pd.concat([train_data, tf_idf], axis=1) tf_idf_featured.drop(['index', 'id_original', 'text_original', 'clean_text', 'keyword_original', 'location_original', 'hashtags', 'labels'], axis=1, inplace=True)<jupyter_code>tf_idf['target_label'] = train_data['target_label']
train, test = train_test_split(tf_idf, test_size=0.2)
clf = MultinomialNB()
clf.fit(train.drop(['target_label'], axis=1), train.target_label)
predicted = clf.predict(test.drop(['target_label'], axis=1))
np.mean(predicted == test.target_label)
test_data.head()
train_data.tail()
train_test_data = train_data.append(test_data, ignore_index=True)
train_test_data['clean_text'].fillna(" ", inplace=True)
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(train_test_data.clean_text)
tf_idf = pd.DataFrame(data = X.toarray(), columns=vectorizer.get_feature_names())
tf_idf<jupyter_output><empty_output><jupyter_text>tf_idf_featured = pd.concat([train_test_data, tf_idf], axis=1)tf_idf_featured tf_idf_featured.drop(['index', 'id_original', 'text_original', 'clean_text', 'keyword_original', 'location_original', 'hashtags', 'labels'], axis=1, inplace=True)<jupyter_code>train = tf_idf[:7613]
test = tf_idf[7613:]
test
clf = MultinomialNB()
clf.fit(train, train_data.target_label)
predicted = clf.predict(test)
test_data['target'] = predicted
test_data[['id_original', 'target']].rename(columns={'id_original': 'id'}).to_csv('~/Documents/Datos/DataSets/TP2/res_NB_2.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15160599571734476, 'fraction_numerical': 0.007708779443254818, 'mean_word_length': 8.815126050420169, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '256012', 'license': 'MIT', 'n_tokens_mistral': 880, 'n_tokens_neox': 860, 'n_words': 100, 'path': 'TP2/Alejo/1.5_NB.ipynb', 'repo_name': 'aleacevedo/Datos-TP1', 'size': '2335'}