-
Notifications
You must be signed in to change notification settings - Fork 2
/
smartcore_random_forest.py
39 lines (31 loc) · 1.2 KB
/
smartcore_random_forest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pandas as pd
from nrel.routee.powertrain.core.model_config import ModelConfig
from nrel.routee.powertrain.estimators.estimator_interface import Estimator
from nrel.routee.powertrain.estimators.smart_core import SmartCoreEstimator
from nrel.routee.powertrain.trainers.trainer import Trainer
class SmartcoreRandomForestTrainer(Trainer):
def inner_train(
self, features: pd.DataFrame, target: pd.DataFrame, config: ModelConfig
) -> Estimator:
"""
Uses a random forest to predict the energy rate values
"""
try:
from powertrain_rust import RustRandomForest
except ImportError:
raise ImportError(
"Please install powertrain_rust to use "
"the SmartCoreRandomForest estimator."
)
x = features.values.tolist()
y = target.values
if y.shape[1] != 1:
raise ValueError(
"SmartCore only supports a single energy rate. "
"Please use a different estimator."
)
y = y.ravel().tolist()
model = RustRandomForest()
model.train(x, y)
estimator = SmartCoreEstimator(model)
return estimator