gpt4 book ai didi

python-3.x - 网格搜索后如何在 pivot_table 上绘制热图

转载 作者:行者123 更新时间:2023-12-04 00:32:38 24 4
gpt4 key购买 nike

我使用 ElasticNet 运行了网格搜索,但我无法绘制热图来查看 alpha 和 l1 比率之间的关系。我能够访问 pivot_table,但我不知道如何使用热图将其可视化。有人可以帮忙吗?

我的代码:

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

我想实现这样的目标: heat map on alpha and l1 ratio

最佳答案

     import seaborn as sns       
ax = sns.heatmap(pvt)

关于python-3.x - 网格搜索后如何在 pivot_table 上绘制热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48791709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com