def predictresult(models, traindatestart, traindateend, testdateend): data = readdata() don, need_train_data = usercluseter(data) train_data, don_not_have_before = xandy( need_train_data, traindatestart, traindateend, testdateend) pymid_and_ys = testp(models, train_data) ty = onetimeintveraldata(data, traindateend, testdateend) a = pd.merge(pymid_and_ys[0], pymid_and_ys[1], left_index=True, right_index=True, how="outer") b = pd.merge( a, pymid_and_ys[2], left_index=True, right_index=True, how="outer") py = b.fillna(0) pyy = ty.copy(deep=True) print id(pyy), id(ty) # print py.ix[:, :] # sys, exit() mindex = pyy["mid"].isin(py.index) pyy.loc[ mindex, ["forward_count", "comment_count", "like_count"]] = py.values[3:6] # print pyy.loc[~mindex, ["forward_count", "comment_count", "like_count"]] pyy.loc[~mindex, ["forward_count", "comment_count", "like_count"]] = 0 f = pyy.values[:, 3:6] t = ty.values[:, 3:6] print f, t print scores(f, t)
def prepare(scaleName, scalePath, state): print "preparing for " + scaleName log = logging.getLogger('prepare') #scale_df=pd.read_csv(scalePath); #obj=eval(scaleName)(scale_df,'raw'); #def scores(scaleName,scalePath): clean_dup(scaleName, scalePath, state) scores(scaleName, scalePath, state) transform(scaleName, scalePath, state) print "\n"
def op(self, data): """ 统一的op接口 """ op = data['op'] if op == 'add': return self.game.add_player(data.get('name', 'unknown'), data.get('side', 'unknown')) elif op in ('moves'): if isinstance(data['moves'] , basestring): data['moves'] = json.loads(data['moves']) return dict(status=self.game.set_player_op(data['id'], data)) elif op == 'map': return self.game.get_map() elif op == 'setmap': return dict(status=self.game.user_set_map(data['data'])) elif op == 'info': return self.game.get_info() elif op == 'history': return self.history() elif op == 'scores': return scores.scores() else: return dict(status='op error: %s' % op)
def create_fit_predict(model, filename, train_data, valid_data, test_data, **kwargs): model, history, checkpointer = model(filename) model_history = model.fit(train_data[0], train_data[1], validation_data=(valid_data[0], valid_data[1]), callbacks=[checkpointer], **kwargs) model.load_weights(filename) from plot_losses import plot_losses plot_losses(model_history) preds = model.predict(test_data[0]) from scores import scores return scores(preds, test_data[1])
def _evaluateAccuracy(self, split='val', fname="val", task="ner"): all_outputs, all_gt, all_vals = self._decodeAll(split=split) all_outputs = map(self.data_handler.getTagsFromIndices, all_outputs) #print "all_vals = ", all_vals #print "all_outputs = ", all_outputs out_data = [] if task == "ner": for output, vals in zip(all_outputs, all_vals): for val, out in zip(vals, output): out_data.append(' '.join(val) + ' ' + out) out_data.append('') else: # pos for output, vals in zip(all_outputs, all_vals): for val, out in zip(vals, output): out_data.append(' '.join(val[0:2]) + ' ' + out) out_data.append('') fname = 'tmp/' + fname + ".predictions" self._outputToFile(fname, out_data) print "SCORES = ", scores.scores(fname)
def initiate_game(): '''set up game unto screen''' pygame.init( ) #initialises background settings that pygame need to work with aa_settings = Settings() screen = pygame.display.set_mode( (aa_settings.screen_width, aa_settings.screen_height)) pygame.display.set_caption('ALIEN ASSAULT') #draws the ship to screen: ship = Ship(aa_settings, screen) #make an instance first bullets = Group() #makes a group of bullets(instance) aliens = Group() #make a group of aliens(instance) #instance of alien: create_aliens(aa_settings, screen, ship, aliens) #create an instance of game_stats: stats = aa_stats(aa_settings) #create an instance of scoreboard show_scores = scores(aa_settings, screen, stats) #displays play button play_button = Button(aa_settings, screen, "Play") #this starts the main loop for the game while True: #observe keyboard and mouse events: Check_events(aa_settings, screen, stats, show_scores, play_button, ship, aliens, bullets) if stats.game_active: ship.update() update_bullets(aa_settings, screen, stats, show_scores, ship, aliens, bullets) update_aliens(aa_settings, screen, stats, show_scores, ship, aliens, bullets) Update_screen(aa_settings, screen, stats, show_scores, ship, aliens, bullets, play_button)
dictionary = { } ## Create a dictionary with songID, song object key-value pairs x = 0 size = len(songlist) for song in songlist: ## Loops over number of songs in songlist song.score1 = s1 = ( float(song.acousticness) + float(song.liveness) ) / 2 ## Score 1 is the average of acousticness and liveness song.score2 = s2 = ( float(song.valence) + float(song.danceability) ) / 2 ## Score 2 is the average of valence and danceability song.score3 = s3 = ( float(song.energy) + (float(song.tempo) / 244) ) / 2 ## Score 3 is the average of energy and adjusted tempo scorelist.append(scores( s1, s2, s3)) ## Create a list of score objects containing all scores score1List.append(song) ## Append score 1 to score 1 list score2List.append(song) ## Append score 2 to score 2 list score3List.append(song) ## Append score 3 to score 3 list dictionary[song.id] = [song] ## Pairs song id to song object in dictionary x = x + 1 ## Increments x score1List.sort(key=getSongScore1) ## Sorts dictionary score2List.sort(key=getSongScore2) ## Sorts dictionary score3List.sort(key=getSongScore3) ## Sorts dictionary menu = True ## Bool to keep menu running until exit while menu: ## While not exiting, loop menu print( ## Menu Print "\n---------- MENU ----------\n" "1.Generate Min-Heap Playlist\n"
def compileResults(seasonResults, weekNum, resultsFileName): resultArray = [] teamList = teams().getTeams(seasonResults) teamScores = scores().teamScores(seasonResults, teamList) totalScores = scores().totalScores(teamScores) averageScores = scores().avgScores(teamScores) medianScores = scores().medianScores(teamScores) rangeScores = scores().rangeScores(teamScores) stdDevScores = scores().stdDevScores(teamScores) winsAgainstEveryone = waeWins().totalWinsAgainstEveryone(teamScores) normalizedWinsAgainstEveryone = waeWins().normalizedWinsAgainstEveryone( winsAgainstEveryone) waeStrengthOfSchedule = waeWins().strengthOfSchedule( seasonResults, teamScores) actualWins = trueWins().getTrueWins(seasonResults, teamList) winDiff = waeWins().winDiff(normalizedWinsAgainstEveryone, actualWins) nStrengthOfSchedule = waeWins().normalizedLosses(waeStrengthOfSchedule) lossDiff = waeWins().lossDiff(nStrengthOfSchedule, actualWins, weekNum) expectedWins = waeWins().expectedWins(winsAgainstEveryone, waeStrengthOfSchedule, weekNum) scheduleLuck = waeWins().scheduleLuck(actualWins, expectedWins) teamList.insert(0, 'Team Name') resultArray.append(teamList) resultArray.append(totalScores) resultArray.append(averageScores) resultArray.append(medianScores) resultArray.append(rangeScores) resultArray.append(stdDevScores) resultArray.append(actualWins) resultArray.append(winsAgainstEveryone) resultArray.append(normalizedWinsAgainstEveryone) resultArray.append(winDiff) resultArray.append(waeStrengthOfSchedule) resultArray.append(nStrengthOfSchedule) resultArray.append(lossDiff) resultArray.append(expectedWins) resultArray.append(scheduleLuck) resultArray = dataSort(resultArray) resultArray[0].append('') resultArray[0].append('Averages') resultArray = addAverage(resultArray) excelEdit().writer(resultArray, resultsFileName)
if (_b == 0): print(_fpcap + '无可解析的数据包') else: print(_fpcap + "解析成功") if (_b == 0): print('路径中无文件或文件中无可分析的数据包') else: c = fx(IP, file_path, mydb, _a, _b) # 分析数据包 print(file_path + "分析成功") insert_dos(file_path, mydb, _a, _b) # 可视化所用表 print(file_path + "流量时序表生成成功") insert_port(IP, file_path, mydb, _a, _b) # 可视化所用表 print(file_path + "端口遍历表生成成功") insert_login(IP, file_path, mydb, _a, _b) # 可视化所用表 print(file_path + "远程登录表生成成功") d, e = insert_time(IP, file_path, mydb, _a, _b) # 可视化所用表 if e != 0: print(file_path + "非法时间操作记录表生成成功") else: print(file_path + "无非法时间操作") scores(mydb, file_path, c, d, e) # 可视化所用表 print(file_path + "更新分析表评分项成功") svm(file_path, mydb, c) # 这个会导入实现训练好的模型,预测结果,这里导入样本集只是帮助分析结果做归一化
try: path2 = Path(argv[2]) path3 = Path(argv[3]) except: path2 = Path('queries/q1.wav') path3 = Path('queries/q2.wav') freq2, samples2 = wavfile.read(path2) freq3, samples3 = wavfile.read(path3) # normalizacia samples1 = samples1 / 2**15 samples2 = samples2 / 2**15 samples3 = samples3 / 2**15 pdf = PdfPages(path1.stem + '_nas.pdf') fig = signal(samples1, freq1, 'gigantic', 'parking') pdf.savefig(fig) fig.clf() fig = features(samples1, freq1, pdf=True) pdf.savefig(fig) fig.clf() fig = scores(samples1, freq1, samples2, freq2, samples3, freq3, 'gigantic', 'parking') pdf.savefig(fig) fig.clf() pdf.close()
q1freq, q1samples = wavfile.read(q1path) q2freq, q2samples = wavfile.read(q2path) # normalizacia q1samples = q1samples / 2**15 q2samples = q2samples / 2**15 for i in range(1, len(argv)): path = Path(argv[i]) freq, samples = wavfile.read(path) samples = samples / 2**15 s1, s2 = scores(samples, freq, q1samples, q1freq, q2samples, q2freq, 'gigantic', 'parking', return_score=True) s1data = [] s2data = [] wavfile.write('hits/gigantic_hit' + str(i) + '.wav', 16000, np.array(s1data)) wavfile.write('hits/parking_hit' + str(i) + '.wav', 16000, np.array(s2data)) """ continuous1 = False