Skip to content
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

Modify the forward selection process of greedy algorithm #12

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
13 changes: 8 additions & 5 deletions MLFeatureSelection/sequence_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _Greedy(self):
for sub, i in enumerate(col): #forward sequence selection add one each round
print(i)
print('{}/{}'.format(sub,len(col)))
selectcol = self._Startcol[:]
selectcol = self._TemplUsedFeatures[:]
selectcol.append(i)
self._validation(selectcol, str(1+sub), i, coetest = 0)
for sr, i in enumerate(self._TemplUsedFeatures[:-1]): # backward sequence selection, -2 becuase the last 2 is just selected
Expand All @@ -238,12 +238,15 @@ def _MyRandom(self,rl=[range(3,9),50]):
for t in rl[0]:
if t < len(col):
print('add {} features'.format(t))
have_selected = []
for i in range(rl[1]):
selectcol = random.sample(col, t)
recordadd = selectcol[:]
for add in self._bestfeature:
selectcol.append(add)
self._validation(selectcol, str(i), str(recordadd))
if sorted(selectcol) not in have_selected: #去重 提速
have_selected.append(sorted(selectcol))
recordadd = selectcol[:]
for add in self._bestfeature:
selectcol.append(add)
self._validation(selectcol, str(i), str(recordadd))
print('{0}{1}{2}'.format('-' * 20, 'complete random', '-' * 20))

@_reachlimit
Expand Down