text_plain_output_1.png
from sklearn.decomposition import NMF

from sklearn.feature_extraction.text import CountVectorizer

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import re

about_data = pd.read_csv('../input/AboutIsis.csv', encoding='ISO-8859-1')
fanboy_data = pd.read_csv('../input/IsisFanboy.csv', encoding='ISO-8859-1')

about_data.keys()

fanboy_space_split = [str(i).split() for i in fanboy_data['tweets']]
fanboy_handles = [j for i in fanboy_space_split for j in i if '@' in j]
about_space_split = [str(i).split() for i in about_data['tweets']]
about_handles = [j for i in about_space_split for j in i if '@' in j]

import re
fanboy_text = [re.sub('[^a-zA-Z]', ' ', j).lower() for i in fanboy_space_split for j in i if not '@' in j and (not '#' in j)]
about_text = [re.sub('[^a-zA-Z]', ' ', j).lower() for i in about_space_split for j in i if not '@' in j and (not '#' in j)]

from sklearn.feature_extraction.text import CountVectorizer
fc_vectorizer = CountVectorizer(stop_words='english', max_features=1000)
fanboy_counts = fc_vectorizer.fit_transform(fanboy_text)
ac_vectorizer = CountVectorizer(stop_words='english', max_features=1000)
about_counts = ac_vectorizer.fit_transform(about_text)

def print_top_words(model, feature_names, n_top_words):
    pass

from sklearn.decomposition import NMF
n_samples = 2000
n_features = 1000
n_topics = 10
n_top_words = 20
fanboy_nmf = NMF(n_components=n_topics, random_state=1, alpha=0.1, l1_ratio=0.5).fit(fanboy_counts)

about_nmf = NMF(n_components=n_topics, random_state=1, alpha=0.1, l1_ratio=0.5).fit(about_counts)

about_feature_names = ac_vectorizer.get_feature_names()
print_top_words(about_nmf, about_feature_names, n_top_words)