Skip to content

Commit

Permalink
Fixed a issue of training in Windows system
Browse files Browse the repository at this point in the history
wenbostar committed Oct 19, 2021
1 parent 522b9f8 commit bc76070
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions autort/Metrics.py
Original file line number Diff line number Diff line change
@@ -45,24 +45,34 @@ def calc_delta_t95(obs, pred):
def calc_elta_tr95(obs, pred):
return calc_delta_t95(obs, pred) / (max(obs) - min(obs))

def evaluate_model_combn(i, x, y, para=None, reverse=True, metric="median_absolute_error"):
ind = list()
ind.extend(i)
y_p = np.apply_along_axis(combine_rts, 1, x[ind], reverse=reverse, scale_para=para, method="mean",remove_outlier=True)
y_t = y
if reverse == True:
y_t = scaling_y_rev(y_t, para)
#y_p = scaling_y_rev(y_p, para)
y2 = pd.DataFrame({"y": y_t, "y_pred": y_p.reshape(y_p.shape[0])})
#if metric == "median_absolute_error":

cor = pearsonr(y2['y'], y2['y_pred'])[0]
mean_absolute_error = sklearn.metrics.mean_absolute_error(y2['y'], y2['y_pred'])
# median_absolute_error = float(np.median(np.abs(y2['y'] - y2['y_pred'])))
median_absolute_error = sklearn.metrics.median_absolute_error(y2['y'], y2['y_pred'])
r2 = sklearn.metrics.r2_score(y2['y'], y2['y_pred'])
d_t95 = calc_delta_t95(y2['y'], y2['y_pred'])
return [i,cor,r2,mean_absolute_error,median_absolute_error,d_t95]
class ModelE:

def __init__(self, x, y, para, reverse=True, metric="median_absolute_error"):
self.x = x
self.y = y
self.para = para
self.reverse = reverse
self.metric = metric

def evaluate_model_combn(self, i):
ind = list()
ind.extend(i)
y_p = np.apply_along_axis(combine_rts, 1, self.x[ind], reverse=self.reverse, scale_para=self.para, method="mean",remove_outlier=True)
y_t = self.y
if self.reverse == True:
y_t = scaling_y_rev(y_t, self.para)
#y_p = scaling_y_rev(y_p, para)
y2 = pd.DataFrame({"y": y_t, "y_pred": y_p.reshape(y_p.shape[0])})
#if metric == "median_absolute_error":

cor = pearsonr(y2['y'], y2['y_pred'])[0]
mean_absolute_error = sklearn.metrics.mean_absolute_error(y2['y'], y2['y_pred'])
# median_absolute_error = float(np.median(np.abs(y2['y'] - y2['y_pred'])))
median_absolute_error = sklearn.metrics.median_absolute_error(y2['y'], y2['y_pred'])
r2 = sklearn.metrics.r2_score(y2['y'], y2['y_pred'])
d_t95 = calc_delta_t95(y2['y'], y2['y_pred'])
return [i,cor,r2,mean_absolute_error,median_absolute_error,d_t95]

def model_selection(x, y, para=None, metric="median_absolute_error"):
## x is a numpy array. shape: sample vs model
@@ -73,8 +83,9 @@ def model_selection(x, y, para=None, metric="median_absolute_error"):
models_list.extend(list(combinations(range(n_models),i+1)))

p = multiprocessing.Pool(processes=multiprocessing.cpu_count())
evaluate_model_combn_x = functools.partial(evaluate_model_combn, x=x,y=y,para=para,reverse=True,metric=metric)
data = p.map(evaluate_model_combn_x, models_list)
model_e = ModelE(x=x, y=y, para=para, reverse=True, metric=metric)
# evaluate_model_combn_x = functools.partial(evaluate_model_combn, x=x,y=y,para=para,reverse=True,metric=metric)
data = p.map(model_e.evaluate_model_combn, models_list)
p.close()
## select best combination
best_i = None

0 comments on commit bc76070

Please sign in to comment.