def dataRefresh(self): """数据更新按钮事件,重新获取数据并处理,并更新页面显示数据""" getData.init() getData.get_data() dataProcess() # 取得最新更新日期 with open('cache.txt') as f: last = f.readlines()[0] df = pd.read_csv('data/total.csv') earlyData = df.iloc[len(df) - 2, :] # 前一天数据 lastData = df.iloc[len(df) - 1, :] # 最新数据 # 最新现存确诊 lastRemain = lastData[1] - lastData[2] - lastData[3] + lastData[4] - lastData[5] - lastData[6] # 前一天现存确诊 earlyRemain = earlyData[1] - earlyData[2] - earlyData[3] + earlyData[4] - earlyData[5] - earlyData[6] # 更新显示数据 self.lastRemainLabel.config(text=f'现存确诊:{lastRemain}') self.lastDateLabel.config(text=f'最新数据更新日期:{last}') self.lastConfirmLabel.config(text=f'确诊:{lastData[1] + lastData[4]}') self.lastCuredLabel.config(text=f'治愈:{lastData[2] + lastData[5]}') self.lastDeadLabel.config(text=f'死亡:{lastData[3] + lastData[6]}') if lastRemain - earlyRemain > 0: self.remainIncrease.config(text=f'现存确诊较昨日增加:{lastRemain - earlyRemain}') else: self.remainIncrease.config(text=f'现存确诊较昨日减少:{earlyRemain - lastRemain}') self.ConfirmIncrease.config(text=f'确诊较昨日增加:{lastData[1] + lastData[4] - earlyData[1] - earlyData[4]}') self.CuredIncrease.config(text=f'治愈较昨日增加:{lastData[2] + lastData[5] - earlyData[2] - earlyData[5]}') self.DeadIncrease.config(text=f'死亡较昨日增加:{lastData[3] + lastData[6] - earlyData[3] - earlyData[6]}')
def change_topic(self): """ Changes pool of words/sentences to a topic specified by user. """ topic = self.newTopic.get() self.modes = getData.get_data(topic) self.mode = self.modes[self.mode_index] self.curPrompt = -1 self.topicL['text'] = "Topic: " + topic self.next_prompt()
def main(): try: for wxid in get_value(): with open('wxb.txt', 'a+') as f: f.write( '-----------------------------------------------------------------------------------------------------------' + '\r\n') print( '---------------------------------------------------------------------------------------------------------------------' ) for article in getData.get_data(wxid): print(article) with open('wxb.txt', 'a+') as f: f.write(article + '\r\n') for word in getHotWord.get_hot_word(wxid): print(word) with open('wxb.txt', 'a+') as f: f.write(word + '\r\n') except: print('error') time.sleep(10)
def import_data(): # constants from getData import get_data UP_LEFT = (38.008050, -122.536985) UP_RIGHT = (38.008050, -122.186437) DOWN_RIGHT = (37.701933, -122.186437) DOWN_LEFT = (37.701933, -122.536985) START_DATE = '2018/10/01' END_DATE = '2019/09/02' START_HOUR = '0' END_HOUR = '24' # load data into dataframe data_df = get_data(UP_LEFT, UP_RIGHT, DOWN_RIGHT, DOWN_LEFT, START_DATE, END_DATE, START_HOUR, END_HOUR, 'Monthly') data_df['created'] = pd.to_datetime(data_df['created'], format='%Y%m%d%H%M') # remove outliers naively data_df = data_df[data_df['2_5um'] < np.percentile(data_df['2_5um'], 99.5)] return data_df
from model.model import get_MobileNet from model.model import preprocess_mobilenet import numpy as np config = tf.ConfigProto() config.gpu_options.allow_growth = True KTF.set_session(tf.Session(config=config)) # cnn_model = get_model() cnn_model = get_MobileNet() cnn_model.compile(optimizer='adam', loss='mean_squared_error') cnn_model.summary() np.random.seed(1) X, Y = get_data() print('x type: ', X.dtype) m = np.shape(X)[0] choice = np.random.permutation(m) X = X[choice] Y = Y[choice] X = preprocess_mobilenet(X) print('fitting...') cnn_model.fit(x=X, y=Y, batch_size=32, epochs=50, validation_split=0.2, shuffle=True) cnn_model.save('resnet50_finetuning.h5') print('done')
def main(srate=1, nb_epoch1=1, nb_epoch2=30, earlystop=20, maxneg=None, codingMode=0, transferlayer=1, inputweights=None, outputweights=None, forkinas=False): ########## Load Training Data ########## oneofkey_pos, oneofkey_neg, pssm_pos, pssm_neg, physical_pos, physical_neg = get_data( r'data/Ubisite_train3.txt', r'data/pssmpickle2/', label=True) ########## Load Testing Data ########## test_oneofkey_pos, test_oneofkey_neg, test_pssm_pos, test_pssm_neg, test_physical_pos, test_physical_neg = get_data( r'data/Ubisite_test3.txt', r'data/pssmpickle2/', label=False) ########## Oneofkey Testing ########## test_oneofkey_pos = pd.DataFrame(test_oneofkey_pos) test_oneofkey_neg = pd.DataFrame(test_oneofkey_neg) test_oneofkey_all = pd.concat([test_oneofkey_pos, test_oneofkey_neg]) test_oneofkeyX, test_oneofkeyY = convertRawToXY( test_oneofkey_all.as_matrix(), codingMode=0) ########## Physical Testing ########## test_physical_pos = pd.DataFrame(test_physical_pos) test_physical_neg = pd.DataFrame(test_physical_neg) test_physical_all = pd.concat([test_physical_pos, test_physical_neg]) test_physicalX, test_physicalY = convertRawToXY( test_physical_all.as_matrix(), codingMode=6) ########## Pssm Testing ########## test_pssm_all = test_pssm_pos + test_pssm_neg test_pssmX = convertRawToXY(test_pssm_all, codingMode=7) test_pssmY = test_oneofkeyY ########## OneofkeyX_t For Shape ########## test_oneofkeyX_t = test_oneofkeyX test_oneofkeyX_t.shape = (test_oneofkeyX.shape[0], test_oneofkeyX.shape[2], test_oneofkeyX.shape[3]) ########## PhysicalX_t For Shape ########## test_physicalX_t = test_physicalX test_physicalX_t.shape = (test_physicalX.shape[0], test_physicalX.shape[2], test_physicalX.shape[3]) ########### PssmX_t For Shape ########## testPssmX_t = test_pssmX testPssmX_t.shape = (test_pssmX.shape[0], test_pssmX.shape[2], test_pssmX.shape[3]) ########## Del Testall ########## del test_oneofkey_all, test_physical_all, test_pssm_all ########## Set Training Times ########## nclass = 20 for cw in range(1, 3, 1): c_weight = {0: cw * 0.1, 1: 1} ########## Set Training Strate ########## for t in range(0, nclass): ########### Shulffle All Training Data ########## pssm_pos, pssm_neg, oneofkey_pos, oneofkey_neg, physical_pos, physical_neg = shufflewrr( pssm_pos, pssm_neg, oneofkey_pos, oneofkey_neg, physical_pos, physical_neg) ########## A For Positive Data Number Set ########## a = int(len(oneofkey_pos) * 0.8) ########## Oneofkey Training ########## train_oneofkey_pos = oneofkey_pos[0:a] train_oneofkey_neg = oneofkey_neg[0:a] ########## Physical Training ########## train_physical_pos = physical_pos[0:a] train_physical_neg = physical_neg[0:a] ########## Pssm Training ########## train_pssm_pos = pssm_pos[0:a] train_pssm_neg = pssm_neg[0:a] print('total train', len(train_oneofkey_pos), len(train_oneofkey_neg), 'blblblblbl', len(train_physical_pos), len(train_physical_neg), len(train_pssm_pos), len(train_pssm_neg)) ########## Pos Concat Neg ########## train_oneofkey_all = pd.concat( [train_oneofkey_pos, train_oneofkey_neg]) train_physical_all = pd.concat( [train_physical_pos, train_physical_neg]) train_pssm_all = train_pssm_pos + train_pssm_neg ########## Shuffle Again ########## train_pssm_all, train_oneofkey_all, train_physical_all = shufflePosNeg( train_pssm_all, train_oneofkey_all, train_physical_all) ########## Dprocess For Codes ########## train_oneofkey_all = pd.DataFrame(train_oneofkey_all) train_oneofkeyX, train_oneofkeyY = convertRawToXY( train_oneofkey_all.as_matrix(), codingMode=0) train_physical_all = pd.DataFrame(train_physical_all) train_physicalX, train_physicalY = convertRawToXY( train_physical_all.as_matrix(), codingMode=6) train_pssmX = convertRawToXY(train_pssm_all, codingMode=7) train_pssmY = train_oneofkeyY ########## Del Trainall ########## del train_oneofkey_all, train_physical_all, train_pssm_all ########## MultiCNN ########## if (t == 0): models = MultiCNN( train_oneofkeyX, train_oneofkeyY, train_physicalX, train_pssmX, pre_train_seq_path='bestmodel/best - oneofk - model.h5', pre_train_physical_path= 'bestmodel/best - physical - model.h5', pre_train_pssm_path='bestmodel/best - pssm - model.h5', nb_epoch=nb_epoch2, earlystop=earlystop, transferlayer=transferlayer, weights=inputweights, class_weights=c_weight, forkinas=forkinas, compiletimes=t) #predict_classes = kutils.probas_to_classes(models.predict([test_oneofkeyX_t,test_physicalX_t,testPssmX_t] ,batch_size=2048)) #predict_classes = K.round(models.predict(test_physicalX)) #print('sklearn mcc',sklearn.metrics.matthews_corrcoef(test_physicalY[:,1], predict_classes)) #print('our calculation',calculate_performance(len(test_physicalY), test_physicalY[:,1], predict_classes)) #print('No.'+ str(t)+':', models.metrics_names,models.evaluate([test_oneofkeyX_t,test_physicalX_t,testPssmX_t], test_oneofkeyY, batch_size=2048)) else: models = MultiCNN( train_oneofkeyX, train_oneofkeyY, train_physicalX, train_pssmX, pre_train_seq_path='bestmodel/best - oneofk - model.h5', pre_train_physical_path= 'bestmodel/best - physical - model.h5', pre_train_pssm_path='bestmodel/best - pssm - model.h5', nb_epoch=nb_epoch2, earlystop=earlystop, transferlayer=transferlayer, weights=inputweights, class_weights=c_weight, forkinas=forkinas, compiletimes=t, compilemodels=models) #models.save('physicalfinal',overwrite=True) #models.save_weights('physicalweightfinal',overwrite=True) #predict_classes = kutils.probas_to_classes(models.predict([test_oneofkeyX_t,test_physicalX_t,testPssmX_t] ,batch_size=2048)) #predict_classes = K.round(models.predict(test_physicalX)) #print('sklearn mcc',sklearn.metrics.matthews_corrcoef(test_physicalY[:,1], predict_classes)) #print('our calculation', calculate_performance(len(test_physicalY), test_physicalY[:,1], predict_classes)) #print('No.'+ str(t)+':', models.metrics_names,models.evaluate([test_oneofkeyX_t,test_physicalX_t,testPssmX_t], test_oneofkeyY, batch_size=2048)) #predict testing set pred_proba = models.predict( [test_oneofkeyX, test_physicalX, test_pssmX], batch_size=2048) predict_classes = kutils.probas_to_classes(pred_proba) #SAVE the prediction metrics with open('result/evaluation.txt', mode='a') as resFile: resFile.write( str(cw) + ' ' + str(t) + ' ' + calculate_performance( len(test_physicalY), test_physicalY[:, 1], predict_classes, pred_proba[:, 1]) + '\r\n') resFile.close() true_label = test_oneofkeyY result = np.column_stack((true_label[:, 1], pred_proba[:, 1])) result = pd.DataFrame(result) result.to_csv(path_or_buf='result/result' + '-' + str(t) + '-' + str(cw) + '-' + '.txt', index=False, header=None, sep='\t', quoting=csv.QUOTE_NONNUMERIC) ########## Del Test Data ########## del test_pssm_pos, test_pssm_neg, test_oneofkey_pos, test_oneofkey_neg, test_physical_pos, test_physical_neg
data1_neg = data1_neg.as_matrix()[index] data1_neg_ss = pd.DataFrame(data1_neg) return data1_pos_ss, data1_neg_ss def get_matrix(windows_pos, windows_neg): windows_pos = pd.DataFrame(windows_pos) windows_neg = pd.DataFrame(windows_neg) windows_all = pd.concat([windows_pos, windows_neg]) windows_all = windows_all.as_matrix() del windows_pos, windows_neg return windows_all all_train_windows_pos, all_train_windows_neg = get_data( r'data/pretrain/1train.txt', r'data/pssmpickle2/', label=True) val_windows_pos, val_windows_neg = get_data(r'data/pretrain/1val.txt', r'data/pssmpickle2/', label=True) test_windows_pos, test_windows_neg = get_data(r'data/pretrain/1test.txt', r'data/pssmpickle2/', label=True) test_windows_all = get_matrix(test_windows_pos, test_windows_neg) test_oneofkeyX, testY = convertRawToXY(test_windows_all, codingMode=0) test_oneofkeyX.shape = (test_oneofkeyX.shape[0], test_oneofkeyX.shape[2], test_oneofkeyX.shape[3]) test_physicalXo, _ = convertRawToXY(test_windows_all, codingMode=9) test_physicalXo.shape = (test_physicalXo.shape[0], test_physicalXo.shape[2], test_physicalXo.shape[3])
Label(new_window, text="To toggle the mode, select the mode button. \n\n" "To play mode 1, type in your guess for the displayed word into the \n" "language you currently have selected and press submit. \n\n" "To play mode 2, type in your guess for the word that fills \n" "in the blank for the sentence into the selected language. \n\n" "To change to a different language to practice with, toggle the\n" "language button.\n\n" "To change the color, toggle the color button.\n\n" "To go to the next word/prompt, press the next button. \n\n To view the answer, press " "the show answer button.\n\n" "Your high score is tracked and saved each time you load the program.\n\n" "Many languages require the use of diacritical marks for certain letters\n" "Please follow the link below to learn how to write them on your OS.\n\n" "To change the topic, type in the title of a valid Wikipedia article \n" "in the bottom input and select change topic. If there are spaces in the\n" "head of the article, use underscores. i.e. Amazon_Prime\n\n" "Advanced Users: If you would like to get access to the data yourself\n" "open the getData.py file to manipulate the data to select what you want.").pack() link = Label(new_window, text=r"https://rom.uga.edu/inserting-diacritical-marks", fg="blue", cursor="hand") link.pack() link.bind("<Button-1>", callback) if __name__ == "__main__": data = getData.get_data('Oregon_State_University') root = Tk() root.title("Language Game") root.geometry("1100x600") game = Main(root, data) root.mainloop()
__author__ = 'Jasper Xu' import numpy as np import getData import cv2 try: # use read-made LBPH trainer in opencv3+ recognizer = cv2.face.LBPHFaceRecognizer_create() # get all users' face samples num = input('How many users do you want to recognize? \n') for i in range(int(num)): print('Now get samples for user No.{} ...'.format(i)) data_dir = getData.get_data() # get all images and labels faces, labels = getData.read_data(data_dir) print("[INFO] Start training! Please wait...") recognizer.train(faces, np.array(labels)) # write only work on desktop, not on raspi recognizer.write('D:/SECRET/face/model/trainer.yml') print("[INFO] Successful in training {} faces".format( len(np.unique(labels)))) except: print('Error!')
from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics import accuracy_score def knn_classifier(train_X, train_y, test_X, test_y): knn = KNeighborsClassifier(n_jobs=-1) knn.fit(train_X, train_y) result = knn.predict(test_X) return accuracy_score(result, test_y), metrics.recall_score(result, test_y, average='micro') # 返回降维后的特征 def dimensionReduction(X, dim=10): pca = PCA(n_components=dim) # X_pca:降维后的X X_pca = pca.fit_transform(X) return X_pca if __name__ == '__main__': data = get_data("./dataSet/UNSW_finally.npy") X, y = data[:, :-1], data[:, -1] X_pca = dimensionReduction(X, 10) X_train, X_test, y_train, y_test = train_test_split(X_pca, y, test_size=0.2) print(knn_classifier(X_train, y_train, X_test, y_test))
def present_prices(keyword): get_data(keyword) parse_amazon_data() parse_nike_data()
#1 - 0/ Rain Tommorow # file_location = 0 file_location = 1 # 0: "/Users/chienvn/PycharmProjects/Weather/Files/weather_include.csv", # 1: "/Users/chienvn/PycharmProjects/Weather/Files/weather_exclude.csv", # 2: "/Users/chienvn/PycharmProjects/Weather/Files/weather_consider.csv", # train_data = 0 train_data = 0 # 0: "Rain_Tomorrow_Yes", # 1: "Rain_today_Yes", # 2: "Rainfall", # 3: "Rainfall_Tomorrow", weather_data = getData.get_data(file_location) weather_data = getData.clear_data(weather_data) train, test, train_lb, test_lb = getData.slip_data( weather_data, getData.get_train_lb(train_data)) learning = Learning(train, test, train_lb) # new = pd.DataFrame(train) # new_train = new[[3, 4, 5, 7, 10, 11, 12, 15]].to_numpy() # t = pd.DataFrame(test) # new_test = t[[3, 4, 5, 7, 10, 11, 12, 15]].to_numpy() # learning = Learning(new_train, new_test, train_lb) logistic_prediction, knn_prediction, svm_prediction, rf_prediction = learning.train_model( ) report = np.array([ test_lb, logistic_prediction, knn_prediction, svm_prediction, rf_prediction
cursor = db.cursor() sql = 'select * from wk' cursor.execute(sql) wkid_wk = dicfetchall.dictfetchall(cursor) for i in wkid_wk: print(i) sql = 'select * from pro_tclass' cursor.execute(sql) pro_tclass = dicfetchall.dictfetchall(cursor) for index in pro_tclass: print(index) wkid = i['wkid'] wk = i['wk'] pro = index['pro'] tclass = index['tclass'] data = getData.get_data(wk, pro, tclass) timetable, d = createTimetable.cre_timetable(data) print(timetable) print(d) time = np.empty([6, 5], dtype=int) time = [ [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], ] # 对应课程的日期
# -*- coding: utf-8 -*- """ Created on Thu Nov 8 18:36:18 2018 @author: Caelum Kamps, Sean Kato, Dan, Denis, Ali """ import pandas as pd import getData #%% Preliminary initializations and imports data = pd.read_pickle('OurSortedData') # Pickled data voting_loc, _ = getData.get_data() # Voting locations voting_loc = voting_loc.sort_values('num') # Sorted voting locations # Column for each voting location model_output = pd.DataFrame(columns=['location ' + str(i) for i in range(54)]) # Model statistics model_statistics = pd.DataFrame( columns=['num of addys', 'mean', 'std', 'median', 'max']) placeholder_column = [None for i in range(54)] for column in model_statistics.columns: model_statistics[column] = placeholder_column # Placeholder to get voting locations columns = [[] for i in range(54)] #%% Actual function to map civic addresses to voting locations for i in range(len(data)): try:
# -*- coding: utf-8 -*- """ Created on Sat, Nov 17, 2018 @author: Caelum Kamps, Sean Kato, Dan, Denis, Ali """ import pandas as pd import getData #%% Preliminary initializations and imports data = pd.read_pickle('OurSortedData') # Pickled data data = data.drop(5219) #This was the row giving us trouble data = data.drop(13988) civic_addy = getData.get_data()[1]['addy'] del civic_addy[5219] del civic_addy[13988] #data.dropna(inplace=True) #data.reset_index(drop=True, inplace=True) voting_loc, _ = getData.get_data() # Voting locations voting_loc = voting_loc.sort_values('num') # Sorted voting locations ideal_num = (len(data)) / (len(voting_loc) ) #Ideal number of addresses per location ratio_tolerance = 1.1 #Arbitrary distance ratio tolerance (voting_loc_n+1/voting_loc_n) quot = pd.DataFrame(columns=['civic addy', 'quot1', 'quot2']) quot['civic addy'] = civic_addy too_many = [] quot1 = [0] * len(data) #array for first difference, initialize to zero quot2 = [0] * len(data) #array for second difference, initialize to zero # Column for each voting location
def gen_Data(path, dim=10, test_size=0.1): UNSW_data = get_data(path) X, y = UNSW_data[:, :-1], UNSW_data[:, -1] X_pca = dimensionReduction(X, dim) return train_test_split(X_pca, y, test_size=test_size)