Ejemplo n.º 1
0
    def merge_and_show(validation_results):
        merged_result = Winner.calculate()
        unneded_columnns = [
            'AdaBoostClassifier', 'GaussianNB', 'KerasAlgorithm',
            'LightGBMAlgorithm', 'LinearSVC', 'MLPClassifier',
            'NearestCentroid', 'RandomForestClassifier', 'SGDClassifier',
            'SVC', 'XGBoostGbtreeAlgorithm', 'winner', 'failure', 'file',
            'lines', 'ok', 'size', 'test', 'train', 'validate'
        ]
        validation_results_mean = []
        for _i, row in validation_results.iterrows():
            values = [
                row['fbeta_run_0'], row['fbeta_run_1'], row['fbeta_run_2'],
                row['fbeta_run_3'], row['fbeta_run_4'], row['fbeta_run_5']
            ]
            minimal_fbeta = min(values)
            maximal_fbeta = max(values)
            mean_fbeta = np.mean(values)
            validation_results_mean.append({
                'drive_csv': row['drive_csv'],
                'minimal_fbeta': minimal_fbeta,
                'maximal_fbeta': maximal_fbeta,
                'mean_fbeta': mean_fbeta
            })

        kfold = merged_result.merge(pd.DataFrame(validation_results_mean),
                                    on='drive_csv')
        return kfold[kfold['winner'] == 'DecisionTreeClassifier'].drop(
            unneded_columnns, axis='columns')
Ejemplo n.º 2
0
    def __init__(self):
        self.merged_result = Winner.calculate()
        self.winners = []
        self.algorithms = [
            'AdaBoostClassifier', 'DecisionTreeClassifier', 'FakeAlgorithm',
            'GaussianNB', 'KerasAlgorithm', 'LightGBMAlgorithm', 'LinearSVC',
            'MLPClassifier', 'NearestCentroid', 'RandomForestClassifier',
            'SGDClassifier', 'SVC', 'XGBoostGbtreeAlgorithm'
        ]
        for algo in self.algorithms:
            total = 0
            for _i, row in self.merged_result.iterrows():
                if row['winner'] == algo:
                    total += 1
            self.winners.append(total)

        self.algorithm_short = [
            x.replace('Classifier', '').replace('Algorithm', '')
            for x in self.algorithms
        ]
Ejemplo n.º 3
0
 def run_all():
     validation_file = 'validation.csv'
     if os.path.exists(validation_file):
         return pd.read_csv(validation_file)
     else:
         merged_result = Winner.calculate()
         all_drives = list(
             merged_result[merged_result['winner'] ==
                           'DecisionTreeClassifier']['drive_csv'])
         results = []
         with tqdm(total=len(all_drives)) as pbar:
             for drive_csv in all_drives:
                 pbar.set_description(drive_csv)
                 drive_information = {'drive_csv': drive_csv}
                 drive_information.update(Validation.run(drive_csv))
                 results.append(drive_information)
                 pbar.update(1)
         df = pd.DataFrame(results)
         df.to_csv(validation_file, index=False)
         return df
Ejemplo n.º 4
0
                         numUnits=1,
                         name='Player 1',
                         equipmentTypes=equipmentTypes)
            gameOverTime = None
            active = game

    elif isinstance(active, Game):
        if active.gameOver:
            if gameOverTime is None:
                gameOverTime = time.time()
            if time.time() - gameOverTime > 5:
                if active.player not in active.units:
                    msg = 'You Lose'
                else:
                    msg = 'You Win'
                active = Winner(active.units[0], screen, msg=msg)
                lastGameEndTime = time.time()

    elif isinstance(active, Winner) and time.time() - lastGameEndTime > 5:
        active = Choose(screen)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        active.Event(event)

    active.Draw(clock)

    # OSD #######################
    fps = int(clock.get_fps())
Ejemplo n.º 5
0
while True:

    if isinstance(active, Choose):
        if active.startGameWith is not None:
            index, stats = active.startGameWith
            game = Game(screen)
            game.NewGame(index, stats, numUnits=1, name='Player 1')
            gameOverTime = None
            active = game

    elif isinstance(active, Game):
        if game.gameOver:
            if gameOverTime is None:
                gameOverTime = time.time()
            if time.time() - gameOverTime > 5:
                active = Winner(game.units[0], screen)
                lastGameEndTime = time.time()

    elif isinstance(active, Winner) and time.time() - lastGameEndTime > 5:
        # game = Game(screen)
        # game.NewGame(numUnits=2)
        # gameOverTime = None
        # active = game

        active = Choose(screen)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        active.Event(event)
 def test_winner_to_dict(self):
     w = Winner("Jan Nowak", "Gold medal")
     assert w.to_dict() == {"name": "Jan Nowak", "prize": "Gold medal"}
 def test_winner(self):
     w = Winner("Jan Nowak", "Gold medal")
     assert w.name == "Jan Nowak"
     assert w.prize == "Gold medal"
Ejemplo n.º 8
0
import csv
from winner import Winner

winners = []

with open("oscars.csv") as csvfile:
  reader = csv.reader(csvfile, skipinitialspace=True)

  next(reader)
  for row in reader:
    current_winner = Winner(*row)
    winners.append(current_winner)

# for winner in winners:
#   print(f"{winner.name} won the Oscar for {winner.movie} in {winner.year} at age {winner.age}.")

for winner in winners:
  if winner.year > 1979 and winner.year < 1990:
    print(winner.name)

old_winner = winners[0]
for winner in winners:
  if winner.age > old_winner.age:
    old_winner = winner
print(old_winner.name, old_winner.age)
  
meryl_streeps_wins = [(winner.movie, winner.year) for winner in winners if winner.name == "Meryl Streep"]
print(meryl_streeps_wins)
Ejemplo n.º 9
0
import csv
from winner import Winner

winners = []
with open("oscars.csv") as csvfile:
    reader = csv.reader(csvfile, skipinitialspace=True)

    next(reader)
    for row in reader:
        winners.append(Winner(*row))

with open("oscars.csv", "w", newline="") as csvfile:
    writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL)

    writer.writerow(["Index", "Year", "Age", "Name", "Movie"])

    for winner in winners:
        winner.age -= 1
        writer.writerow(winner.values_as_list())
Ejemplo n.º 10
0
import csv
from winner import Winner

with open("oscars.csv") as csvfile:
  reader = csv.reader(csvfile, skipinitialspace=True)
  index = sum(1 for row in reader)

with open("oscars.csv", "a") as csvfile:
  writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
  winner = Winner(index, 2020, 50, "Renée Zelweger", "Judy")
  writer.writerow(winner.values_as_list())