Skip to content

Commit

Permalink
scoring function improved
Browse files Browse the repository at this point in the history
  • Loading branch information
grro committed Jan 3, 2023
1 parent 817f55d commit b11c9b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pvpower/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CoreVectorizer(Vectorizer):

def vectorize(self, sample: WeatherForecast) -> List[float]:
vectorized = [self._scale(sample.time_utc.month, 12),
self._scale(12-abs(12-sample.time_utc.hour), 12),
self._scale(sample.time_utc.hour, 24),
self._scale(sample.irradiance, 1000)]
return vectorized

Expand Down Expand Up @@ -207,6 +207,7 @@ def num_samples_last_train(self) -> int:
def retrain(self, train_data: TrainData):
start = time.time()
samples = train_data.samples
samples = [sample for sample in samples if sample.irradiance > 0] # do not train the estimator for zero irradiance
feature_vector_list = [self.__vectorizer.vectorize(sample) for sample in samples]
label_list = [sample.power_watt for sample in samples]
if len(set(label_list)) > 1:
Expand Down
9 changes: 4 additions & 5 deletions pvpower/trainingcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def __init__(self, estimator: Estimator, train_data: TrainData):
self.predictions = [estimator.predict(validation_record) for validation_record in self.validation_samples]
self.estimator.retrain(train_data) # retrain with all data

def __score(self, real, predicted):
distance = abs(real - predicted)
return distance
def __score(self, real, predicted)-> int:
return round(abs(real - predicted) / 10)*10

@property
def score(self) -> float:
Expand All @@ -28,8 +27,8 @@ def score(self) -> float:
if real == 0 and predicted == 0: # do not waste the total score by true zero predictions
continue
scores.append(self.__score(real, predicted))
scores = self.__without_outliners(scores, 0.1)
return mean(scores)
scores_without_outliners = self.__without_outliners(scores, 0.1)
return mean(scores_without_outliners)

@staticmethod
def __without_outliners(scores: List[int], percent: float) -> List[int]:
Expand Down

0 comments on commit b11c9b9

Please sign in to comment.