Skip to content

included removing sparse values from dictionnary #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ def sample(self):
self.sampler = weighted_sampler(list(self.dictionary.keys()),
list(self.dictionary.values()))
return self.sampler()

def remove_sparse(self, sparse_value):
""" Keep items with probablity greater than sparse value
and remove all others, eg. if sparse_value=0.98 items with probablity
0.02 would be removed"""
prob_to_remove = 1-sparse_value
tot = self.n_obs
for (k, v) in self.dictionary.items():
if v/tot < prob_to_remove:
del self.dictionary[k]
self.n_obs -= v


# ______________________________________________________________________________

Expand Down