def analysistest(): f = [#'IsPenalty', 'Distance', 'Angle', 'Surface', #'LastEvent', #'NbOfPassesInPhase', #'NbOfEventsInPhase', 'NbOfPassesInTimewindow', 'NbOfEventsInTimewindow', 'SpeedInTimewindow', 'AngleInTimewindow', #'Random' ] wo_penalties = True only_fcb_shots = False skmodel = lambda: RandomForestClassifier(n_estimators=1000) skmodel_alt = lambda: ExtraTreesClassifier(n_estimators=1000) model = SKLearnModel(skmodel,True) model_alt = SKLearnModel(LogisticRegression,True) X = np.array(get_features(f,wo_penalties,only_fcb_shots)) y = np.array(get_results(wo_penalties,only_fcb_shots)) prob = model.crosspredict(X, y) #prob_alt = model_alt.crosspredict(X, y) plot_model_analysis(X,y,prob,f,indexes=[0]) print_scores(get_scores(y, prob)) #print_scores(get_scores(y, prob)) #print_scores(get_scores(y, prob_alt)) #compare_models(X, y, prob, prob_alt, f, True,[0]) plt.show()
def plot_features_bins2(): X = np.array(get_features(fs,wo_penalties,only_fcb_shots)) y = np.array(get_results(wo_penalties,only_fcb_shots)) n = len(fs) names = {'Distance' : 'Afstand tot doel (m)' , 'Angle' : 'Zichthoek (radialen)', 'Surface' : 'Oppervlakte driehoek (m^2)', 'NbOfPassesInTimewindow' : 'Aantal passes in de laatste 10 seconden', 'SpeedInTimewindow' : 'Afgelegde afstand in de laatste 10 seconden (m)', 'AngleInTimewindow' : 'Hoek in de laatste 10 seconden (radialen)', 'NbOfPassesInPhase' : "passes in fase", 'NbOfEventsInPhase' : "events in fase", 'NbOfEventsInTimewindow' : 'events in de laatste 10 seconden'} for i in range(0,n): fig,ax = plt.subplots(1,1) fig.set_size_inches(7*0.7,5*0.7,forward=True) name = fs[i] subax = ax if n > 1 else ax x = X[...,i] if n > 1 else X if name== 'Distance' or name == 'SpeedInTimewindow': x = [float(a)/100 for a in x] if name== 'Surface': x = [float(a)/10000 for a in x] if name in ['NbOfPassesInPhase','NbOfEventsInPhase','NbOfPassesInTimewindow','NbOfEventsInTimewindow']: plot_passes(x,y,names[name],subax) else: plot_feature_bins(x,y,names[name], subax) plt.tight_layout() #plt.savefig("C:/Users/Temp/Dropbox/thesis/reports/thesis/img/model2/" + name + ".pdf") plt.show()
def build_shotclasstable(cross=True): from db.prozoneDB import DB c = DB.c conn = DB.conn idsX = np.array(get_features(["shotid"] + f,wo_penalties,only_fcb_shots)) X = idsX[:,1:] y = np.array(get_results(wo_penalties,only_fcb_shots)) if cross: prob = model.crosspredict(X,y) else: model.fit(X,y) prob = model.predict(X) #print prob c.execute("drop table if exists Shotvalue") c.execute("create table Shotvalue (shotid int,esv real)") for t in zip(idsX[:,0],prob): print(t) c.execute("insert into Shotvalue values (?,?)",t) conn.commit() conn.close() print("Shotclass table succcesfully built") print_scores(get_scores(y,prob)) plot_roc_curve(y,prob)
def comparemodelsroc(models,labels): preds = [] X = np.array(get_features(f, wo_penalties, only_fcb_shots)) y = np.array(get_results(wo_penalties, only_fcb_shots)) for model in models: preds.append(model.crosspredict(X,y)) plot_roc_curves(y,preds,labels)
def plot_features_bins(): X = np.array(get_features(fs,wo_penalties,only_fcb_shots)) y = np.array(get_results(wo_penalties,only_fcb_shots)) n = len(fs) fig,ax = plt.subplots(1,n) fig.set_size_inches(n*5,5,forward=True) for i in range(0,n): name = fs[i] subax = ax[i] if n > 1 else ax x = X[...,i] if n > 1 else X plot_feature_bins(x,y,name, subax) plt.tight_layout()
def comparemodels(cross=True): X = np.array(get_features(f,wo_penalties,only_fcb_shots)) X_alt = np.array(get_features(f_alt,wo_penalties,only_fcb_shots)) y = np.array(get_results(wo_penalties,only_fcb_shots)) if cross: prob = model.crosspredict(X,y) prob_alt = model_alt.crosspredict(X_alt,y) else: model.fit(X,y) model_alt.fit(X,y) prob = model.predict(X) prob_alt = model.predict(X) #compare_models(X, y, prob, prob_alt, f, f_plot=True) plot_roc_curve(y, prob, prob_alt)
def analyze_model(cross=True): X = np.array(get_features(f,wo_penalties,only_fcb_shots)) y = np.array(get_results(wo_penalties,only_fcb_shots)) if cross: prob = model.crosspredict(X,y) else: model.fit(X,y) prob = model.predict(X) # print prob # plt.hist(prob) # plt.show() #plot_model_analysis(X,y,prob,f) print_scores(get_scores(y,prob)) plot_roc_curve(y,prob)