This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = build_model(_alpha=1.0, _l1_ratio=0.3) | |
kfcv = KFold(n_splits=5) | |
scores = cross_val_score(model, X_train, y_train, cv=kfcv, scoring=r2) | |
print("Loss: {0:.3f} (+/- {1:.3f})".format(scores.mean(), scores.std())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loss: -103.076 (+/- 205.979) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = build_model(_alpha=1.0, _l1_ratio=0.3) | |
tscv = TimeSeriesSplit(n_splits=5) | |
scores = cross_val_score(model, X_train, y_train, cv=tscv, scoring=r2) | |
print("Loss: {0:.3f} (+/- {1:.3f})".format(scores.mean(), scores.std())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loss: -9.799 (+/- 19.292) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlockingTimeSeriesSplit(): | |
def __init__(self, n_splits): | |
self.n_splits = n_splits | |
def get_n_splits(self, X, y, groups): | |
return self.n_splits | |
def split(self, X, y=None, groups=None): | |
n_samples = len(X) | |
k_fold_size = n_samples // self.n_splits |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = build_model(_alpha=1.0, _l1_ratio=0.3) | |
btscv = BlockingTimeSeriesSplit(n_splits=5) | |
scores = cross_val_score(model, X_train, y_train, cv=btscv, scoring=r2) | |
print("Loss: {0:.3f} (+/- {1:.3f})".format(scores.mean(), scores.std())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loss: -15.527 (+/- 27.488) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params = { | |
'estimator__alpha':(0.1, 0.3, 0.5, 0.7, 0.9), | |
'estimator__l1_ratio':(0.1, 0.3, 0.5, 0.7, 0.9) | |
} | |
for i in range(100): | |
model = build_model(_alpha=1.0, _l1_ratio=0.3) | |
finder = GridSearchCV( | |
estimator=model, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# optimal model | |
model = build_model(_alpha=0.1, _l1_ratio=0.1) | |
# train model | |
model.fit(X_train, y_train) | |
# test score | |
y_predicted = model.predict(X_test) | |
score = r2_score(y_test, y_predicted, multioutput='uniform_average') | |
print("Test Loss: {0:.3f}".format(score)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test Loss: 0.925 |