Skip to content

Commit

Permalink
make ALGORITHMS const
Browse files Browse the repository at this point in the history
  • Loading branch information
myslak71 authored and myslak71 committed Feb 24, 2019
1 parent 97fe04e commit 95cdedb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions common/utils/count_percentage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

MEDIA_ROOT = settings.MEDIA_ROOT

ALGORITHMS = {
'KNeighborsClassifier': KNeighborsClassifier,
'LogisticRegression': LogisticRegression,
'LinearSVC': LinearSVC,
'GaussianNB': GaussianNB,
'DecisionTreeClassifier': DecisionTreeClassifier,
'RandomForestClassifier': RandomForestClassifier,
'GradientBoostingClassifier': GradientBoostingClassifier,
'MLPClassifier': MLPClassifier,
}


def count_percentage(duel, algorithm):
dataset = pandas.read_csv(f'{MEDIA_ROOT}/{duel.dataset.dataset}')
Expand All @@ -27,20 +38,10 @@ def count_percentage(duel, algorithm):
y = dataset.values[:, 3]
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2,
random_state=0)
algorithms = {
'KNeighborsClassifier': KNeighborsClassifier,
'LogisticRegression': LogisticRegression,
'LinearSVC': LinearSVC,
'GaussianNB': GaussianNB,
'DecisionTreeClassifier': DecisionTreeClassifier,
'RandomForestClassifier': RandomForestClassifier,
'GradientBoostingClassifier': GradientBoostingClassifier,
'MLPClassifier': MLPClassifier,
}

if algorithm.get_name_display() not in ('KNeighborsClassifier', 'GaussianNB'):
algorithm.parameters.update({'random_state': 0})
model = algorithms[algorithm.get_name_display()](**algorithm.parameters)
model = ALGORITHMS[algorithm.get_name_display()](**algorithm.parameters)
model.fit(x_train, y_train)

return float(Decimal(100 * model.score(x_test, y_test)).quantize(Decimal('.001')))

0 comments on commit 95cdedb

Please sign in to comment.