Skip to content

Commit

Permalink
restore index.year
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahAlidoost committed Nov 24, 2023
1 parent 298b8b8 commit dc39649
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions motrainer/jackknife.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,31 @@ def train(self,
normalize_method)

# Data split
input_years = self.gpi_input.index.get_level_values('year')
output_years = self.gpi_output.index.get_level_values('year')
input_years = self.gpi_input.index.year
output_years = self.gpi_output.index.year
logger.debug(
'Spliting Trainning and validation data. Split year: {}.'.format(
self.val_split_year))
jackknife_input = self.gpi_input[input_years < self.val_split_year]
jackknife_output = self.gpi_output[output_years < self.val_split_year]
vali_input = self.gpi_input[input_years >= self.val_split_year]
vali_output = self.gpi_output[output_years >= self.val_split_year]
year_list = jackknife_input.index.get_level_values('year').unique()
year_list = jackknife_input.index.year.unique()

# Jackknife in time
loo = LeaveOneOut()
best_perf_sum = None
for train_index, test_index in loo.split(year_list):
this_year = test_index[0] + year_list[0]

input_years = jackknife_input.index.get_level_values('year')
output_years = jackknife_output.index.get_level_values('year')
input_years = jackknife_input.index.year
output_years = jackknife_output.index.year

logger.info('Jackknife on year: {}.'.format(str(this_year)))
train_input = jackknife_input[
input_years != this_year]
train_output = jackknife_output[
output_years != this_year]
test_input = jackknife_input[input_years ==
this_year]
test_output = jackknife_output[output_years ==
this_year]
train_input = jackknife_input[input_years != this_year]
train_output = jackknife_output[output_years != this_year]
test_input = jackknife_input[input_years == this_year]
test_output = jackknife_output[output_years == this_year]

# Execute training
training = NNTrain(train_input, train_output)
Expand Down

0 comments on commit dc39649

Please sign in to comment.