partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | coarse_tag_str | Convert POS sequence to our coarse system, formatted as a string. | scattertext/external/phrasemachine/phrasemachine.py | def coarse_tag_str(pos_seq):
"""Convert POS sequence to our coarse system, formatted as a string."""
global tag2coarse
tags = [tag2coarse.get(tag, 'O') for tag in pos_seq]
return ''.join(tags) | def coarse_tag_str(pos_seq):
"""Convert POS sequence to our coarse system, formatted as a string."""
global tag2coarse
tags = [tag2coarse.get(tag, 'O') for tag in pos_seq]
return ''.join(tags) | [
"Convert",
"POS",
"sequence",
"to",
"our",
"coarse",
"system",
"formatted",
"as",
"a",
"string",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/external/phrasemachine/phrasemachine.py#L65-L69 | [
"def",
"coarse_tag_str",
"(",
"pos_seq",
")",
":",
"global",
"tag2coarse",
"tags",
"=",
"[",
"tag2coarse",
".",
"get",
"(",
"tag",
",",
"'O'",
")",
"for",
"tag",
"in",
"pos_seq",
"]",
"return",
"''",
".",
"join",
"(",
"tags",
")"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | extract_finditer | The "GreedyFSA" method in Handler et al. 2016.
Returns token position spans of valid ngrams. | scattertext/external/phrasemachine/phrasemachine.py | def extract_finditer(pos_seq, regex=SimpleNP):
"""The "GreedyFSA" method in Handler et al. 2016.
Returns token position spans of valid ngrams."""
ss = coarse_tag_str(pos_seq)
def gen():
for m in re.finditer(regex, ss):
yield (m.start(), m.end())
return list(gen()) | def extract_finditer(pos_seq, regex=SimpleNP):
"""The "GreedyFSA" method in Handler et al. 2016.
Returns token position spans of valid ngrams."""
ss = coarse_tag_str(pos_seq)
def gen():
for m in re.finditer(regex, ss):
yield (m.start(), m.end())
return list(gen()) | [
"The",
"GreedyFSA",
"method",
"in",
"Handler",
"et",
"al",
".",
"2016",
".",
"Returns",
"token",
"position",
"spans",
"of",
"valid",
"ngrams",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/external/phrasemachine/phrasemachine.py#L78-L87 | [
"def",
"extract_finditer",
"(",
"pos_seq",
",",
"regex",
"=",
"SimpleNP",
")",
":",
"ss",
"=",
"coarse_tag_str",
"(",
"pos_seq",
")",
"def",
"gen",
"(",
")",
":",
"for",
"m",
"in",
"re",
".",
"finditer",
"(",
"regex",
",",
"ss",
")",
":",
"yield",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | extract_ngram_filter | The "FilterFSA" method in Handler et al. 2016.
Returns token position spans of valid ngrams. | scattertext/external/phrasemachine/phrasemachine.py | def extract_ngram_filter(pos_seq, regex=SimpleNP, minlen=1, maxlen=8):
"""The "FilterFSA" method in Handler et al. 2016.
Returns token position spans of valid ngrams."""
ss = coarse_tag_str(pos_seq)
def gen():
for s in xrange(len(ss)):
for n in xrange(minlen, 1 + min(maxlen, len(ss) - s)):
e = s + n
s... | def extract_ngram_filter(pos_seq, regex=SimpleNP, minlen=1, maxlen=8):
"""The "FilterFSA" method in Handler et al. 2016.
Returns token position spans of valid ngrams."""
ss = coarse_tag_str(pos_seq)
def gen():
for s in xrange(len(ss)):
for n in xrange(minlen, 1 + min(maxlen, len(ss) - s)):
e = s + n
s... | [
"The",
"FilterFSA",
"method",
"in",
"Handler",
"et",
"al",
".",
"2016",
".",
"Returns",
"token",
"position",
"spans",
"of",
"valid",
"ngrams",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/external/phrasemachine/phrasemachine.py#L90-L103 | [
"def",
"extract_ngram_filter",
"(",
"pos_seq",
",",
"regex",
"=",
"SimpleNP",
",",
"minlen",
"=",
"1",
",",
"maxlen",
"=",
"8",
")",
":",
"ss",
"=",
"coarse_tag_str",
"(",
"pos_seq",
")",
"def",
"gen",
"(",
")",
":",
"for",
"s",
"in",
"xrange",
"(",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | extract_JK | The 'JK' method in Handler et al. 2016.
Returns token positions of valid ngrams. | scattertext/external/phrasemachine/phrasemachine.py | def extract_JK(pos_seq):
"""The 'JK' method in Handler et al. 2016.
Returns token positions of valid ngrams."""
def find_ngrams(input_list, num_):
'''get ngrams of len n from input list'''
return zip(*[input_list[i:] for i in range(num_)])
# copied from M and S chp 5'''
patterns = set(['AN', 'NN', 'AAN', 'AN... | def extract_JK(pos_seq):
"""The 'JK' method in Handler et al. 2016.
Returns token positions of valid ngrams."""
def find_ngrams(input_list, num_):
'''get ngrams of len n from input list'''
return zip(*[input_list[i:] for i in range(num_)])
# copied from M and S chp 5'''
patterns = set(['AN', 'NN', 'AAN', 'AN... | [
"The",
"JK",
"method",
"in",
"Handler",
"et",
"al",
".",
"2016",
".",
"Returns",
"token",
"positions",
"of",
"valid",
"ngrams",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/external/phrasemachine/phrasemachine.py#L106-L127 | [
"def",
"extract_JK",
"(",
"pos_seq",
")",
":",
"def",
"find_ngrams",
"(",
"input_list",
",",
"num_",
")",
":",
"'''get ngrams of len n from input list'''",
"return",
"zip",
"(",
"*",
"[",
"input_list",
"[",
"i",
":",
"]",
"for",
"i",
"in",
"range",
"(",
"n... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | get_phrases | Give a text (or POS tag sequence), return the phrases matching the given
grammar. Works on documents or sentences.
Returns a dict with one or more keys with the phrase information.
text: the text of the document. If supplied, we will try to POS tag it.
You can also do your own tokenzation and/or tagging and sup... | scattertext/external/phrasemachine/phrasemachine.py | def get_phrases(text=None, tokens=None, postags=None, tagger='nltk', grammar='SimpleNP', regex=None, minlen=2, maxlen=8,
output='counts'):
"""Give a text (or POS tag sequence), return the phrases matching the given
grammar. Works on documents or sentences.
Returns a dict with one or more keys with t... | def get_phrases(text=None, tokens=None, postags=None, tagger='nltk', grammar='SimpleNP', regex=None, minlen=2, maxlen=8,
output='counts'):
"""Give a text (or POS tag sequence), return the phrases matching the given
grammar. Works on documents or sentences.
Returns a dict with one or more keys with t... | [
"Give",
"a",
"text",
"(",
"or",
"POS",
"tag",
"sequence",
")",
"return",
"the",
"phrases",
"matching",
"the",
"given",
"grammar",
".",
"Works",
"on",
"documents",
"or",
"sentences",
".",
"Returns",
"a",
"dict",
"with",
"one",
"or",
"more",
"keys",
"with"... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/external/phrasemachine/phrasemachine.py#L276-L363 | [
"def",
"get_phrases",
"(",
"text",
"=",
"None",
",",
"tokens",
"=",
"None",
",",
"postags",
"=",
"None",
",",
"tagger",
"=",
"'nltk'",
",",
"grammar",
"=",
"'SimpleNP'",
",",
"regex",
"=",
"None",
",",
"minlen",
"=",
"2",
",",
"maxlen",
"=",
"8",
"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | NLTKTagger.tag_text | take input text and return tokens w/ part of speech tags using NLTK | scattertext/external/phrasemachine/phrasemachine.py | def tag_text(self, text):
'''take input text and return tokens w/ part of speech tags using NLTK'''
# putting import here instead of top of file b.c. not all will have nltk installed
sents = self.sent_detector.tokenize(text) # TODO: this will fail on some unicode chars. I think assumes ascii
word_pos_pairs = ... | def tag_text(self, text):
'''take input text and return tokens w/ part of speech tags using NLTK'''
# putting import here instead of top of file b.c. not all will have nltk installed
sents = self.sent_detector.tokenize(text) # TODO: this will fail on some unicode chars. I think assumes ascii
word_pos_pairs = ... | [
"take",
"input",
"text",
"and",
"return",
"tokens",
"w",
"/",
"part",
"of",
"speech",
"tags",
"using",
"NLTK"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/external/phrasemachine/phrasemachine.py#L195-L207 | [
"def",
"tag_text",
"(",
"self",
",",
"text",
")",
":",
"# putting import here instead of top of file b.c. not all will have nltk installed",
"sents",
"=",
"self",
".",
"sent_detector",
".",
"tokenize",
"(",
"text",
")",
"# TODO: this will fail on some unicode chars. I think ass... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CorpusFromFeatureDict.build | Constructs the term doc matrix.
Returns
-------
scattertext.ParsedCorpus.ParsedCorpus | scattertext/CorpusFromFeatureDict.py | def build(self):
'''Constructs the term doc matrix.
Returns
-------
scattertext.ParsedCorpus.ParsedCorpus
'''
self._y = self._get_y_and_populate_category_idx_store()
self._df.apply(self._add_to_x_factory, axis=1)
self._X = self._X_factory.set_last_row_idx(len(self._y) - 1).get_csr_matrix()
self._mX =... | def build(self):
'''Constructs the term doc matrix.
Returns
-------
scattertext.ParsedCorpus.ParsedCorpus
'''
self._y = self._get_y_and_populate_category_idx_store()
self._df.apply(self._add_to_x_factory, axis=1)
self._X = self._X_factory.set_last_row_idx(len(self._y) - 1).get_csr_matrix()
self._mX =... | [
"Constructs",
"the",
"term",
"doc",
"matrix",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/CorpusFromFeatureDict.py#L46-L75 | [
"def",
"build",
"(",
"self",
")",
":",
"self",
".",
"_y",
"=",
"self",
".",
"_get_y_and_populate_category_idx_store",
"(",
")",
"self",
".",
"_df",
".",
"apply",
"(",
"self",
".",
"_add_to_x_factory",
",",
"axis",
"=",
"1",
")",
"self",
".",
"_X",
"=",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CombineDocsIntoDomains.get_new_term_doc_mat | Combines documents together that are in the same domain
Parameters
----------
doc_domains : array-like
Returns
-------
scipy.sparse.csr_matrix | scattertext/domain/CombineDocsIntoDomains.py | def get_new_term_doc_mat(self, doc_domains):
'''
Combines documents together that are in the same domain
Parameters
----------
doc_domains : array-like
Returns
-------
scipy.sparse.csr_matrix
'''
assert len(doc_domains) == self.term_doc_matrix.get_num_docs()
doc_domain_set = set(doc_domains)
... | def get_new_term_doc_mat(self, doc_domains):
'''
Combines documents together that are in the same domain
Parameters
----------
doc_domains : array-like
Returns
-------
scipy.sparse.csr_matrix
'''
assert len(doc_domains) == self.term_doc_matrix.get_num_docs()
doc_domain_set = set(doc_domains)
... | [
"Combines",
"documents",
"together",
"that",
"are",
"in",
"the",
"same",
"domain"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/domain/CombineDocsIntoDomains.py#L14-L35 | [
"def",
"get_new_term_doc_mat",
"(",
"self",
",",
"doc_domains",
")",
":",
"assert",
"len",
"(",
"doc_domains",
")",
"==",
"self",
".",
"term_doc_matrix",
".",
"get_num_docs",
"(",
")",
"doc_domain_set",
"=",
"set",
"(",
"doc_domains",
")",
"num_terms",
"=",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CorpusFromParsedDocuments.build | Constructs the term doc matrix.
Returns
-------
scattertext.ParsedCorpus.ParsedCorpus | scattertext/CorpusFromParsedDocuments.py | def build(self):
'''Constructs the term doc matrix.
Returns
-------
scattertext.ParsedCorpus.ParsedCorpus
'''
self._y = self._get_y_and_populate_category_idx_store()
self._df.apply(self._add_to_x_factory, axis=1)
self._X = self._X_factory.set_last_row_idx(len(self._y)-1).get_csr_matrix()
self._mX = s... | def build(self):
'''Constructs the term doc matrix.
Returns
-------
scattertext.ParsedCorpus.ParsedCorpus
'''
self._y = self._get_y_and_populate_category_idx_store()
self._df.apply(self._add_to_x_factory, axis=1)
self._X = self._X_factory.set_last_row_idx(len(self._y)-1).get_csr_matrix()
self._mX = s... | [
"Constructs",
"the",
"term",
"doc",
"matrix",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/CorpusFromParsedDocuments.py#L37-L56 | [
"def",
"build",
"(",
"self",
")",
":",
"self",
".",
"_y",
"=",
"self",
".",
"_get_y_and_populate_category_idx_store",
"(",
")",
"self",
".",
"_df",
".",
"apply",
"(",
"self",
".",
"_add_to_x_factory",
",",
"axis",
"=",
"1",
")",
"self",
".",
"_X",
"=",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermCategoryFrequencies.get_term_and_background_counts | Returns
-------
A pd.DataFrame consisting of unigram term counts of words occurring
in the TermDocumentMatrix and their corresponding background corpus
counts. The dataframe has two columns, corpus and background.
>>> corpus.get_unigram_corpus.get_term_and_background_counts()
corpus b... | scattertext/TermCategoryFrequencies.py | def get_term_and_background_counts(self):
'''
Returns
-------
A pd.DataFrame consisting of unigram term counts of words occurring
in the TermDocumentMatrix and their corresponding background corpus
counts. The dataframe has two columns, corpus and background.
>>> corpus.get_unigram_corpus.get_term_and... | def get_term_and_background_counts(self):
'''
Returns
-------
A pd.DataFrame consisting of unigram term counts of words occurring
in the TermDocumentMatrix and their corresponding background corpus
counts. The dataframe has two columns, corpus and background.
>>> corpus.get_unigram_corpus.get_term_and... | [
"Returns",
"-------",
"A",
"pd",
".",
"DataFrame",
"consisting",
"of",
"unigram",
"term",
"counts",
"of",
"words",
"occurring",
"in",
"the",
"TermDocumentMatrix",
"and",
"their",
"corresponding",
"background",
"corpus",
"counts",
".",
"The",
"dataframe",
"has",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermCategoryFrequencies.py#L127-L147 | [
"def",
"get_term_and_background_counts",
"(",
"self",
")",
":",
"background_df",
"=",
"self",
".",
"_get_background_unigram_frequencies",
"(",
")",
"corpus_freq_df",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"'corpus'",
":",
"self",
".",
"term_category_freq_df",
".",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermCategoryFrequencies.get_doc_indices | Returns
-------
np.array
Integer document indices | scattertext/TermCategoryFrequencies.py | def get_doc_indices(self):
'''
Returns
-------
np.array
Integer document indices
'''
if self._document_category_df is None:
return pd.np.array([])
categories_d = {d: i for i, d in enumerate(self.get_categories())}
return self._document_category_df.category.apply(categories_d.get).values | def get_doc_indices(self):
'''
Returns
-------
np.array
Integer document indices
'''
if self._document_category_df is None:
return pd.np.array([])
categories_d = {d: i for i, d in enumerate(self.get_categories())}
return self._document_category_df.category.apply(categories_d.get).values | [
"Returns",
"-------",
"np",
".",
"array"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermCategoryFrequencies.py#L165-L176 | [
"def",
"get_doc_indices",
"(",
"self",
")",
":",
"if",
"self",
".",
"_document_category_df",
"is",
"None",
":",
"return",
"pd",
".",
"np",
".",
"array",
"(",
"[",
"]",
")",
"categories_d",
"=",
"{",
"d",
":",
"i",
"for",
"i",
",",
"d",
"in",
"enume... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermCategoryFrequencies.get_texts | Returns
-------
np.array
Texts | scattertext/TermCategoryFrequencies.py | def get_texts(self):
'''
Returns
-------
np.array
Texts
'''
if self._document_category_df is None:
return pd.np.array([])
return self._document_category_df.text.values | def get_texts(self):
'''
Returns
-------
np.array
Texts
'''
if self._document_category_df is None:
return pd.np.array([])
return self._document_category_df.text.values | [
"Returns",
"-------",
"np",
".",
"array"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermCategoryFrequencies.py#L178-L188 | [
"def",
"get_texts",
"(",
"self",
")",
":",
"if",
"self",
".",
"_document_category_df",
"is",
"None",
":",
"return",
"pd",
".",
"np",
".",
"array",
"(",
"[",
"]",
")",
"return",
"self",
".",
"_document_category_df",
".",
"text",
".",
"values"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermCategoryFrequencies.get_term_category_frequencies | Parameters
----------
scatterchartdata : ScatterChartData
Returns
-------
pd.DataFrame | scattertext/TermCategoryFrequencies.py | def get_term_category_frequencies(self, scatterchartdata):
'''
Parameters
----------
scatterchartdata : ScatterChartData
Returns
-------
pd.DataFrame
'''
df = self.term_category_freq_df.rename(
columns={c: c + ' freq' for c in self.term_category_freq_df}
)
df.index.name = 'term'
return df | def get_term_category_frequencies(self, scatterchartdata):
'''
Parameters
----------
scatterchartdata : ScatterChartData
Returns
-------
pd.DataFrame
'''
df = self.term_category_freq_df.rename(
columns={c: c + ' freq' for c in self.term_category_freq_df}
)
df.index.name = 'term'
return df | [
"Parameters",
"----------",
"scatterchartdata",
":",
"ScatterChartData"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermCategoryFrequencies.py#L190-L205 | [
"def",
"get_term_category_frequencies",
"(",
"self",
",",
"scatterchartdata",
")",
":",
"df",
"=",
"self",
".",
"term_category_freq_df",
".",
"rename",
"(",
"columns",
"=",
"{",
"c",
":",
"c",
"+",
"' freq'",
"for",
"c",
"in",
"self",
".",
"term_category_fre... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrixFilter.filter | Parameters
----------
term_doc_matrix : TermDocMatrix
Returns
-------
TermDocMatrix pmi-filterd term doc matrix | scattertext/TermDocMatrixFilter.py | def filter(self, term_doc_matrix):
'''
Parameters
----------
term_doc_matrix : TermDocMatrix
Returns
-------
TermDocMatrix pmi-filterd term doc matrix
'''
df = term_doc_matrix.get_term_freq_df()
if len(df) == 0:
return term_doc_matrix
low_pmi_bigrams = get_low_pmi_bigrams(self._threshold_coef... | def filter(self, term_doc_matrix):
'''
Parameters
----------
term_doc_matrix : TermDocMatrix
Returns
-------
TermDocMatrix pmi-filterd term doc matrix
'''
df = term_doc_matrix.get_term_freq_df()
if len(df) == 0:
return term_doc_matrix
low_pmi_bigrams = get_low_pmi_bigrams(self._threshold_coef... | [
"Parameters",
"----------",
"term_doc_matrix",
":",
"TermDocMatrix"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrixFilter.py#L75-L95 | [
"def",
"filter",
"(",
"self",
",",
"term_doc_matrix",
")",
":",
"df",
"=",
"term_doc_matrix",
".",
"get_term_freq_df",
"(",
")",
"if",
"len",
"(",
"df",
")",
"==",
"0",
":",
"return",
"term_doc_matrix",
"low_pmi_bigrams",
"=",
"get_low_pmi_bigrams",
"(",
"se... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_scattertext_explorer | Returns html code of visualization.
Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of category column as it appears in original data frame.
category_name : str
Name of category to use. E.g., "5-star reviews."
Optional, defaults to category ... | scattertext/__init__.py | def produce_scattertext_explorer(corpus,
category,
category_name=None,
not_category_name=None,
protocol='https',
pmi_threshold_coefficient=DEFAULT_MINIMUM_... | def produce_scattertext_explorer(corpus,
category,
category_name=None,
not_category_name=None,
protocol='https',
pmi_threshold_coefficient=DEFAULT_MINIMUM_... | [
"Returns",
"html",
"code",
"of",
"visualization",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L105-L500 | [
"def",
"produce_scattertext_explorer",
"(",
"corpus",
",",
"category",
",",
"category_name",
"=",
"None",
",",
"not_category_name",
"=",
"None",
",",
"protocol",
"=",
"'https'",
",",
"pmi_threshold_coefficient",
"=",
"DEFAULT_MINIMUM_TERM_FREQUENCY",
",",
"minimum_term_... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_scattertext_html | Returns html code of visualization.
Parameters
----------
term_doc_matrix : TermDocMatrix
Corpus to use
category : str
name of category column
category_name: str
name of category to mine for
not_category_name: str
name of everything that isn't in category
pro... | scattertext/__init__.py | def produce_scattertext_html(term_doc_matrix,
category,
category_name,
not_category_name,
protocol='https',
minimum_term_frequency=DEFAULT_MINIMUM_TERM_FREQUENCY,
... | def produce_scattertext_html(term_doc_matrix,
category,
category_name,
not_category_name,
protocol='https',
minimum_term_frequency=DEFAULT_MINIMUM_TERM_FREQUENCY,
... | [
"Returns",
"html",
"code",
"of",
"visualization",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L520-L577 | [
"def",
"produce_scattertext_html",
"(",
"term_doc_matrix",
",",
"category",
",",
"category_name",
",",
"not_category_name",
",",
"protocol",
"=",
"'https'",
",",
"minimum_term_frequency",
"=",
"DEFAULT_MINIMUM_TERM_FREQUENCY",
",",
"pmi_threshold_coefficient",
"=",
"DEFAULT... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | word_similarity_explorer_gensim | Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of category column as it appears in original data frame.
category_name : str
Name of category to use. E.g., "5-star reviews."
not_category_name : str
Name of ... | scattertext/__init__.py | def word_similarity_explorer_gensim(corpus,
category,
target_term,
category_name=None,
not_category_name=None,
word2vec=None,
... | def word_similarity_explorer_gensim(corpus,
category,
target_term,
category_name=None,
not_category_name=None,
word2vec=None,
... | [
"Parameters",
"----------",
"corpus",
":",
"Corpus",
"Corpus",
"to",
"use",
".",
"category",
":",
"str",
"Name",
"of",
"category",
"column",
"as",
"it",
"appears",
"in",
"original",
"data",
"frame",
".",
"category_name",
":",
"str",
"Name",
"of",
"category",... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L608-L678 | [
"def",
"word_similarity_explorer_gensim",
"(",
"corpus",
",",
"category",
",",
"target_term",
",",
"category_name",
"=",
"None",
",",
"not_category_name",
"=",
"None",
",",
"word2vec",
"=",
"None",
",",
"alpha",
"=",
"0.01",
",",
"max_p_val",
"=",
"0.1",
",",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | word_similarity_explorer | Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of category column as it appears in original data frame.
category_name : str
Name of category to use. E.g., "5-star reviews."
not_category_name : str
Name of everything that isn't in category. ... | scattertext/__init__.py | def word_similarity_explorer(corpus,
category,
category_name,
not_category_name,
target_term,
nlp=None,
alpha=0.01,
m... | def word_similarity_explorer(corpus,
category,
category_name,
not_category_name,
target_term,
nlp=None,
alpha=0.01,
m... | [
"Parameters",
"----------",
"corpus",
":",
"Corpus",
"Corpus",
"to",
"use",
".",
"category",
":",
"str",
"Name",
"of",
"category",
"column",
"as",
"it",
"appears",
"in",
"original",
"data",
"frame",
".",
"category_name",
":",
"str",
"Name",
"of",
"category",... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L681-L734 | [
"def",
"word_similarity_explorer",
"(",
"corpus",
",",
"category",
",",
"category_name",
",",
"not_category_name",
",",
"target_term",
",",
"nlp",
"=",
"None",
",",
"alpha",
"=",
"0.01",
",",
"max_p_val",
"=",
"0.1",
",",
"*",
"*",
"kwargs",
")",
":",
"if"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_frequency_explorer | Produces a Monroe et al. style visualization, with the x-axis being the log frequency
Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of category column as it appears in original data frame.
category_name : str or None
Name of category to use. E.g.,... | scattertext/__init__.py | def produce_frequency_explorer(corpus,
category,
category_name=None,
not_category_name=None,
term_ranker=termranking.AbsoluteFrequencyRanker,
alpha=0.01,
... | def produce_frequency_explorer(corpus,
category,
category_name=None,
not_category_name=None,
term_ranker=termranking.AbsoluteFrequencyRanker,
alpha=0.01,
... | [
"Produces",
"a",
"Monroe",
"et",
"al",
".",
"style",
"visualization",
"with",
"the",
"x",
"-",
"axis",
"being",
"the",
"log",
"frequency"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L737-L860 | [
"def",
"produce_frequency_explorer",
"(",
"corpus",
",",
"category",
",",
"category_name",
"=",
"None",
",",
"not_category_name",
"=",
"None",
",",
"term_ranker",
"=",
"termranking",
".",
"AbsoluteFrequencyRanker",
",",
"alpha",
"=",
"0.01",
",",
"use_term_significa... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_semiotic_square_explorer | Produces a semiotic square visualization.
Parameters
----------
semiotic_square : SemioticSquare
The basis of the visualization
x_label : str
The x-axis label in the scatter plot. Relationship between `category_a` and `category_b`.
y_label
The y-axis label in the scatter pl... | scattertext/__init__.py | def produce_semiotic_square_explorer(semiotic_square,
x_label,
y_label,
category_name=None,
not_category_name=None,
neutral_category_na... | def produce_semiotic_square_explorer(semiotic_square,
x_label,
y_label,
category_name=None,
not_category_name=None,
neutral_category_na... | [
"Produces",
"a",
"semiotic",
"square",
"visualization",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L867-L960 | [
"def",
"produce_semiotic_square_explorer",
"(",
"semiotic_square",
",",
"x_label",
",",
"y_label",
",",
"category_name",
"=",
"None",
",",
"not_category_name",
"=",
"None",
",",
"neutral_category_name",
"=",
"None",
",",
"num_terms_semiotic_square",
"=",
"None",
",",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_four_square_explorer | Produces a semiotic square visualization.
Parameters
----------
four_square : FourSquare
The basis of the visualization
x_label : str
The x-axis label in the scatter plot. Relationship between `category_a` and `category_b`.
y_label
The y-axis label in the scatter plot. Rel... | scattertext/__init__.py | def produce_four_square_explorer(four_square,
x_label=None,
y_label=None,
a_category_name=None,
b_category_name=None,
not_a_category_name=None,
... | def produce_four_square_explorer(four_square,
x_label=None,
y_label=None,
a_category_name=None,
b_category_name=None,
not_a_category_name=None,
... | [
"Produces",
"a",
"semiotic",
"square",
"visualization",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L963-L1082 | [
"def",
"produce_four_square_explorer",
"(",
"four_square",
",",
"x_label",
"=",
"None",
",",
"y_label",
"=",
"None",
",",
"a_category_name",
"=",
"None",
",",
"b_category_name",
"=",
"None",
",",
"not_a_category_name",
"=",
"None",
",",
"not_b_category_name",
"=",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_four_square_axes_explorer | Produces a semiotic square visualization.
Parameters
----------
four_square : FourSquareAxes
The basis of the visualization
x_label : str
The x-axis label in the scatter plot. Relationship between `category_a` and `category_b`.
y_label
The y-axis label in the scatter plot. ... | scattertext/__init__.py | def produce_four_square_axes_explorer(four_square_axes,
x_label=None,
y_label=None,
num_terms_semiotic_square=None,
get_tooltip_content=None,
... | def produce_four_square_axes_explorer(four_square_axes,
x_label=None,
y_label=None,
num_terms_semiotic_square=None,
get_tooltip_content=None,
... | [
"Produces",
"a",
"semiotic",
"square",
"visualization",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L1085-L1180 | [
"def",
"produce_four_square_axes_explorer",
"(",
"four_square_axes",
",",
"x_label",
"=",
"None",
",",
"y_label",
"=",
"None",
",",
"num_terms_semiotic_square",
"=",
"None",
",",
"get_tooltip_content",
"=",
"None",
",",
"x_axis_values",
"=",
"None",
",",
"y_axis_val... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_projection_explorer | Parameters
----------
corpus : ParsedCorpus
It is highly recommended to use a stoplisted, unigram corpus-- `corpus.get_stoplisted_unigram_corpus()`
category : str
word2vec_model : Word2Vec
A gensim word2vec model. A default model will be used instead. See Word2VecFromParsedCorpus for th... | scattertext/__init__.py | def produce_projection_explorer(corpus,
category,
word2vec_model=None,
projection_model=None,
embeddings=None,
term_acceptance_re=re.compile('[a-z]{3,}'),
... | def produce_projection_explorer(corpus,
category,
word2vec_model=None,
projection_model=None,
embeddings=None,
term_acceptance_re=re.compile('[a-z]{3,}'),
... | [
"Parameters",
"----------",
"corpus",
":",
"ParsedCorpus",
"It",
"is",
"highly",
"recommended",
"to",
"use",
"a",
"stoplisted",
"unigram",
"corpus",
"--",
"corpus",
".",
"get_stoplisted_unigram_corpus",
"()",
"category",
":",
"str",
"word2vec_model",
":",
"Word2Vec"... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L1183-L1236 | [
"def",
"produce_projection_explorer",
"(",
"corpus",
",",
"category",
",",
"word2vec_model",
"=",
"None",
",",
"projection_model",
"=",
"None",
",",
"embeddings",
"=",
"None",
",",
"term_acceptance_re",
"=",
"re",
".",
"compile",
"(",
"'[a-z]{3,}'",
")",
",",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_pca_explorer | Parameters
----------
corpus : ParsedCorpus
It is highly recommended to use a stoplisted, unigram corpus-- `corpus.get_stoplisted_unigram_corpus()`
category : str
word2vec_model : Word2Vec
A gensim word2vec model. A default model will be used instead. See Word2VecFromParsedCorpus for th... | scattertext/__init__.py | def produce_pca_explorer(corpus,
category,
word2vec_model=None,
projection_model=None,
embeddings=None,
projection=None,
term_acceptance_re=re.compile('[a-z]{3,}'),
... | def produce_pca_explorer(corpus,
category,
word2vec_model=None,
projection_model=None,
embeddings=None,
projection=None,
term_acceptance_re=re.compile('[a-z]{3,}'),
... | [
"Parameters",
"----------",
"corpus",
":",
"ParsedCorpus",
"It",
"is",
"highly",
"recommended",
"to",
"use",
"a",
"stoplisted",
"unigram",
"corpus",
"--",
"corpus",
".",
"get_stoplisted_unigram_corpus",
"()",
"category",
":",
"str",
"word2vec_model",
":",
"Word2Vec"... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L1239-L1323 | [
"def",
"produce_pca_explorer",
"(",
"corpus",
",",
"category",
",",
"word2vec_model",
"=",
"None",
",",
"projection_model",
"=",
"None",
",",
"embeddings",
"=",
"None",
",",
"projection",
"=",
"None",
",",
"term_acceptance_re",
"=",
"re",
".",
"compile",
"(",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | produce_characteristic_explorer | Parameters
----------
corpus : Corpus
It is highly recommended to use a stoplisted, unigram corpus-- `corpus.get_stoplisted_unigram_corpus()`
category : str
category_name : str
not_category_name : str
not_categories : list
characteristic_scorer : CharacteristicScorer
term_ranker
... | scattertext/__init__.py | def produce_characteristic_explorer(corpus,
category,
category_name=None,
not_category_name=None,
not_categories=None,
characteristic_scorer... | def produce_characteristic_explorer(corpus,
category,
category_name=None,
not_category_name=None,
not_categories=None,
characteristic_scorer... | [
"Parameters",
"----------",
"corpus",
":",
"Corpus",
"It",
"is",
"highly",
"recommended",
"to",
"use",
"a",
"stoplisted",
"unigram",
"corpus",
"--",
"corpus",
".",
"get_stoplisted_unigram_corpus",
"()",
"category",
":",
"str",
"category_name",
":",
"str",
"not_cat... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L1326-L1399 | [
"def",
"produce_characteristic_explorer",
"(",
"corpus",
",",
"category",
",",
"category_name",
"=",
"None",
",",
"not_category_name",
"=",
"None",
",",
"not_categories",
"=",
"None",
",",
"characteristic_scorer",
"=",
"DenseRankCharacteristicness",
"(",
")",
",",
"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | sparse_explorer | Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of category column as it appears in original data frame.
category_name : str
Name of category to use. E.g., "5-star reviews."
not_category_name : str
Name of everything that isn't in category. ... | scattertext/__init__.py | def sparse_explorer(corpus,
category,
scores,
category_name=None,
not_category_name=None,
**kwargs):
'''
Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of cat... | def sparse_explorer(corpus,
category,
scores,
category_name=None,
not_category_name=None,
**kwargs):
'''
Parameters
----------
corpus : Corpus
Corpus to use.
category : str
Name of cat... | [
"Parameters",
"----------",
"corpus",
":",
"Corpus",
"Corpus",
"to",
"use",
".",
"category",
":",
"str",
"Name",
"of",
"category",
"column",
"as",
"it",
"appears",
"in",
"original",
"data",
"frame",
".",
"category_name",
":",
"str",
"Name",
"of",
"category",... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/__init__.py#L1402-L1438 | [
"def",
"sparse_explorer",
"(",
"corpus",
",",
"category",
",",
"scores",
",",
"category_name",
"=",
"None",
",",
"not_category_name",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"produce_scattertext_explorer",
"(",
"corpus",
",",
"category",
",",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ClassPercentageCompactor.compact | Parameters
-------
term_doc_matrix : TermDocMatrix
Returns
-------
New term doc matrix | scattertext/termcompaction/ClassPercentageCompactor.py | def compact(self, term_doc_matrix):
'''
Parameters
-------
term_doc_matrix : TermDocMatrix
Returns
-------
New term doc matrix
'''
tdf = self.term_ranker(term_doc_matrix).get_ranks()
tdf_sum = tdf.sum(axis=0)
tdf_portions = tdf / tdf_sum
threshold = np.max(self.term_count / tdf_sum)
terms_to_... | def compact(self, term_doc_matrix):
'''
Parameters
-------
term_doc_matrix : TermDocMatrix
Returns
-------
New term doc matrix
'''
tdf = self.term_ranker(term_doc_matrix).get_ranks()
tdf_sum = tdf.sum(axis=0)
tdf_portions = tdf / tdf_sum
threshold = np.max(self.term_count / tdf_sum)
terms_to_... | [
"Parameters",
"-------",
"term_doc_matrix",
":",
"TermDocMatrix"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termcompaction/ClassPercentageCompactor.py#L23-L38 | [
"def",
"compact",
"(",
"self",
",",
"term_doc_matrix",
")",
":",
"tdf",
"=",
"self",
".",
"term_ranker",
"(",
"term_doc_matrix",
")",
".",
"get_ranks",
"(",
")",
"tdf_sum",
"=",
"tdf",
".",
"sum",
"(",
"axis",
"=",
"0",
")",
"tdf_portions",
"=",
"tdf",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | IndexStoreFromList.build | Parameters
----------
values: [term, ...]
Returns
-------
IndexStore | scattertext/indexstore/IndexStoreFromList.py | def build(values):
'''
Parameters
----------
values: [term, ...]
Returns
-------
IndexStore
'''
idxstore = IndexStore()
idxstore._i2val = list(values)
idxstore._val2i = {term:i for i,term in enumerate(values)}
idxstore._next_i = len(values)
return idxstore | def build(values):
'''
Parameters
----------
values: [term, ...]
Returns
-------
IndexStore
'''
idxstore = IndexStore()
idxstore._i2val = list(values)
idxstore._val2i = {term:i for i,term in enumerate(values)}
idxstore._next_i = len(values)
return idxstore | [
"Parameters",
"----------",
"values",
":",
"[",
"term",
"...",
"]"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/indexstore/IndexStoreFromList.py#L6-L20 | [
"def",
"build",
"(",
"values",
")",
":",
"idxstore",
"=",
"IndexStore",
"(",
")",
"idxstore",
".",
"_i2val",
"=",
"list",
"(",
"values",
")",
"idxstore",
".",
"_val2i",
"=",
"{",
"term",
":",
"i",
"for",
"i",
",",
"term",
"in",
"enumerate",
"(",
"v... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | DocsAndLabelsFromCorpusSample.get_labels_and_texts | Parameters
----------
metadata : (array like or None)
Returns
-------
{'labels':[], 'texts': []} or {'labels':[], 'texts': [], 'meta': []} | scattertext/DocsAndLabelsFromCorpus.py | def get_labels_and_texts(self, metadata=None):
'''
Parameters
----------
metadata : (array like or None)
Returns
-------
{'labels':[], 'texts': []} or {'labels':[], 'texts': [], 'meta': []}
'''
to_ret = {'categories': self._corpus.get_categories(), 'labels': [], 'texts': []}
labels = self._corpus._... | def get_labels_and_texts(self, metadata=None):
'''
Parameters
----------
metadata : (array like or None)
Returns
-------
{'labels':[], 'texts': []} or {'labels':[], 'texts': [], 'meta': []}
'''
to_ret = {'categories': self._corpus.get_categories(), 'labels': [], 'texts': []}
labels = self._corpus._... | [
"Parameters",
"----------",
"metadata",
":",
"(",
"array",
"like",
"or",
"None",
")"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/DocsAndLabelsFromCorpus.py#L76-L105 | [
"def",
"get_labels_and_texts",
"(",
"self",
",",
"metadata",
"=",
"None",
")",
":",
"to_ret",
"=",
"{",
"'categories'",
":",
"self",
".",
"_corpus",
".",
"get_categories",
"(",
")",
",",
"'labels'",
":",
"[",
"]",
",",
"'texts'",
":",
"[",
"]",
"}",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScoreBalancer.balance_scores_and_dont_scale | median = np.median(cat_scores)
scores = np.zeros(len(cat_scores)).astype(np.float)
scores[cat_scores > median] = cat_scores[cat_scores > median]
not_cat_mask = cat_scores < median if median != 0 else cat_scores <= median
scores[not_cat_mask] = -not_cat_scores[not_cat_mask] | scattertext/termscoring/ScaledFScore.py | def balance_scores_and_dont_scale(cat_scores, not_cat_scores):
'''
median = np.median(cat_scores)
scores = np.zeros(len(cat_scores)).astype(np.float)
scores[cat_scores > median] = cat_scores[cat_scores > median]
not_cat_mask = cat_scores < median if median != 0 else cat_scores <= median
scores[not_cat_mask]... | def balance_scores_and_dont_scale(cat_scores, not_cat_scores):
'''
median = np.median(cat_scores)
scores = np.zeros(len(cat_scores)).astype(np.float)
scores[cat_scores > median] = cat_scores[cat_scores > median]
not_cat_mask = cat_scores < median if median != 0 else cat_scores <= median
scores[not_cat_mask]... | [
"median",
"=",
"np",
".",
"median",
"(",
"cat_scores",
")",
"scores",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"cat_scores",
"))",
".",
"astype",
"(",
"np",
".",
"float",
")",
"scores",
"[",
"cat_scores",
">",
"median",
"]",
"=",
"cat_scores",
"[",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/ScaledFScore.py#L19-L30 | [
"def",
"balance_scores_and_dont_scale",
"(",
"cat_scores",
",",
"not_cat_scores",
")",
":",
"scores",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"cat_scores",
")",
")",
".",
"astype",
"(",
"np",
".",
"float",
")",
"scores",
"[",
"cat_scores",
">",
"not_cat_... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScaledFScorePresets.get_scores | Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
Returns
-------
np.array
scores | scattertext/termscoring/ScaledFScore.py | def get_scores(self, cat_word_counts, not_cat_word_counts):
'''
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
Returns
-------
np.array
scores
'''
cat_scores = self.get_scores_for_category(cat_word_counts,
... | def get_scores(self, cat_word_counts, not_cat_word_counts):
'''
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
Returns
-------
np.array
scores
'''
cat_scores = self.get_scores_for_category(cat_word_counts,
... | [
"Parameters",
"----------",
"cat_word_counts",
":",
"np",
".",
"array",
"category",
"counts",
"not_cat_word_counts",
":",
"np",
".",
"array",
"not",
"category",
"counts"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/ScaledFScore.py#L70-L95 | [
"def",
"get_scores",
"(",
"self",
",",
"cat_word_counts",
",",
"not_cat_word_counts",
")",
":",
"cat_scores",
"=",
"self",
".",
"get_scores_for_category",
"(",
"cat_word_counts",
",",
"not_cat_word_counts",
")",
"not_cat_scores",
"=",
"self",
".",
"get_scores_for_cate... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScaledFScorePresets.get_scores_for_category | Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
Returns
-------
np.array
scores | scattertext/termscoring/ScaledFScore.py | def get_scores_for_category(self, cat_word_counts, not_cat_word_counts):
'''
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
Returns
-------
np.array
scores
'''
beta = self.beta_
assert len(cat_word_counts) == len(not_ca... | def get_scores_for_category(self, cat_word_counts, not_cat_word_counts):
'''
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
Returns
-------
np.array
scores
'''
beta = self.beta_
assert len(cat_word_counts) == len(not_ca... | [
"Parameters",
"----------",
"cat_word_counts",
":",
"np",
".",
"array",
"category",
"counts",
"not_cat_word_counts",
":",
"np",
".",
"array",
"not",
"category",
"counts"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/ScaledFScore.py#L97-L126 | [
"def",
"get_scores_for_category",
"(",
"self",
",",
"cat_word_counts",
",",
"not_cat_word_counts",
")",
":",
"beta",
"=",
"self",
".",
"beta_",
"assert",
"len",
"(",
"cat_word_counts",
")",
"==",
"len",
"(",
"not_cat_word_counts",
")",
"if",
"self",
".",
"prio... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScaledFZScore.get_p_vals | Parameters
----------
X : np.array
Array of word counts, shape (N, 2) where N is the vocab size. X[:,0] is the
positive class, while X[:,1] is the negative class. None by default
Returns
-------
np.array of p-values | scattertext/termscoring/ScaledFScore.py | def get_p_vals(self, X):
'''
Parameters
----------
X : np.array
Array of word counts, shape (N, 2) where N is the vocab size. X[:,0] is the
positive class, while X[:,1] is the negative class. None by default
Returns
-------
np.array of p-values
'''
z_scores = self.get_scores(X[:, 0], X[:, 1])... | def get_p_vals(self, X):
'''
Parameters
----------
X : np.array
Array of word counts, shape (N, 2) where N is the vocab size. X[:,0] is the
positive class, while X[:,1] is the negative class. None by default
Returns
-------
np.array of p-values
'''
z_scores = self.get_scores(X[:, 0], X[:, 1])... | [
"Parameters",
"----------",
"X",
":",
"np",
".",
"array",
"Array",
"of",
"word",
"counts",
"shape",
"(",
"N",
"2",
")",
"where",
"N",
"is",
"the",
"vocab",
"size",
".",
"X",
"[",
":",
"0",
"]",
"is",
"the",
"positive",
"class",
"while",
"X",
"[",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/ScaledFScore.py#L166-L180 | [
"def",
"get_p_vals",
"(",
"self",
",",
"X",
")",
":",
"z_scores",
"=",
"self",
".",
"get_scores",
"(",
"X",
"[",
":",
",",
"0",
"]",
",",
"X",
"[",
":",
",",
"1",
"]",
")",
"return",
"norm",
".",
"cdf",
"(",
"z_scores",
")"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScaledFScore.get_scores | Computes balanced scaled f-scores
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
scaler_algo : str
Function that scales an array to a range \in [0 and 1]. Use 'percentile', 'normcdf'. Default.
beta : float
Beta in (1+B^2) * (Sc... | scattertext/termscoring/ScaledFScore.py | def get_scores(cat_word_counts, not_cat_word_counts,
scaler_algo=DEFAULT_SCALER_ALGO, beta=DEFAULT_BETA):
''' Computes balanced scaled f-scores
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
scaler_algo : str
Funct... | def get_scores(cat_word_counts, not_cat_word_counts,
scaler_algo=DEFAULT_SCALER_ALGO, beta=DEFAULT_BETA):
''' Computes balanced scaled f-scores
Parameters
----------
cat_word_counts : np.array
category counts
not_cat_word_counts : np.array
not category counts
scaler_algo : str
Funct... | [
"Computes",
"balanced",
"scaled",
"f",
"-",
"scores",
"Parameters",
"----------",
"cat_word_counts",
":",
"np",
".",
"array",
"category",
"counts",
"not_cat_word_counts",
":",
"np",
".",
"array",
"not",
"category",
"counts",
"scaler_algo",
":",
"str",
"Function",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/ScaledFScore.py#L226-L255 | [
"def",
"get_scores",
"(",
"cat_word_counts",
",",
"not_cat_word_counts",
",",
"scaler_algo",
"=",
"DEFAULT_SCALER_ALGO",
",",
"beta",
"=",
"DEFAULT_BETA",
")",
":",
"cat_scores",
"=",
"ScaledFScore",
".",
"get_scores_for_category",
"(",
"cat_word_counts",
",",
"not_ca... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScaledFScore.get_scores_for_category | Computes unbalanced scaled-fscores
Parameters
----------
category : str
category name to score
scaler_algo : str
Function that scales an array to a range \in [0 and 1]. Use 'percentile', 'normcdf'. Default normcdf
beta : float
Beta in (1+B^2) * (Scale(P(w|c)) * Scale(P(c|w)))/(B^2*Scale(P(w|c)) + Sca... | scattertext/termscoring/ScaledFScore.py | def get_scores_for_category(cat_word_counts, not_cat_word_counts,
scaler_algo=DEFAULT_SCALER_ALGO, beta=DEFAULT_BETA):
''' Computes unbalanced scaled-fscores
Parameters
----------
category : str
category name to score
scaler_algo : str
Function that scales an array to a rang... | def get_scores_for_category(cat_word_counts, not_cat_word_counts,
scaler_algo=DEFAULT_SCALER_ALGO, beta=DEFAULT_BETA):
''' Computes unbalanced scaled-fscores
Parameters
----------
category : str
category name to score
scaler_algo : str
Function that scales an array to a rang... | [
"Computes",
"unbalanced",
"scaled",
"-",
"fscores",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score",
"scaler_algo",
":",
"str",
"Function",
"that",
"scales",
"an",
"array",
"to",
"a",
"range",
"\\",
"in",
"[",
"0",
"and"... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/ScaledFScore.py#L258-L281 | [
"def",
"get_scores_for_category",
"(",
"cat_word_counts",
",",
"not_cat_word_counts",
",",
"scaler_algo",
"=",
"DEFAULT_SCALER_ALGO",
",",
"beta",
"=",
"DEFAULT_BETA",
")",
":",
"assert",
"beta",
">",
"0",
"precision",
"=",
"(",
"cat_word_counts",
"*",
"1.",
"/",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | extract_emoji | Parameters
----------
text, str
Returns
-------
List of 5.0-compliant emojis that occur in text. | scattertext/emojis/EmojiExtractor.py | def extract_emoji(text):
'''
Parameters
----------
text, str
Returns
-------
List of 5.0-compliant emojis that occur in text.
'''
found_emojis = []
len_text = len(text)
i = 0
while i < len_text:
cur_char = ord(text[i])
try:
VALID_EMOJIS[cur_char]
except:
i += 1
continue
found = False
for... | def extract_emoji(text):
'''
Parameters
----------
text, str
Returns
-------
List of 5.0-compliant emojis that occur in text.
'''
found_emojis = []
len_text = len(text)
i = 0
while i < len_text:
cur_char = ord(text[i])
try:
VALID_EMOJIS[cur_char]
except:
i += 1
continue
found = False
for... | [
"Parameters",
"----------",
"text",
"str"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/emojis/EmojiExtractor.py#L32-L71 | [
"def",
"extract_emoji",
"(",
"text",
")",
":",
"found_emojis",
"=",
"[",
"]",
"len_text",
"=",
"len",
"(",
"text",
")",
"i",
"=",
"0",
"while",
"i",
"<",
"len_text",
":",
"cur_char",
"=",
"ord",
"(",
"text",
"[",
"i",
"]",
")",
"try",
":",
"VALID... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | GanttChart.make_chart | Returns
-------
altair.Chart | scattertext/diachronic/GanttChart.py | def make_chart(self):
'''
Returns
-------
altair.Chart
'''
task_df = self.get_task_df()
import altair as alt
chart = alt.Chart(task_df).mark_bar().encode(
x='start',
x2='end',
y='term',
)
return chart | def make_chart(self):
'''
Returns
-------
altair.Chart
'''
task_df = self.get_task_df()
import altair as alt
chart = alt.Chart(task_df).mark_bar().encode(
x='start',
x2='end',
y='term',
)
return chart | [
"Returns",
"-------",
"altair",
".",
"Chart"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/diachronic/GanttChart.py#L57-L70 | [
"def",
"make_chart",
"(",
"self",
")",
":",
"task_df",
"=",
"self",
".",
"get_task_df",
"(",
")",
"import",
"altair",
"as",
"alt",
"chart",
"=",
"alt",
".",
"Chart",
"(",
"task_df",
")",
".",
"mark_bar",
"(",
")",
".",
"encode",
"(",
"x",
"=",
"'st... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | GanttChart.get_temporal_score_df | Returns
------- | scattertext/diachronic/GanttChart.py | def get_temporal_score_df(self):
'''
Returns
-------
'''
scoredf = {}
tdf = self.term_ranker(self.corpus).get_ranks()
for cat in sorted(self.corpus.get_categories()):
if cat >= self.starting_time_step:
negative_categories = self._get_negative_categories(cat, tdf)
scores = self.term_scorer.get_... | def get_temporal_score_df(self):
'''
Returns
-------
'''
scoredf = {}
tdf = self.term_ranker(self.corpus).get_ranks()
for cat in sorted(self.corpus.get_categories()):
if cat >= self.starting_time_step:
negative_categories = self._get_negative_categories(cat, tdf)
scores = self.term_scorer.get_... | [
"Returns",
"-------"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/diachronic/GanttChart.py#L72-L89 | [
"def",
"get_temporal_score_df",
"(",
"self",
")",
":",
"scoredf",
"=",
"{",
"}",
"tdf",
"=",
"self",
".",
"term_ranker",
"(",
"self",
".",
"corpus",
")",
".",
"get_ranks",
"(",
")",
"for",
"cat",
"in",
"sorted",
"(",
"self",
".",
"corpus",
".",
"get_... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | GanttChart.get_task_df | Returns
------- | scattertext/diachronic/GanttChart.py | def get_task_df(self):
'''
Returns
-------
'''
term_time_df = self._get_term_time_df()
terms_to_include = (
term_time_df
.groupby('term')['top']
.sum()
.sort_values(ascending=False)
.iloc[:self.num_terms_to_include].index
)
task_df = (
term_time_df[term_time_df.term.isin(terms_to_... | def get_task_df(self):
'''
Returns
-------
'''
term_time_df = self._get_term_time_df()
terms_to_include = (
term_time_df
.groupby('term')['top']
.sum()
.sort_values(ascending=False)
.iloc[:self.num_terms_to_include].index
)
task_df = (
term_time_df[term_time_df.term.isin(terms_to_... | [
"Returns",
"-------"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/diachronic/GanttChart.py#L111-L136 | [
"def",
"get_task_df",
"(",
"self",
")",
":",
"term_time_df",
"=",
"self",
".",
"_get_term_time_df",
"(",
")",
"terms_to_include",
"=",
"(",
"term_time_df",
".",
"groupby",
"(",
"'term'",
")",
"[",
"'top'",
"]",
".",
"sum",
"(",
")",
".",
"sort_values",
"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CorpusDF.search | Parameters
----------
ngram, str or unicode, string to search for
Returns
-------
pd.DataFrame, {self._parsed_col: <matching texts>, self._category_col: <corresponding categories>, ...} | scattertext/CorpusDF.py | def search(self, ngram):
'''
Parameters
----------
ngram, str or unicode, string to search for
Returns
-------
pd.DataFrame, {self._parsed_col: <matching texts>, self._category_col: <corresponding categories>, ...}
'''
mask = self._document_index... | def search(self, ngram):
'''
Parameters
----------
ngram, str or unicode, string to search for
Returns
-------
pd.DataFrame, {self._parsed_col: <matching texts>, self._category_col: <corresponding categories>, ...}
'''
mask = self._document_index... | [
"Parameters",
"----------",
"ngram",
"str",
"or",
"unicode",
"string",
"to",
"search",
"for"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/CorpusDF.py#L60-L72 | [
"def",
"search",
"(",
"self",
",",
"ngram",
")",
":",
"mask",
"=",
"self",
".",
"_document_index_mask",
"(",
"ngram",
")",
"return",
"self",
".",
"_df",
"[",
"mask",
"]"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | get_p_vals | Parameters
----------
df : A data frame from, e.g., get_term_freq_df : pd.DataFrame
positive_category : str
The positive category name.
term_significance : TermSignificance
A TermSignificance instance from which to extract p-values. | scattertext/PValGetter.py | def get_p_vals(df, positive_category, term_significance):
'''
Parameters
----------
df : A data frame from, e.g., get_term_freq_df : pd.DataFrame
positive_category : str
The positive category name.
term_significance : TermSignificance
A TermSignificance instance from which to extract p-values.
'''
df_pos = ... | def get_p_vals(df, positive_category, term_significance):
'''
Parameters
----------
df : A data frame from, e.g., get_term_freq_df : pd.DataFrame
positive_category : str
The positive category name.
term_significance : TermSignificance
A TermSignificance instance from which to extract p-values.
'''
df_pos = ... | [
"Parameters",
"----------",
"df",
":",
"A",
"data",
"frame",
"from",
"e",
".",
"g",
".",
"get_term_freq_df",
":",
"pd",
".",
"DataFrame",
"positive_category",
":",
"str",
"The",
"positive",
"category",
"name",
".",
"term_significance",
":",
"TermSignificance",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PValGetter.py#L4-L21 | [
"def",
"get_p_vals",
"(",
"df",
",",
"positive_category",
",",
"term_significance",
")",
":",
"df_pos",
"=",
"df",
"[",
"[",
"positive_category",
"]",
"]",
"df_pos",
".",
"columns",
"=",
"[",
"'pos'",
"]",
"df_neg",
"=",
"pd",
".",
"DataFrame",
"(",
"df"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermRanker.get_X | :return: term freq matrix or metadata freq matrix | scattertext/termranking/TermRanker.py | def get_X(self):
'''
:return: term freq matrix or metadata freq matrix
'''
if self._use_non_text_features:
return self._term_doc_matrix._mX
else:
return self._term_doc_matrix._X | def get_X(self):
'''
:return: term freq matrix or metadata freq matrix
'''
if self._use_non_text_features:
return self._term_doc_matrix._mX
else:
return self._term_doc_matrix._X | [
":",
"return",
":",
"term",
"freq",
"matrix",
"or",
"metadata",
"freq",
"matrix"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termranking/TermRanker.py#L34-L41 | [
"def",
"get_X",
"(",
"self",
")",
":",
"if",
"self",
".",
"_use_non_text_features",
":",
"return",
"self",
".",
"_term_doc_matrix",
".",
"_mX",
"else",
":",
"return",
"self",
".",
"_term_doc_matrix",
".",
"_X"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | scale_neg_1_to_1_with_zero_mean_log_abs_max | !!! not working | scattertext/Scalers.py | def scale_neg_1_to_1_with_zero_mean_log_abs_max(v):
'''
!!! not working
'''
df = pd.DataFrame({'v':v,
'sign': (v > 0) * 2 - 1})
df['lg'] = np.log(np.abs(v)) / np.log(1.96)
df['exclude'] = (np.isinf(df.lg) | np.isneginf(df.lg))
for mask in [(df['sign'] == -1) & (df['exclude'] == False),
... | def scale_neg_1_to_1_with_zero_mean_log_abs_max(v):
'''
!!! not working
'''
df = pd.DataFrame({'v':v,
'sign': (v > 0) * 2 - 1})
df['lg'] = np.log(np.abs(v)) / np.log(1.96)
df['exclude'] = (np.isinf(df.lg) | np.isneginf(df.lg))
for mask in [(df['sign'] == -1) & (df['exclude'] == False),
... | [
"!!!",
"not",
"working"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/Scalers.py#L35-L58 | [
"def",
"scale_neg_1_to_1_with_zero_mean_log_abs_max",
"(",
"v",
")",
":",
"df",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"'v'",
":",
"v",
",",
"'sign'",
":",
"(",
"v",
">",
"0",
")",
"*",
"2",
"-",
"1",
"}",
")",
"df",
"[",
"'lg'",
"]",
"=",
"np",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrixFromPandas.build | Constructs the term doc matrix.
Returns
-------
TermDocMatrix | scattertext/TermDocMatrixFromPandas.py | def build(self):
'''Constructs the term doc matrix.
Returns
-------
TermDocMatrix
'''
X_factory, mX_factory, category_idx_store, term_idx_store, metadata_idx_store, y \
= self._init_term_doc_matrix_variables()
parse_pipeline = ParsePipelineFactory(se... | def build(self):
'''Constructs the term doc matrix.
Returns
-------
TermDocMatrix
'''
X_factory, mX_factory, category_idx_store, term_idx_store, metadata_idx_store, y \
= self._init_term_doc_matrix_variables()
parse_pipeline = ParsePipelineFactory(se... | [
"Constructs",
"the",
"term",
"doc",
"matrix",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrixFromPandas.py#L130-L157 | [
"def",
"build",
"(",
"self",
")",
":",
"X_factory",
",",
"mX_factory",
",",
"category_idx_store",
",",
"term_idx_store",
",",
"metadata_idx_store",
",",
"y",
"=",
"self",
".",
"_init_term_doc_matrix_variables",
"(",
")",
"parse_pipeline",
"=",
"ParsePipelineFactory"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrixWithoutCategoriesFromPandas.build | Constructs the term doc matrix.
Returns
-------
TermDocMatrix | scattertext/TermDocMatrixFromPandas.py | def build(self):
'''Constructs the term doc matrix.
Returns
-------
TermDocMatrix
'''
X_factory = CSRMatrixFactory()
mX_factory = CSRMatrixFactory()
term_idx_store = IndexStore()
metadata_idx_store = IndexStore()
parse_pipeline = ParsePi... | def build(self):
'''Constructs the term doc matrix.
Returns
-------
TermDocMatrix
'''
X_factory = CSRMatrixFactory()
mX_factory = CSRMatrixFactory()
term_idx_store = IndexStore()
metadata_idx_store = IndexStore()
parse_pipeline = ParsePi... | [
"Constructs",
"the",
"term",
"doc",
"matrix",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrixFromPandas.py#L223-L249 | [
"def",
"build",
"(",
"self",
")",
":",
"X_factory",
"=",
"CSRMatrixFactory",
"(",
")",
"mX_factory",
"=",
"CSRMatrixFactory",
"(",
")",
"term_idx_store",
"=",
"IndexStore",
"(",
")",
"metadata_idx_store",
"=",
"IndexStore",
"(",
")",
"parse_pipeline",
"=",
"Pa... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CorpusSentenceIterator.get_sentences | Parameters
----------
corpus, ParsedCorpus
Returns
-------
iter: [sentence1word1, ...], [sentence2word1, ...] | scattertext/representations/CorpusSentenceIterator.py | def get_sentences(corpus):
'''
Parameters
----------
corpus, ParsedCorpus
Returns
-------
iter: [sentence1word1, ...], [sentence2word1, ...]
'''
assert isinstance(corpus, ParsedCorpus)
return itertools.chain(*[[[corpus._term_idx_store.getidxstrict(t.lower_) for t in sent
... | def get_sentences(corpus):
'''
Parameters
----------
corpus, ParsedCorpus
Returns
-------
iter: [sentence1word1, ...], [sentence2word1, ...]
'''
assert isinstance(corpus, ParsedCorpus)
return itertools.chain(*[[[corpus._term_idx_store.getidxstrict(t.lower_) for t in sent
... | [
"Parameters",
"----------",
"corpus",
"ParsedCorpus"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/representations/CorpusSentenceIterator.py#L8-L22 | [
"def",
"get_sentences",
"(",
"corpus",
")",
":",
"assert",
"isinstance",
"(",
"corpus",
",",
"ParsedCorpus",
")",
"return",
"itertools",
".",
"chain",
"(",
"*",
"[",
"[",
"[",
"corpus",
".",
"_term_idx_store",
".",
"getidxstrict",
"(",
"t",
".",
"lower_",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | DenseRankCharacteristicness.get_scores | Parameters
----------
corpus
Returns
-------
float, pd.Series
float: point on x-axis at even characteristicness
pd.Series: term -> value between 0 and 1, sorted by score in a descending manner
Background scores from corpus | scattertext/characteristic/DenseRankCharacteristicness.py | def get_scores(self, corpus):
'''
Parameters
----------
corpus
Returns
-------
float, pd.Series
float: point on x-axis at even characteristicness
pd.Series: term -> value between 0 and 1, sorted by score in a descending manner
Background scores from corpus
'''
term_ranks = self.term_ranker(corp... | def get_scores(self, corpus):
'''
Parameters
----------
corpus
Returns
-------
float, pd.Series
float: point on x-axis at even characteristicness
pd.Series: term -> value between 0 and 1, sorted by score in a descending manner
Background scores from corpus
'''
term_ranks = self.term_ranker(corp... | [
"Parameters",
"----------",
"corpus"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/characteristic/DenseRankCharacteristicness.py#L37-L74 | [
"def",
"get_scores",
"(",
"self",
",",
"corpus",
")",
":",
"term_ranks",
"=",
"self",
".",
"term_ranker",
"(",
"corpus",
")",
".",
"get_ranks",
"(",
")",
"freq_df",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"'corpus'",
":",
"term_ranks",
".",
"sum",
"(",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PairPlotFromScatterplotStructure.to_html | Returns
-------
str, the html file representation | scattertext/viz/PairPlotFromScattertextStructure.py | def to_html(self):
'''
Returns
-------
str, the html file representation
'''
javascript_to_insert = '\n'.join([
PackedDataUtils.full_content_of_javascript_files(),
self.category_scatterplot_structure._visualization_data.to_javascript('getCategoryD... | def to_html(self):
'''
Returns
-------
str, the html file representation
'''
javascript_to_insert = '\n'.join([
PackedDataUtils.full_content_of_javascript_files(),
self.category_scatterplot_structure._visualization_data.to_javascript('getCategoryD... | [
"Returns",
"-------",
"str",
"the",
"html",
"file",
"representation"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/viz/PairPlotFromScattertextStructure.py#L60-L89 | [
"def",
"to_html",
"(",
"self",
")",
":",
"javascript_to_insert",
"=",
"'\\n'",
".",
"join",
"(",
"[",
"PackedDataUtils",
".",
"full_content_of_javascript_files",
"(",
")",
",",
"self",
".",
"category_scatterplot_structure",
".",
"_visualization_data",
".",
"to_javas... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | DiachronicTermMiner.get_display_dataframe | Gets list of terms to display that have some interesting diachronic variation.
Returns
-------
pd.DataFrame
e.g.,
term variable frequency trending
2 in 200310 1.0 0.000000
19 for 200310 1.0 0.000000
20 to 200311 1.0 0.000000 | scattertext/diachronic/DiachronicTermMiner.py | def get_display_dataframe(self):
'''
Gets list of terms to display that have some interesting diachronic variation.
Returns
-------
pd.DataFrame
e.g.,
term variable frequency trending
2 in 200310 1.0 0.000000
19 for 200310 1.0 0.000000
20 ... | def get_display_dataframe(self):
'''
Gets list of terms to display that have some interesting diachronic variation.
Returns
-------
pd.DataFrame
e.g.,
term variable frequency trending
2 in 200310 1.0 0.000000
19 for 200310 1.0 0.000000
20 ... | [
"Gets",
"list",
"of",
"terms",
"to",
"display",
"that",
"have",
"some",
"interesting",
"diachronic",
"variation",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/diachronic/DiachronicTermMiner.py#L37-L122 | [
"def",
"get_display_dataframe",
"(",
"self",
")",
":",
"X",
"=",
"self",
".",
"corpus_",
".",
"get_term_doc_mat",
"(",
")",
"categories",
"=",
"pd",
".",
"Series",
"(",
"self",
".",
"corpus_",
".",
"get_category_ids",
"(",
")",
")",
"cat_ar",
"=",
"np",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PhraseMachinePhrases.get_feats | Parameters
----------
doc, Spacy Doc
Returns
-------
Counter noun chunk -> count | scattertext/features/PhraseMachinePhrases.py | def get_feats(self, doc):
'''
Parameters
----------
doc, Spacy Doc
Returns
-------
Counter noun chunk -> count
'''
ngram_counter = Counter()
for sent in doc.sents:
ngram_counter += _phrase_counts(sent)
return ngram_counter | def get_feats(self, doc):
'''
Parameters
----------
doc, Spacy Doc
Returns
-------
Counter noun chunk -> count
'''
ngram_counter = Counter()
for sent in doc.sents:
ngram_counter += _phrase_counts(sent)
return ngram_counter | [
"Parameters",
"----------",
"doc",
"Spacy",
"Doc"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/features/PhraseMachinePhrases.py#L12-L25 | [
"def",
"get_feats",
"(",
"self",
",",
"doc",
")",
":",
"ngram_counter",
"=",
"Counter",
"(",
")",
"for",
"sent",
"in",
"doc",
".",
"sents",
":",
"ngram_counter",
"+=",
"_phrase_counts",
"(",
"sent",
")",
"return",
"ngram_counter"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PhraseMachinePhrasesAndUnigrams.get_feats | Parameters
----------
doc, Spacy Doc
Returns
-------
Counter noun chunk -> count | scattertext/features/PhraseMachinePhrases.py | def get_feats(self, doc):
'''
Parameters
----------
doc, Spacy Doc
Returns
-------
Counter noun chunk -> count
'''
# ngram_counter = phrasemachine.get_phrases(str(doc), tagger='spacy')['counts']
ngram_counter = Counter()
for sent in doc.sents:
unigrams = self._get_unigram_feats(sent)
ngram_... | def get_feats(self, doc):
'''
Parameters
----------
doc, Spacy Doc
Returns
-------
Counter noun chunk -> count
'''
# ngram_counter = phrasemachine.get_phrases(str(doc), tagger='spacy')['counts']
ngram_counter = Counter()
for sent in doc.sents:
unigrams = self._get_unigram_feats(sent)
ngram_... | [
"Parameters",
"----------",
"doc",
"Spacy",
"Doc"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/features/PhraseMachinePhrases.py#L33-L48 | [
"def",
"get_feats",
"(",
"self",
",",
"doc",
")",
":",
"# ngram_counter = phrasemachine.get_phrases(str(doc), tagger='spacy')['counts']",
"ngram_counter",
"=",
"Counter",
"(",
")",
"for",
"sent",
"in",
"doc",
".",
"sents",
":",
"unigrams",
"=",
"self",
".",
"_get_un... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | BasicHTMLFromScatterplotStructure.to_html | Parameters
----------
protocol : str
'http' or 'https' for including external urls
d3_url, str
None by default. The url (or path) of
d3, to be inserted into <script src="..."/>
By default, this is `DEFAULT_D3_URL` declared in `ScatterplotStructure`.
... | scattertext/viz/BasicHTMLFromScatterplotStructure.py | def to_html(self,
protocol='http',
d3_url=None,
d3_scale_chromatic_url=None,
html_base=None):
'''
Parameters
----------
protocol : str
'http' or 'https' for including external urls
d3_url, str
None... | def to_html(self,
protocol='http',
d3_url=None,
d3_scale_chromatic_url=None,
html_base=None):
'''
Parameters
----------
protocol : str
'http' or 'https' for including external urls
d3_url, str
None... | [
"Parameters",
"----------",
"protocol",
":",
"str",
"http",
"or",
"https",
"for",
"including",
"external",
"urls",
"d3_url",
"str",
"None",
"by",
"default",
".",
"The",
"url",
"(",
"or",
"path",
")",
"of",
"d3",
"to",
"be",
"inserted",
"into",
"<script",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/viz/BasicHTMLFromScatterplotStructure.py#L59-L116 | [
"def",
"to_html",
"(",
"self",
",",
"protocol",
"=",
"'http'",
",",
"d3_url",
"=",
"None",
",",
"d3_scale_chromatic_url",
"=",
"None",
",",
"html_base",
"=",
"None",
")",
":",
"d3_url_struct",
"=",
"D3URLs",
"(",
"d3_url",
",",
"d3_scale_chromatic_url",
")",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | Corpus.search | Parameters
----------
ngram str or unicode, string to search for
Returns
-------
pd.DataFrame, {'texts': <matching texts>, 'categories': <corresponding categories>} | scattertext/Corpus.py | def search(self, ngram):
'''
Parameters
----------
ngram str or unicode, string to search for
Returns
-------
pd.DataFrame, {'texts': <matching texts>, 'categories': <corresponding categories>}
'''
mask = self._document_index_mask(ngram)
return pd.DataFrame({
'text': self.get_texts()[mask],
... | def search(self, ngram):
'''
Parameters
----------
ngram str or unicode, string to search for
Returns
-------
pd.DataFrame, {'texts': <matching texts>, 'categories': <corresponding categories>}
'''
mask = self._document_index_mask(ngram)
return pd.DataFrame({
'text': self.get_texts()[mask],
... | [
"Parameters",
"----------",
"ngram",
"str",
"or",
"unicode",
"string",
"to",
"search",
"for"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/Corpus.py#L56-L72 | [
"def",
"search",
"(",
"self",
",",
"ngram",
")",
":",
"mask",
"=",
"self",
".",
"_document_index_mask",
"(",
"ngram",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'text'",
":",
"self",
".",
"get_texts",
"(",
")",
"[",
"mask",
"]",
",",
"'categor... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_term_freq_df | Parameters
-------
label_append : str
Returns
-------
pd.DataFrame indexed on terms, with columns giving frequencies for each | scattertext/TermDocMatrix.py | def get_term_freq_df(self, label_append=' freq'):
'''
Parameters
-------
label_append : str
Returns
-------
pd.DataFrame indexed on terms, with columns giving frequencies for each
'''
'''
row = self._row_category_ids()
newX = csr_... | def get_term_freq_df(self, label_append=' freq'):
'''
Parameters
-------
label_append : str
Returns
-------
pd.DataFrame indexed on terms, with columns giving frequencies for each
'''
'''
row = self._row_category_ids()
newX = csr_... | [
"Parameters",
"-------",
"label_append",
":",
"str"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L87-L106 | [
"def",
"get_term_freq_df",
"(",
"self",
",",
"label_append",
"=",
"' freq'",
")",
":",
"'''\n row = self._row_category_ids()\n newX = csr_matrix((self._X.data, (row, self._X.indices)))\n return self._term_freq_df_from_matrix(newX)\n '''",
"mat",
"=",
"self",
"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_term_freq_mat | Returns
-------
np.array with columns as categories and rows as terms | scattertext/TermDocMatrix.py | def get_term_freq_mat(self):
'''
Returns
-------
np.array with columns as categories and rows as terms
'''
freq_mat = np.zeros(shape=(self.get_num_terms(), self.get_num_categories()), dtype=int)
for cat_i in range(self.get_num_categories()):
freq_mat[:... | def get_term_freq_mat(self):
'''
Returns
-------
np.array with columns as categories and rows as terms
'''
freq_mat = np.zeros(shape=(self.get_num_terms(), self.get_num_categories()), dtype=int)
for cat_i in range(self.get_num_categories()):
freq_mat[:... | [
"Returns",
"-------",
"np",
".",
"array",
"with",
"columns",
"as",
"categories",
"and",
"rows",
"as",
"terms"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L108-L117 | [
"def",
"get_term_freq_mat",
"(",
"self",
")",
":",
"freq_mat",
"=",
"np",
".",
"zeros",
"(",
"shape",
"=",
"(",
"self",
".",
"get_num_terms",
"(",
")",
",",
"self",
".",
"get_num_categories",
"(",
")",
")",
",",
"dtype",
"=",
"int",
")",
"for",
"cat_... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_term_count_mat | Returns
-------
np.array with columns as categories and rows as terms | scattertext/TermDocMatrix.py | def get_term_count_mat(self):
'''
Returns
-------
np.array with columns as categories and rows as terms
'''
freq_mat = np.zeros(shape=(self.get_num_terms(), self.get_num_categories()), dtype=int)
for cat_i in range(self.get_num_categories()):
X = (self... | def get_term_count_mat(self):
'''
Returns
-------
np.array with columns as categories and rows as terms
'''
freq_mat = np.zeros(shape=(self.get_num_terms(), self.get_num_categories()), dtype=int)
for cat_i in range(self.get_num_categories()):
X = (self... | [
"Returns",
"-------",
"np",
".",
"array",
"with",
"columns",
"as",
"categories",
"and",
"rows",
"as",
"terms"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L119-L129 | [
"def",
"get_term_count_mat",
"(",
"self",
")",
":",
"freq_mat",
"=",
"np",
".",
"zeros",
"(",
"shape",
"=",
"(",
"self",
".",
"get_num_terms",
"(",
")",
",",
"self",
".",
"get_num_categories",
"(",
")",
")",
",",
"dtype",
"=",
"int",
")",
"for",
"cat... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_metadata_count_mat | Returns
-------
np.array with columns as categories and rows as terms | scattertext/TermDocMatrix.py | def get_metadata_count_mat(self):
'''
Returns
-------
np.array with columns as categories and rows as terms
'''
freq_mat = np.zeros(shape=(self.get_num_metadata(), self.get_num_categories()), dtype=int)
for cat_i in range(self.get_num_categories()):
mX... | def get_metadata_count_mat(self):
'''
Returns
-------
np.array with columns as categories and rows as terms
'''
freq_mat = np.zeros(shape=(self.get_num_metadata(), self.get_num_categories()), dtype=int)
for cat_i in range(self.get_num_categories()):
mX... | [
"Returns",
"-------",
"np",
".",
"array",
"with",
"columns",
"as",
"categories",
"and",
"rows",
"as",
"terms"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L131-L141 | [
"def",
"get_metadata_count_mat",
"(",
"self",
")",
":",
"freq_mat",
"=",
"np",
".",
"zeros",
"(",
"shape",
"=",
"(",
"self",
".",
"get_num_metadata",
"(",
")",
",",
"self",
".",
"get_num_categories",
"(",
")",
")",
",",
"dtype",
"=",
"int",
")",
"for",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_metadata_freq_df | Parameters
-------
label_append : str
Returns
-------
pd.DataFrame indexed on metadata, with columns giving frequencies for each category | scattertext/TermDocMatrix.py | def get_metadata_freq_df(self, label_append=' freq'):
'''
Parameters
-------
label_append : str
Returns
-------
pd.DataFrame indexed on metadata, with columns giving frequencies for each category
'''
row = self._row_category_ids_for_meta()
... | def get_metadata_freq_df(self, label_append=' freq'):
'''
Parameters
-------
label_append : str
Returns
-------
pd.DataFrame indexed on metadata, with columns giving frequencies for each category
'''
row = self._row_category_ids_for_meta()
... | [
"Parameters",
"-------",
"label_append",
":",
"str"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L187-L199 | [
"def",
"get_metadata_freq_df",
"(",
"self",
",",
"label_append",
"=",
"' freq'",
")",
":",
"row",
"=",
"self",
".",
"_row_category_ids_for_meta",
"(",
")",
"newX",
"=",
"csr_matrix",
"(",
"(",
"self",
".",
"_mX",
".",
"data",
",",
"(",
"row",
",",
"self"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.keep_only_these_categories | Non destructive category removal.
Parameters
----------
categories : list
list of categories to keep
ignore_absences : bool, False by default
if categories does not appear, don't raise an error, just move on.
Returns
-------
TermDocMatrix... | scattertext/TermDocMatrix.py | def keep_only_these_categories(self, categories, ignore_absences=False):
'''
Non destructive category removal.
Parameters
----------
categories : list
list of categories to keep
ignore_absences : bool, False by default
if categories does not appea... | def keep_only_these_categories(self, categories, ignore_absences=False):
'''
Non destructive category removal.
Parameters
----------
categories : list
list of categories to keep
ignore_absences : bool, False by default
if categories does not appea... | [
"Non",
"destructive",
"category",
"removal",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L229-L247 | [
"def",
"keep_only_these_categories",
"(",
"self",
",",
"categories",
",",
"ignore_absences",
"=",
"False",
")",
":",
"if",
"not",
"ignore_absences",
":",
"assert",
"set",
"(",
"self",
".",
"get_categories",
"(",
")",
")",
"&",
"set",
"(",
"categories",
")",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.remove_categories | Non destructive category removal.
Parameters
----------
categories : list
list of categories to remove
ignore_absences : bool, False by default
if categories does not appear, don't raise an error, just move on.
Returns
-------
TermDocMatr... | scattertext/TermDocMatrix.py | def remove_categories(self, categories, ignore_absences=False):
'''
Non destructive category removal.
Parameters
----------
categories : list
list of categories to remove
ignore_absences : bool, False by default
if categories does not appear, don'... | def remove_categories(self, categories, ignore_absences=False):
'''
Non destructive category removal.
Parameters
----------
categories : list
list of categories to remove
ignore_absences : bool, False by default
if categories does not appear, don'... | [
"Non",
"destructive",
"category",
"removal",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L249-L296 | [
"def",
"remove_categories",
"(",
"self",
",",
"categories",
",",
"ignore_absences",
"=",
"False",
")",
":",
"idx_to_delete_list",
"=",
"[",
"]",
"existing_categories",
"=",
"set",
"(",
"self",
".",
"get_categories",
"(",
")",
")",
"for",
"category",
"in",
"c... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.remove_terms_by_indices | Parameters
----------
idx_to_delete_list, list
Returns
-------
TermDocMatrix | scattertext/TermDocMatrix.py | def remove_terms_by_indices(self, idx_to_delete_list):
'''
Parameters
----------
idx_to_delete_list, list
Returns
-------
TermDocMatrix
'''
new_X, new_term_idx_store = self._get_X_after_delete_terms(idx_to_delete_list)
return self._make_ne... | def remove_terms_by_indices(self, idx_to_delete_list):
'''
Parameters
----------
idx_to_delete_list, list
Returns
-------
TermDocMatrix
'''
new_X, new_term_idx_store = self._get_X_after_delete_terms(idx_to_delete_list)
return self._make_ne... | [
"Parameters",
"----------",
"idx_to_delete_list",
"list"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L298-L310 | [
"def",
"remove_terms_by_indices",
"(",
"self",
",",
"idx_to_delete_list",
")",
":",
"new_X",
",",
"new_term_idx_store",
"=",
"self",
".",
"_get_X_after_delete_terms",
"(",
"idx_to_delete_list",
")",
"return",
"self",
".",
"_make_new_term_doc_matrix",
"(",
"new_X",
","... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_rudder_scores | Computes Rudder score.
Parameters
----------
category : str
category name to score
Returns
-------
np.array | scattertext/TermDocMatrix.py | def get_rudder_scores(self, category):
''' Computes Rudder score.
Parameters
----------
category : str
category name to score
Returns
-------
np.array
'''
category_percentiles = self._get_term_percentiles_in_category(category)
... | def get_rudder_scores(self, category):
''' Computes Rudder score.
Parameters
----------
category : str
category name to score
Returns
-------
np.array
'''
category_percentiles = self._get_term_percentiles_in_category(category)
... | [
"Computes",
"Rudder",
"score",
".",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L357-L372 | [
"def",
"get_rudder_scores",
"(",
"self",
",",
"category",
")",
":",
"category_percentiles",
"=",
"self",
".",
"_get_term_percentiles_in_category",
"(",
"category",
")",
"not_category_percentiles",
"=",
"self",
".",
"_get_term_percentiles_not_in_category",
"(",
"category",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_logistic_regression_coefs_l2 | Computes l2-penalized logistic regression score.
Parameters
----------
category : str
category name to score
category : str
category name to score
Returns
-------
(coefficient array, accuracy, majority class baseline accuracy) | scattertext/TermDocMatrix.py | def get_logistic_regression_coefs_l2(self, category,
clf=RidgeClassifierCV()):
''' Computes l2-penalized logistic regression score.
Parameters
----------
category : str
category name to score
category : str
categor... | def get_logistic_regression_coefs_l2(self, category,
clf=RidgeClassifierCV()):
''' Computes l2-penalized logistic regression score.
Parameters
----------
category : str
category name to score
category : str
categor... | [
"Computes",
"l2",
"-",
"penalized",
"logistic",
"regression",
"score",
".",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L391-L414 | [
"def",
"get_logistic_regression_coefs_l2",
"(",
"self",
",",
"category",
",",
"clf",
"=",
"RidgeClassifierCV",
"(",
")",
")",
":",
"try",
":",
"from",
"sklearn",
".",
"cross_validation",
"import",
"cross_val_predict",
"except",
":",
"from",
"sklearn",
".",
"mode... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_logistic_regression_coefs_l1 | Computes l1-penalized logistic regression score.
Parameters
----------
category : str
category name to score
Returns
-------
(coefficient array, accuracy, majority class baseline accuracy) | scattertext/TermDocMatrix.py | def get_logistic_regression_coefs_l1(self, category,
clf=LassoCV(alphas=[0.1, 0.001],
max_iter=10000,
n_jobs=-1)):
''' Computes l1-penalized logistic regression scor... | def get_logistic_regression_coefs_l1(self, category,
clf=LassoCV(alphas=[0.1, 0.001],
max_iter=10000,
n_jobs=-1)):
''' Computes l1-penalized logistic regression scor... | [
"Computes",
"l1",
"-",
"penalized",
"logistic",
"regression",
"score",
".",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L421-L448 | [
"def",
"get_logistic_regression_coefs_l1",
"(",
"self",
",",
"category",
",",
"clf",
"=",
"LassoCV",
"(",
"alphas",
"=",
"[",
"0.1",
",",
"0.001",
"]",
",",
"max_iter",
"=",
"10000",
",",
"n_jobs",
"=",
"-",
"1",
")",
")",
":",
"try",
":",
"from",
"s... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_regression_coefs | Computes regression score of tdfidf transformed features
Parameters
----------
category : str
category name to score
clf : sklearn regressor
Returns
-------
coefficient array | scattertext/TermDocMatrix.py | def get_regression_coefs(self, category, clf=ElasticNet()):
''' Computes regression score of tdfidf transformed features
Parameters
----------
category : str
category name to score
clf : sklearn regressor
Returns
-------
coefficient array
... | def get_regression_coefs(self, category, clf=ElasticNet()):
''' Computes regression score of tdfidf transformed features
Parameters
----------
category : str
category name to score
clf : sklearn regressor
Returns
-------
coefficient array
... | [
"Computes",
"regression",
"score",
"of",
"tdfidf",
"transformed",
"features",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score",
"clf",
":",
"sklearn",
"regressor"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L450-L463 | [
"def",
"get_regression_coefs",
"(",
"self",
",",
"category",
",",
"clf",
"=",
"ElasticNet",
"(",
")",
")",
":",
"self",
".",
"_fit_tfidf_model",
"(",
"category",
",",
"clf",
")",
"return",
"clf",
".",
"coef_"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_logreg_coefs | Computes regression score of tdfidf transformed features
Parameters
----------
category : str
category name to score
clf : sklearn regressor
Returns
-------
coefficient array | scattertext/TermDocMatrix.py | def get_logreg_coefs(self, category, clf=LogisticRegression()):
''' Computes regression score of tdfidf transformed features
Parameters
----------
category : str
category name to score
clf : sklearn regressor
Returns
-------
coefficient array
... | def get_logreg_coefs(self, category, clf=LogisticRegression()):
''' Computes regression score of tdfidf transformed features
Parameters
----------
category : str
category name to score
clf : sklearn regressor
Returns
-------
coefficient array
... | [
"Computes",
"regression",
"score",
"of",
"tdfidf",
"transformed",
"features",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score",
"clf",
":",
"sklearn",
"regressor"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L465-L478 | [
"def",
"get_logreg_coefs",
"(",
"self",
",",
"category",
",",
"clf",
"=",
"LogisticRegression",
"(",
")",
")",
":",
"self",
".",
"_fit_tfidf_model",
"(",
"category",
",",
"clf",
")",
"return",
"clf",
".",
"coef_",
"[",
"0",
"]"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_scaled_f_scores | Computes scaled-fscores
Parameters
----------
category : str
category name to score
scaler_algo : str
Function that scales an array to a range \in [0 and 1]. Use 'percentile', 'normcdf'. Default.
beta : float
Beta in (1+B^2) * (Scale(P(w|c)) * Sc... | scattertext/TermDocMatrix.py | def get_scaled_f_scores(self,
category,
scaler_algo=DEFAULT_SCALER_ALGO,
beta=DEFAULT_BETA):
''' Computes scaled-fscores
Parameters
----------
category : str
category name to score
sca... | def get_scaled_f_scores(self,
category,
scaler_algo=DEFAULT_SCALER_ALGO,
beta=DEFAULT_BETA):
''' Computes scaled-fscores
Parameters
----------
category : str
category name to score
sca... | [
"Computes",
"scaled",
"-",
"fscores",
"Parameters",
"----------",
"category",
":",
"str",
"category",
"name",
"to",
"score",
"scaler_algo",
":",
"str",
"Function",
"that",
"scales",
"an",
"array",
"to",
"a",
"range",
"\\",
"in",
"[",
"0",
"and",
"1",
"]",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L489-L510 | [
"def",
"get_scaled_f_scores",
"(",
"self",
",",
"category",
",",
"scaler_algo",
"=",
"DEFAULT_SCALER_ALGO",
",",
"beta",
"=",
"DEFAULT_BETA",
")",
":",
"assert",
"beta",
">",
"0",
"cat_word_counts",
",",
"not_cat_word_counts",
"=",
"self",
".",
"_get_catetgory_and... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix._get_scaled_f_score_from_counts | scaler = self._get_scaler_function(scaler_algo)
p_word_given_category = cat_word_counts.astype(np.float64) / cat_word_counts.sum()
p_category_given_word = cat_word_counts.astype(np.float64) / (cat_word_counts + not_cat_word_counts)
scores \
= self._computer_harmoic_mean_of_probabilit... | scattertext/TermDocMatrix.py | def _get_scaled_f_score_from_counts(self, cat_word_counts, not_cat_word_counts, scaler_algo,
beta=DEFAULT_BETA):
'''
scaler = self._get_scaler_function(scaler_algo)
p_word_given_category = cat_word_counts.astype(np.float64) / cat_word_counts.sum()
... | def _get_scaled_f_score_from_counts(self, cat_word_counts, not_cat_word_counts, scaler_algo,
beta=DEFAULT_BETA):
'''
scaler = self._get_scaler_function(scaler_algo)
p_word_given_category = cat_word_counts.astype(np.float64) / cat_word_counts.sum()
... | [
"scaler",
"=",
"self",
".",
"_get_scaler_function",
"(",
"scaler_algo",
")",
"p_word_given_category",
"=",
"cat_word_counts",
".",
"astype",
"(",
"np",
".",
"float64",
")",
"/",
"cat_word_counts",
".",
"sum",
"()",
"p_category_given_word",
"=",
"cat_word_counts",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L512-L523 | [
"def",
"_get_scaled_f_score_from_counts",
"(",
"self",
",",
"cat_word_counts",
",",
"not_cat_word_counts",
",",
"scaler_algo",
",",
"beta",
"=",
"DEFAULT_BETA",
")",
":",
"return",
"ScaledFScore",
".",
"get_scores",
"(",
"cat_word_counts",
",",
"not_cat_word_counts",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_fisher_scores_vs_background | Returns
-------
pd.DataFrame of fisher scores vs background | scattertext/TermDocMatrix.py | def get_fisher_scores_vs_background(self):
'''
Returns
-------
pd.DataFrame of fisher scores vs background
'''
df = self.get_term_and_background_counts()
odds_ratio, p_values = self._get_fisher_scores_from_counts(
df['corpus'], df['background'])
... | def get_fisher_scores_vs_background(self):
'''
Returns
-------
pd.DataFrame of fisher scores vs background
'''
df = self.get_term_and_background_counts()
odds_ratio, p_values = self._get_fisher_scores_from_counts(
df['corpus'], df['background'])
... | [
"Returns",
"-------",
"pd",
".",
"DataFrame",
"of",
"fisher",
"scores",
"vs",
"background"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L566-L579 | [
"def",
"get_fisher_scores_vs_background",
"(",
"self",
")",
":",
"df",
"=",
"self",
".",
"get_term_and_background_counts",
"(",
")",
"odds_ratio",
",",
"p_values",
"=",
"self",
".",
"_get_fisher_scores_from_counts",
"(",
"df",
"[",
"'corpus'",
"]",
",",
"df",
"[... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_posterior_mean_ratio_scores_vs_background | Returns
-------
pd.DataFrame of posterior mean scores vs background | scattertext/TermDocMatrix.py | def get_posterior_mean_ratio_scores_vs_background(self):
'''
Returns
-------
pd.DataFrame of posterior mean scores vs background
'''
df = self.get_term_and_background_counts()
df['Log Posterior Mean Ratio'] = self._get_posterior_mean_ratio_from_counts(df['cor... | def get_posterior_mean_ratio_scores_vs_background(self):
'''
Returns
-------
pd.DataFrame of posterior mean scores vs background
'''
df = self.get_term_and_background_counts()
df['Log Posterior Mean Ratio'] = self._get_posterior_mean_ratio_from_counts(df['cor... | [
"Returns",
"-------",
"pd",
".",
"DataFrame",
"of",
"posterior",
"mean",
"scores",
"vs",
"background"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L581-L590 | [
"def",
"get_posterior_mean_ratio_scores_vs_background",
"(",
"self",
")",
":",
"df",
"=",
"self",
".",
"get_term_and_background_counts",
"(",
")",
"df",
"[",
"'Log Posterior Mean Ratio'",
"]",
"=",
"self",
".",
"_get_posterior_mean_ratio_from_counts",
"(",
"df",
"[",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_rudder_scores_vs_background | Returns
-------
pd.DataFrame of rudder scores vs background | scattertext/TermDocMatrix.py | def get_rudder_scores_vs_background(self):
'''
Returns
-------
pd.DataFrame of rudder scores vs background
'''
df = self.get_term_and_background_counts()
corpus_percentiles = self._get_percentiles_from_freqs(df['corpus'])
background_percentiles = self._get... | def get_rudder_scores_vs_background(self):
'''
Returns
-------
pd.DataFrame of rudder scores vs background
'''
df = self.get_term_and_background_counts()
corpus_percentiles = self._get_percentiles_from_freqs(df['corpus'])
background_percentiles = self._get... | [
"Returns",
"-------",
"pd",
".",
"DataFrame",
"of",
"rudder",
"scores",
"vs",
"background"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L615-L627 | [
"def",
"get_rudder_scores_vs_background",
"(",
"self",
")",
":",
"df",
"=",
"self",
".",
"get_term_and_background_counts",
"(",
")",
"corpus_percentiles",
"=",
"self",
".",
"_get_percentiles_from_freqs",
"(",
"df",
"[",
"'corpus'",
"]",
")",
"background_percentiles",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.get_term_category_frequencies | Applies the ranker in scatterchartdata to term-category frequencies.
Parameters
----------
scatterchartdata : ScatterChartData
Returns
-------
pd.DataFrame | scattertext/TermDocMatrix.py | def get_term_category_frequencies(self, scatterchartdata):
'''
Applies the ranker in scatterchartdata to term-category frequencies.
Parameters
----------
scatterchartdata : ScatterChartData
Returns
-------
pd.DataFrame
'''
term_ranker = s... | def get_term_category_frequencies(self, scatterchartdata):
'''
Applies the ranker in scatterchartdata to term-category frequencies.
Parameters
----------
scatterchartdata : ScatterChartData
Returns
-------
pd.DataFrame
'''
term_ranker = s... | [
"Applies",
"the",
"ranker",
"in",
"scatterchartdata",
"to",
"term",
"-",
"category",
"frequencies",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L656-L671 | [
"def",
"get_term_category_frequencies",
"(",
"self",
",",
"scatterchartdata",
")",
":",
"term_ranker",
"=",
"scatterchartdata",
".",
"term_ranker",
"(",
"self",
")",
"if",
"scatterchartdata",
".",
"use_non_text_features",
":",
"term_ranker",
".",
"use_non_text_features"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.recategorize | Parameters
----------
new_categories : array like
String names of new categories. Length should be equal to number of documents
Returns
-------
TermDocMatrix | scattertext/TermDocMatrix.py | def recategorize(self, new_categories):
'''
Parameters
----------
new_categories : array like
String names of new categories. Length should be equal to number of documents
Returns
-------
TermDocMatrix
'''
assert len(new_categories) == sel... | def recategorize(self, new_categories):
'''
Parameters
----------
new_categories : array like
String names of new categories. Length should be equal to number of documents
Returns
-------
TermDocMatrix
'''
assert len(new_categories) == sel... | [
"Parameters",
"----------",
"new_categories",
":",
"array",
"like",
"String",
"names",
"of",
"new",
"categories",
".",
"Length",
"should",
"be",
"equal",
"to",
"number",
"of",
"documents"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L693-L711 | [
"def",
"recategorize",
"(",
"self",
",",
"new_categories",
")",
":",
"assert",
"len",
"(",
"new_categories",
")",
"==",
"self",
".",
"get_num_docs",
"(",
")",
"new_category_idx_store",
"=",
"IndexStoreFromList",
".",
"build",
"(",
"set",
"(",
"new_categories",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.use_categories_as_metadata | Returns a TermDocMatrix which is identical to self except the metadata values are now identical to the
categories present.
:return: TermDocMatrix | scattertext/TermDocMatrix.py | def use_categories_as_metadata(self):
'''
Returns a TermDocMatrix which is identical to self except the metadata values are now identical to the
categories present.
:return: TermDocMatrix
'''
new_metadata_factory = CSRMatrixFactory()
for i, category_idx in enume... | def use_categories_as_metadata(self):
'''
Returns a TermDocMatrix which is identical to self except the metadata values are now identical to the
categories present.
:return: TermDocMatrix
'''
new_metadata_factory = CSRMatrixFactory()
for i, category_idx in enume... | [
"Returns",
"a",
"TermDocMatrix",
"which",
"is",
"identical",
"to",
"self",
"except",
"the",
"metadata",
"values",
"are",
"now",
"identical",
"to",
"the",
"categories",
"present",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L713-L731 | [
"def",
"use_categories_as_metadata",
"(",
"self",
")",
":",
"new_metadata_factory",
"=",
"CSRMatrixFactory",
"(",
")",
"for",
"i",
",",
"category_idx",
"in",
"enumerate",
"(",
"self",
".",
"get_category_ids",
"(",
")",
")",
":",
"new_metadata_factory",
"[",
"i",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | TermDocMatrix.use_categories_as_metadata_and_replace_terms | Returns a TermDocMatrix which is identical to self except the metadata values are now identical to the
categories present and term-doc-matrix is now the metadata matrix.
:return: TermDocMatrix | scattertext/TermDocMatrix.py | def use_categories_as_metadata_and_replace_terms(self):
'''
Returns a TermDocMatrix which is identical to self except the metadata values are now identical to the
categories present and term-doc-matrix is now the metadata matrix.
:return: TermDocMatrix
'''
new_metadata_... | def use_categories_as_metadata_and_replace_terms(self):
'''
Returns a TermDocMatrix which is identical to self except the metadata values are now identical to the
categories present and term-doc-matrix is now the metadata matrix.
:return: TermDocMatrix
'''
new_metadata_... | [
"Returns",
"a",
"TermDocMatrix",
"which",
"is",
"identical",
"to",
"self",
"except",
"the",
"metadata",
"values",
"are",
"now",
"identical",
"to",
"the",
"categories",
"present",
"and",
"term",
"-",
"doc",
"-",
"matrix",
"is",
"now",
"the",
"metadata",
"matr... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/TermDocMatrix.py#L733-L751 | [
"def",
"use_categories_as_metadata_and_replace_terms",
"(",
"self",
")",
":",
"new_metadata_factory",
"=",
"CSRMatrixFactory",
"(",
")",
"for",
"i",
",",
"category_idx",
"in",
"enumerate",
"(",
"self",
".",
"get_category_ids",
"(",
")",
")",
":",
"new_metadata_facto... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | RottenTomatoes.get_data | Returns
-------
pd.DataFrame
I.e.,
>>> convention_df.iloc[0]
category plot
filename subjectivity_html/obj/2002/Abandon.html
text A senior at an elite college (Katie Holmes), a...
movie_name ... | scattertext/SampleCorpora.py | def get_data():
'''
Returns
-------
pd.DataFrame
I.e.,
>>> convention_df.iloc[0]
category plot
filename subjectivity_html/obj/2002/Abandon.html
text A senior at an elite college (Katie Holmes), a...
movie_name ... | def get_data():
'''
Returns
-------
pd.DataFrame
I.e.,
>>> convention_df.iloc[0]
category plot
filename subjectivity_html/obj/2002/Abandon.html
text A senior at an elite college (Katie Holmes), a...
movie_name ... | [
"Returns",
"-------",
"pd",
".",
"DataFrame"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/SampleCorpora.py#L94-L112 | [
"def",
"get_data",
"(",
")",
":",
"try",
":",
"data_stream",
"=",
"pkgutil",
".",
"get_data",
"(",
"'scattertext'",
",",
"'data/rotten_tomatoes_corpus.csv.bz2'",
")",
"except",
":",
"url",
"=",
"ROTTEN_TOMATOES_DATA_URL",
"data_stream",
"=",
"urlopen",
"(",
"url",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.use_general_term_frequencies | Returns
-------
PriorFactory | scattertext/PriorFactory.py | def use_general_term_frequencies(self):
'''
Returns
-------
PriorFactory
'''
tdf = self._get_relevant_term_freq()
bg_df = self.term_doc_mat.get_term_and_background_counts()[['background']]
bg_df = pd.merge(tdf,
bg_df,
left_index=True,
right_index=... | def use_general_term_frequencies(self):
'''
Returns
-------
PriorFactory
'''
tdf = self._get_relevant_term_freq()
bg_df = self.term_doc_mat.get_term_and_background_counts()[['background']]
bg_df = pd.merge(tdf,
bg_df,
left_index=True,
right_index=... | [
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L51-L65 | [
"def",
"use_general_term_frequencies",
"(",
"self",
")",
":",
"tdf",
"=",
"self",
".",
"_get_relevant_term_freq",
"(",
")",
"bg_df",
"=",
"self",
".",
"term_doc_mat",
".",
"get_term_and_background_counts",
"(",
")",
"[",
"[",
"'background'",
"]",
"]",
"bg_df",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.use_custom_term_frequencies | Parameters
----------
pd.Series
term -> frequency
Returns
-------
PriorFactory | scattertext/PriorFactory.py | def use_custom_term_frequencies(self, custom_term_frequencies):
'''
Parameters
----------
pd.Series
term -> frequency
Returns
-------
PriorFactory
'''
self.priors += custom_term_frequencies.reindex(self.priors.index).fillna(0)
return self | def use_custom_term_frequencies(self, custom_term_frequencies):
'''
Parameters
----------
pd.Series
term -> frequency
Returns
-------
PriorFactory
'''
self.priors += custom_term_frequencies.reindex(self.priors.index).fillna(0)
return self | [
"Parameters",
"----------",
"pd",
".",
"Series",
"term",
"-",
">",
"frequency",
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L77-L88 | [
"def",
"use_custom_term_frequencies",
"(",
"self",
",",
"custom_term_frequencies",
")",
":",
"self",
".",
"priors",
"+=",
"custom_term_frequencies",
".",
"reindex",
"(",
"self",
".",
"priors",
".",
"index",
")",
".",
"fillna",
"(",
"0",
")",
"return",
"self"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.use_all_categories | Returns
-------
PriorFactory | scattertext/PriorFactory.py | def use_all_categories(self):
'''
Returns
-------
PriorFactory
'''
term_df = self.term_ranker.get_ranks()
self.priors += term_df.sum(axis=1).fillna(0.)
return self | def use_all_categories(self):
'''
Returns
-------
PriorFactory
'''
term_df = self.term_ranker.get_ranks()
self.priors += term_df.sum(axis=1).fillna(0.)
return self | [
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L95-L103 | [
"def",
"use_all_categories",
"(",
"self",
")",
":",
"term_df",
"=",
"self",
".",
"term_ranker",
".",
"get_ranks",
"(",
")",
"self",
".",
"priors",
"+=",
"term_df",
".",
"sum",
"(",
"axis",
"=",
"1",
")",
".",
"fillna",
"(",
"0.",
")",
"return",
"self... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.use_neutral_categories | Returns
-------
PriorFactory | scattertext/PriorFactory.py | def use_neutral_categories(self):
'''
Returns
-------
PriorFactory
'''
term_df = self.term_ranker.get_ranks()
self.priors += term_df[[c + ' freq' for c in self._get_neutral_categories()]].sum(axis=1)
return self | def use_neutral_categories(self):
'''
Returns
-------
PriorFactory
'''
term_df = self.term_ranker.get_ranks()
self.priors += term_df[[c + ' freq' for c in self._get_neutral_categories()]].sum(axis=1)
return self | [
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L105-L113 | [
"def",
"use_neutral_categories",
"(",
"self",
")",
":",
"term_df",
"=",
"self",
".",
"term_ranker",
".",
"get_ranks",
"(",
")",
"self",
".",
"priors",
"+=",
"term_df",
"[",
"[",
"c",
"+",
"' freq'",
"for",
"c",
"in",
"self",
".",
"_get_neutral_categories",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.drop_neutral_categories_from_corpus | Returns
-------
PriorFactory | scattertext/PriorFactory.py | def drop_neutral_categories_from_corpus(self):
'''
Returns
-------
PriorFactory
'''
neutral_categories = self._get_neutral_categories()
self.term_doc_mat = self.term_doc_mat.remove_categories(neutral_categories)
self._reindex_priors()
return self | def drop_neutral_categories_from_corpus(self):
'''
Returns
-------
PriorFactory
'''
neutral_categories = self._get_neutral_categories()
self.term_doc_mat = self.term_doc_mat.remove_categories(neutral_categories)
self._reindex_priors()
return self | [
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L115-L124 | [
"def",
"drop_neutral_categories_from_corpus",
"(",
"self",
")",
":",
"neutral_categories",
"=",
"self",
".",
"_get_neutral_categories",
"(",
")",
"self",
".",
"term_doc_mat",
"=",
"self",
".",
"term_doc_mat",
".",
"remove_categories",
"(",
"neutral_categories",
")",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.drop_unused_terms | Returns
-------
PriorFactory | scattertext/PriorFactory.py | def drop_unused_terms(self):
'''
Returns
-------
PriorFactory
'''
self.term_doc_mat = self.term_doc_mat.remove_terms(
set(self.term_doc_mat.get_terms()) - set(self.priors.index)
)
self._reindex_priors()
return self | def drop_unused_terms(self):
'''
Returns
-------
PriorFactory
'''
self.term_doc_mat = self.term_doc_mat.remove_terms(
set(self.term_doc_mat.get_terms()) - set(self.priors.index)
)
self._reindex_priors()
return self | [
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L133-L143 | [
"def",
"drop_unused_terms",
"(",
"self",
")",
":",
"self",
".",
"term_doc_mat",
"=",
"self",
".",
"term_doc_mat",
".",
"remove_terms",
"(",
"set",
"(",
"self",
".",
"term_doc_mat",
".",
"get_terms",
"(",
")",
")",
"-",
"set",
"(",
"self",
".",
"priors",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.drop_zero_priors | Returns
-------
PriorFactory | scattertext/PriorFactory.py | def drop_zero_priors(self):
'''
Returns
-------
PriorFactory
'''
self.term_doc_mat = self.term_doc_mat.remove_terms(
self.priors[self.priors == 0].index
)
self._reindex_priors()
return self | def drop_zero_priors(self):
'''
Returns
-------
PriorFactory
'''
self.term_doc_mat = self.term_doc_mat.remove_terms(
self.priors[self.priors == 0].index
)
self._reindex_priors()
return self | [
"Returns",
"-------",
"PriorFactory"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L145-L155 | [
"def",
"drop_zero_priors",
"(",
"self",
")",
":",
"self",
".",
"term_doc_mat",
"=",
"self",
".",
"term_doc_mat",
".",
"remove_terms",
"(",
"self",
".",
"priors",
"[",
"self",
".",
"priors",
"==",
"0",
"]",
".",
"index",
")",
"self",
".",
"_reindex_priors... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.align_to_target | Parameters
----------
target_term_doc_mat : TermDocMatrix
Returns
-------
PriorFactory | scattertext/PriorFactory.py | def align_to_target(self, target_term_doc_mat):
'''
Parameters
----------
target_term_doc_mat : TermDocMatrix
Returns
-------
PriorFactory
'''
self.priors = self.priors[target_term_doc_mat.get_terms()].fillna(0)
return self | def align_to_target(self, target_term_doc_mat):
'''
Parameters
----------
target_term_doc_mat : TermDocMatrix
Returns
-------
PriorFactory
'''
self.priors = self.priors[target_term_doc_mat.get_terms()].fillna(0)
return self | [
"Parameters",
"----------",
"target_term_doc_mat",
":",
"TermDocMatrix"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L157-L168 | [
"def",
"align_to_target",
"(",
"self",
",",
"target_term_doc_mat",
")",
":",
"self",
".",
"priors",
"=",
"self",
".",
"priors",
"[",
"target_term_doc_mat",
".",
"get_terms",
"(",
")",
"]",
".",
"fillna",
"(",
"0",
")",
"return",
"self"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PriorFactory.get_priors | Returns
-------
pd.Series | scattertext/PriorFactory.py | def get_priors(self):
'''
Returns
-------
pd.Series
'''
priors = self.priors
priors[~np.isfinite(priors)] = 0
priors += self.starting_count
return priors | def get_priors(self):
'''
Returns
-------
pd.Series
'''
priors = self.priors
priors[~np.isfinite(priors)] = 0
priors += self.starting_count
return priors | [
"Returns",
"-------",
"pd",
".",
"Series"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/PriorFactory.py#L178-L187 | [
"def",
"get_priors",
"(",
"self",
")",
":",
"priors",
"=",
"self",
".",
"priors",
"priors",
"[",
"~",
"np",
".",
"isfinite",
"(",
"priors",
")",
"]",
"=",
"0",
"priors",
"+=",
"self",
".",
"starting_count",
"return",
"priors"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | LogOddsRatioUninformativeDirichletPrior.get_zeta_i_j_given_separate_counts | Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positive class
y_j, np.array(int)
Returns
-------
np.array of z-scores | scattertext/termsignificance/LogOddsRatioUninformativeDirichletPrior.py | def get_zeta_i_j_given_separate_counts(self, y_i, y_j):
'''
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positive class
y_j, np.array(int)
Returns
-------
np.array of z-scores
'''
yp_i = y_i + self.alpha_w
yp_j = y_j + self.alpha_w
np_i = np.sum(yp_i)
... | def get_zeta_i_j_given_separate_counts(self, y_i, y_j):
'''
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positive class
y_j, np.array(int)
Returns
-------
np.array of z-scores
'''
yp_i = y_i + self.alpha_w
yp_j = y_j + self.alpha_w
np_i = np.sum(yp_i)
... | [
"Parameters",
"----------",
"y_i",
"np",
".",
"array",
"(",
"int",
")",
"Arrays",
"of",
"word",
"counts",
"of",
"words",
"occurring",
"in",
"positive",
"class",
"y_j",
"np",
".",
"array",
"(",
"int",
")"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termsignificance/LogOddsRatioUninformativeDirichletPrior.py#L61-L84 | [
"def",
"get_zeta_i_j_given_separate_counts",
"(",
"self",
",",
"y_i",
",",
"y_j",
")",
":",
"yp_i",
"=",
"y_i",
"+",
"self",
".",
"alpha_w",
"yp_j",
"=",
"y_j",
"+",
"self",
".",
"alpha_w",
"np_i",
"=",
"np",
".",
"sum",
"(",
"yp_i",
")",
"np_j",
"="... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | LogOddsRatioUninformativeDirichletPrior.get_zeta_i_j | Parameters
----------
X : np.array
Array of word counts, shape (N, 2) where N is the vocab size. X[:,0] is the
positive class, while X[:,1] is the negative class. None by default
Returns
-------
np.array of z-scores | scattertext/termsignificance/LogOddsRatioUninformativeDirichletPrior.py | def get_zeta_i_j(self, X):
'''
Parameters
----------
X : np.array
Array of word counts, shape (N, 2) where N is the vocab size. X[:,0] is the
positive class, while X[:,1] is the negative class. None by default
Returns
-------
np.array of z-scores
'''
y_i, y_j = X.T[0], X.T[1]
return self.get... | def get_zeta_i_j(self, X):
'''
Parameters
----------
X : np.array
Array of word counts, shape (N, 2) where N is the vocab size. X[:,0] is the
positive class, while X[:,1] is the negative class. None by default
Returns
-------
np.array of z-scores
'''
y_i, y_j = X.T[0], X.T[1]
return self.get... | [
"Parameters",
"----------",
"X",
":",
"np",
".",
"array",
"Array",
"of",
"word",
"counts",
"shape",
"(",
"N",
"2",
")",
"where",
"N",
"is",
"the",
"vocab",
"size",
".",
"X",
"[",
":",
"0",
"]",
"is",
"the",
"positive",
"class",
"while",
"X",
"[",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termsignificance/LogOddsRatioUninformativeDirichletPrior.py#L86-L99 | [
"def",
"get_zeta_i_j",
"(",
"self",
",",
"X",
")",
":",
"y_i",
",",
"y_j",
"=",
"X",
".",
"T",
"[",
"0",
"]",
",",
"X",
".",
"T",
"[",
"1",
"]",
"return",
"self",
".",
"get_zeta_i_j_given_separate_counts",
"(",
"y_i",
",",
"y_j",
")"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | LogOddsRatioUninformativeDirichletPrior.get_scores | Same function as get_zeta_i_j_given_separate_counts
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positive class
y_j, np.array(int)
Returns
-------
np.array of z-scores | scattertext/termsignificance/LogOddsRatioUninformativeDirichletPrior.py | def get_scores(self, y_i, y_j):
'''
Same function as get_zeta_i_j_given_separate_counts
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positive class
y_j, np.array(int)
Returns
-------
np.array of z-scores
'''
z_scores = self.get_zeta_i_j_given_separate_c... | def get_scores(self, y_i, y_j):
'''
Same function as get_zeta_i_j_given_separate_counts
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positive class
y_j, np.array(int)
Returns
-------
np.array of z-scores
'''
z_scores = self.get_zeta_i_j_given_separate_c... | [
"Same",
"function",
"as",
"get_zeta_i_j_given_separate_counts"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termsignificance/LogOddsRatioUninformativeDirichletPrior.py#L107-L123 | [
"def",
"get_scores",
"(",
"self",
",",
"y_i",
",",
"y_j",
")",
":",
"z_scores",
"=",
"self",
".",
"get_zeta_i_j_given_separate_counts",
"(",
"y_i",
",",
"y_j",
")",
"# scaled_scores = scale_neg_1_to_1_with_zero_mean_abs_max(z_scores)",
"return",
"z_scores"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | PhraseSelector.compact | Parameters
-------
term_doc_matrix : TermDocMatrix
Returns
-------
New term doc matrix | scattertext/termcompaction/PhraseSelector.py | def compact(self, term_doc_matrix):
'''
Parameters
-------
term_doc_matrix : TermDocMatrix
Returns
-------
New term doc matrix
'''
count_df = self._get_statistics_dataframe(term_doc_matrix)
return term_doc_matrix.remove_terms(
count_df[count_df['pmi'] < self.minimum_pmi].index
) | def compact(self, term_doc_matrix):
'''
Parameters
-------
term_doc_matrix : TermDocMatrix
Returns
-------
New term doc matrix
'''
count_df = self._get_statistics_dataframe(term_doc_matrix)
return term_doc_matrix.remove_terms(
count_df[count_df['pmi'] < self.minimum_pmi].index
) | [
"Parameters",
"-------",
"term_doc_matrix",
":",
"TermDocMatrix"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termcompaction/PhraseSelector.py#L20-L35 | [
"def",
"compact",
"(",
"self",
",",
"term_doc_matrix",
")",
":",
"count_df",
"=",
"self",
".",
"_get_statistics_dataframe",
"(",
"term_doc_matrix",
")",
"return",
"term_doc_matrix",
".",
"remove_terms",
"(",
"count_df",
"[",
"count_df",
"[",
"'pmi'",
"]",
"<",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | check_topic_model_string_format | Parameters
----------
term_dict: dict {metadataname: [term1, term2, ....], ...}
Returns
-------
None | scattertext/ScatterChart.py | def check_topic_model_string_format(term_dict):
'''
Parameters
----------
term_dict: dict {metadataname: [term1, term2, ....], ...}
Returns
-------
None
'''
if type(term_dict) != dict:
raise TypeError("Argument for term_dict must be a dict, keyed on strings, and contain a li... | def check_topic_model_string_format(term_dict):
'''
Parameters
----------
term_dict: dict {metadataname: [term1, term2, ....], ...}
Returns
-------
None
'''
if type(term_dict) != dict:
raise TypeError("Argument for term_dict must be a dict, keyed on strings, and contain a li... | [
"Parameters",
"----------",
"term_dict",
":",
"dict",
"{",
"metadataname",
":",
"[",
"term1",
"term2",
"....",
"]",
"...",
"}"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/ScatterChart.py#L26-L54 | [
"def",
"check_topic_model_string_format",
"(",
"term_dict",
")",
":",
"if",
"type",
"(",
"term_dict",
")",
"!=",
"dict",
":",
"raise",
"TypeError",
"(",
"\"Argument for term_dict must be a dict, keyed on strings, and contain a list of strings.\"",
")",
"for",
"k",
",",
"v... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScatterChart.inject_metadata_term_lists | Inserts dictionary of meta data terms into object.
Parameters
----------
term_dict: dict {metadataname: [term1, term2, ....], ...}
Returns
-------
self: ScatterChart | scattertext/ScatterChart.py | def inject_metadata_term_lists(self, term_dict):
'''
Inserts dictionary of meta data terms into object.
Parameters
----------
term_dict: dict {metadataname: [term1, term2, ....], ...}
Returns
-------
self: ScatterChart
'''
check_topic_mod... | def inject_metadata_term_lists(self, term_dict):
'''
Inserts dictionary of meta data terms into object.
Parameters
----------
term_dict: dict {metadataname: [term1, term2, ....], ...}
Returns
-------
self: ScatterChart
'''
check_topic_mod... | [
"Inserts",
"dictionary",
"of",
"meta",
"data",
"terms",
"into",
"object",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/ScatterChart.py#L86-L104 | [
"def",
"inject_metadata_term_lists",
"(",
"self",
",",
"term_dict",
")",
":",
"check_topic_model_string_format",
"(",
"term_dict",
")",
"if",
"not",
"self",
".",
"term_doc_matrix",
".",
"metadata_in_use",
"(",
")",
":",
"raise",
"TermDocMatrixHasNoMetadataException",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScatterChart.inject_metadata_descriptions | Inserts a set of descriptions of meta data terms. These will be displayed
below the scatter plot when a meta data term is clicked. All keys in the term dict
must occur as meta data.
Parameters
----------
term_dict: dict {metadataname: str: 'explanation to insert', ...}
... | scattertext/ScatterChart.py | def inject_metadata_descriptions(self, term_dict):
'''
Inserts a set of descriptions of meta data terms. These will be displayed
below the scatter plot when a meta data term is clicked. All keys in the term dict
must occur as meta data.
Parameters
----------
ter... | def inject_metadata_descriptions(self, term_dict):
'''
Inserts a set of descriptions of meta data terms. These will be displayed
below the scatter plot when a meta data term is clicked. All keys in the term dict
must occur as meta data.
Parameters
----------
ter... | [
"Inserts",
"a",
"set",
"of",
"descriptions",
"of",
"meta",
"data",
"terms",
".",
"These",
"will",
"be",
"displayed",
"below",
"the",
"scatter",
"plot",
"when",
"a",
"meta",
"data",
"term",
"is",
"clicked",
".",
"All",
"keys",
"in",
"the",
"term",
"dict",... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/ScatterChart.py#L106-L134 | [
"def",
"inject_metadata_descriptions",
"(",
"self",
",",
"term_dict",
")",
":",
"assert",
"type",
"(",
"term_dict",
")",
"==",
"dict",
"if",
"not",
"self",
".",
"term_doc_matrix",
".",
"metadata_in_use",
"(",
")",
":",
"raise",
"TermDocMatrixHasNoMetadataException... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScatterChart.inject_coordinates | Inject custom x and y coordinates for each term into chart.
Parameters
----------
x_coords: array-like
positions on x-axis \in [0,1]
y_coords: array-like
positions on y-axis \in [0,1]
rescale_x: lambda list[0,1]: list[0,1], default identity
Re... | scattertext/ScatterChart.py | def inject_coordinates(self,
x_coords,
y_coords,
rescale_x=None,
rescale_y=None,
original_x=None,
original_y=None):
'''
Inject custom x and y ... | def inject_coordinates(self,
x_coords,
y_coords,
rescale_x=None,
rescale_y=None,
original_x=None,
original_y=None):
'''
Inject custom x and y ... | [
"Inject",
"custom",
"x",
"and",
"y",
"coordinates",
"for",
"each",
"term",
"into",
"chart",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/ScatterChart.py#L145-L181 | [
"def",
"inject_coordinates",
"(",
"self",
",",
"x_coords",
",",
"y_coords",
",",
"rescale_x",
"=",
"None",
",",
"rescale_y",
"=",
"None",
",",
"original_x",
"=",
"None",
",",
"original_y",
"=",
"None",
")",
":",
"self",
".",
"_verify_coordinates",
"(",
"x_... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScatterChart._add_jitter | :param vec: array to jitter
:return: array, jittered version of arrays | scattertext/ScatterChart.py | def _add_jitter(self, vec):
"""
:param vec: array to jitter
:return: array, jittered version of arrays
"""
if self.scatterchartdata.jitter == 0 or self.scatterchartdata.jitter is None:
return vec
return vec + np.random.rand(1, len(vec))[0] * self.scatterchartd... | def _add_jitter(self, vec):
"""
:param vec: array to jitter
:return: array, jittered version of arrays
"""
if self.scatterchartdata.jitter == 0 or self.scatterchartdata.jitter is None:
return vec
return vec + np.random.rand(1, len(vec))[0] * self.scatterchartd... | [
":",
"param",
"vec",
":",
"array",
"to",
"jitter",
":",
"return",
":",
"array",
"jittered",
"version",
"of",
"arrays"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/ScatterChart.py#L470-L477 | [
"def",
"_add_jitter",
"(",
"self",
",",
"vec",
")",
":",
"if",
"self",
".",
"scatterchartdata",
".",
"jitter",
"==",
"0",
"or",
"self",
".",
"scatterchartdata",
".",
"jitter",
"is",
"None",
":",
"return",
"vec",
"return",
"vec",
"+",
"np",
".",
"random... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | ScatterChart.draw | Outdated. MPLD3 drawing.
Parameters
----------
category
num_top_words_to_annotate
words_to_annotate
scores
transform
Returns
-------
pd.DataFrame, html of fgure | scattertext/ScatterChart.py | def draw(self,
category,
num_top_words_to_annotate=4,
words_to_annotate=[],
scores=None,
transform=percentile_alphabetical):
'''Outdated. MPLD3 drawing.
Parameters
----------
category
num_top_words_to_annotate
... | def draw(self,
category,
num_top_words_to_annotate=4,
words_to_annotate=[],
scores=None,
transform=percentile_alphabetical):
'''Outdated. MPLD3 drawing.
Parameters
----------
category
num_top_words_to_annotate
... | [
"Outdated",
".",
"MPLD3",
"drawing",
"."
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/ScatterChart.py#L551-L634 | [
"def",
"draw",
"(",
"self",
",",
"category",
",",
"num_top_words_to_annotate",
"=",
"4",
",",
"words_to_annotate",
"=",
"[",
"]",
",",
"scores",
"=",
"None",
",",
"transform",
"=",
"percentile_alphabetical",
")",
":",
"try",
":",
"import",
"matplotlib",
".",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | LogOddsRatioSmoothed.get_zeta_i_j_given_separate_counts | Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positi ve class
y_j, np.array(int)
Returns
-------
np.array of z-scores | scattertext/termsignificance/LogOddsRatioSmoothed.py | def get_zeta_i_j_given_separate_counts(self, y_i, y_j):
'''
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positi ve class
y_j, np.array(int)
Returns
-------
np.array of z-scores
'''
n_i, n_j = y_i.sum(), y_j.sum()
delta_i_j = (np.log((y_i + 1) / (1. + n_i... | def get_zeta_i_j_given_separate_counts(self, y_i, y_j):
'''
Parameters
----------
y_i, np.array(int)
Arrays of word counts of words occurring in positi ve class
y_j, np.array(int)
Returns
-------
np.array of z-scores
'''
n_i, n_j = y_i.sum(), y_j.sum()
delta_i_j = (np.log((y_i + 1) / (1. + n_i... | [
"Parameters",
"----------",
"y_i",
"np",
".",
"array",
"(",
"int",
")",
"Arrays",
"of",
"word",
"counts",
"of",
"words",
"occurring",
"in",
"positi",
"ve",
"class",
"y_j",
"np",
".",
"array",
"(",
"int",
")"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termsignificance/LogOddsRatioSmoothed.py#L57-L72 | [
"def",
"get_zeta_i_j_given_separate_counts",
"(",
"self",
",",
"y_i",
",",
"y_j",
")",
":",
"n_i",
",",
"n_j",
"=",
"y_i",
".",
"sum",
"(",
")",
",",
"y_j",
".",
"sum",
"(",
")",
"delta_i_j",
"=",
"(",
"np",
".",
"log",
"(",
"(",
"y_i",
"+",
"1",... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | OLSUngarStyle.get_scores_and_p_values | Parameters
----------
tdm: TermDocMatrix
category: str, category name
Returns
-------
pd.DataFrame(['coef', 'p-val']) | scattertext/termscoring/OLSUngnarStyle.py | def get_scores_and_p_values(self, tdm, category):
'''
Parameters
----------
tdm: TermDocMatrix
category: str, category name
Returns
-------
pd.DataFrame(['coef', 'p-val'])
'''
X = tdm._X
y = self._make_response_variable_1_or_negative_1(category, tdm)
pX = X / X.sum(axis=1)
ansX = self._anscom... | def get_scores_and_p_values(self, tdm, category):
'''
Parameters
----------
tdm: TermDocMatrix
category: str, category name
Returns
-------
pd.DataFrame(['coef', 'p-val'])
'''
X = tdm._X
y = self._make_response_variable_1_or_negative_1(category, tdm)
pX = X / X.sum(axis=1)
ansX = self._anscom... | [
"Parameters",
"----------",
"tdm",
":",
"TermDocMatrix",
"category",
":",
"str",
"category",
"name"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/termscoring/OLSUngnarStyle.py#L6-L22 | [
"def",
"get_scores_and_p_values",
"(",
"self",
",",
"tdm",
",",
"category",
")",
":",
"X",
"=",
"tdm",
".",
"_X",
"y",
"=",
"self",
".",
"_make_response_variable_1_or_negative_1",
"(",
"category",
",",
"tdm",
")",
"pX",
"=",
"X",
"/",
"X",
".",
"sum",
... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | delete_columns | >>> a = csr_matrix(np.array([[0, 1, 3, 0, 1, 0],
[0, 0, 1, 0, 1, 1]])
>>> delete_columns(a, [1,2]).todense()
matrix([[0, 0, 1, 0],
[0, 0, 1, 1]])
Parameters
----------
mat : csr_matrix
columns_to_delete : list[int]
Returns
-------
csr_matrix that is stripped of columns ... | scattertext/CSRMatrixTools.py | def delete_columns(mat, columns_to_delete):
'''
>>> a = csr_matrix(np.array([[0, 1, 3, 0, 1, 0],
[0, 0, 1, 0, 1, 1]])
>>> delete_columns(a, [1,2]).todense()
matrix([[0, 0, 1, 0],
[0, 0, 1, 1]])
Parameters
----------
mat : csr_matrix
columns_to_delete : list[int]
Returns... | def delete_columns(mat, columns_to_delete):
'''
>>> a = csr_matrix(np.array([[0, 1, 3, 0, 1, 0],
[0, 0, 1, 0, 1, 1]])
>>> delete_columns(a, [1,2]).todense()
matrix([[0, 0, 1, 0],
[0, 0, 1, 1]])
Parameters
----------
mat : csr_matrix
columns_to_delete : list[int]
Returns... | [
">>>",
"a",
"=",
"csr_matrix",
"(",
"np",
".",
"array",
"(",
"[[",
"0",
"1",
"3",
"0",
"1",
"0",
"]",
"[",
"0",
"0",
"1",
"0",
"1",
"1",
"]]",
")",
">>>",
"delete_columns",
"(",
"a",
"[",
"1",
"2",
"]",
")",
".",
"todense",
"()",
"matrix",
... | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/CSRMatrixTools.py#L71-L90 | [
"def",
"delete_columns",
"(",
"mat",
",",
"columns_to_delete",
")",
":",
"column_mask",
"=",
"np",
".",
"ones",
"(",
"mat",
".",
"shape",
"[",
"1",
"]",
",",
"dtype",
"=",
"bool",
")",
"column_mask",
"[",
"columns_to_delete",
"]",
"=",
"0",
"return",
"... | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CSRMatrixFactory.set_last_col_idx | Parameters
----------
param last_col_idx : int
number of columns | scattertext/CSRMatrixTools.py | def set_last_col_idx(self, last_col_idx):
'''
Parameters
----------
param last_col_idx : int
number of columns
'''
assert last_col_idx >= self._max_col
self._max_col = last_col_idx
return self | def set_last_col_idx(self, last_col_idx):
'''
Parameters
----------
param last_col_idx : int
number of columns
'''
assert last_col_idx >= self._max_col
self._max_col = last_col_idx
return self | [
"Parameters",
"----------",
"param",
"last_col_idx",
":",
"int",
"number",
"of",
"columns"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/CSRMatrixTools.py#L40-L49 | [
"def",
"set_last_col_idx",
"(",
"self",
",",
"last_col_idx",
")",
":",
"assert",
"last_col_idx",
">=",
"self",
".",
"_max_col",
"self",
".",
"_max_col",
"=",
"last_col_idx",
"return",
"self"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
train | CSRMatrixFactory.set_last_row_idx | Parameters
----------
param last_row_idx : int
number of rows | scattertext/CSRMatrixTools.py | def set_last_row_idx(self, last_row_idx):
'''
Parameters
----------
param last_row_idx : int
number of rows
'''
assert last_row_idx >= self._max_row
self._max_row = last_row_idx
return self | def set_last_row_idx(self, last_row_idx):
'''
Parameters
----------
param last_row_idx : int
number of rows
'''
assert last_row_idx >= self._max_row
self._max_row = last_row_idx
return self | [
"Parameters",
"----------",
"param",
"last_row_idx",
":",
"int",
"number",
"of",
"rows"
] | JasonKessler/scattertext | python | https://github.com/JasonKessler/scattertext/blob/cacf1f687d218ee8cae3fc05cc901db824bb1b81/scattertext/CSRMatrixTools.py#L51-L60 | [
"def",
"set_last_row_idx",
"(",
"self",
",",
"last_row_idx",
")",
":",
"assert",
"last_row_idx",
">=",
"self",
".",
"_max_row",
"self",
".",
"_max_row",
"=",
"last_row_idx",
"return",
"self"
] | cacf1f687d218ee8cae3fc05cc901db824bb1b81 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.