I ran a Grid-searching with ElasticNet but I had trouble plotting a heat map to see the relation between alpha and l1 ratio. I was able to get to the pivot_table, but I don't know how to visualize it w/ a heat map. Can anyone please help?
My codes:
from sklearn.datasets import fetch_california_housing
cal=fetch_california_housing()
X = cal.data
y = cal.target
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
import matplotlib.pyplot as plt
%matplotlib inline
param_grid = {'alpha': np.logspace(-3, -1, 10), 'l1_ratio':[0.01, .1, .9,
.98, 1]}
print(param_grid)
grid = GridSearchCV(ElasticNet(normalize=True), param_grid, cv=10)
grid.fit(X_train, y_train)
print("Best cross-validation score: {:.2f}".format(grid.best_score_))
print("Best parameters: ", grid.best_params_)
import pandas as pd
pvt = pd.pivot_table(pd.DataFrame(grid.cv_results_),
values='mean_test_score', index='param_alpha', columns='param_l1_ratio')
pvt
I want to achieve something like this:

import seaborn as sns
ax = sns.heatmap(pvt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With