python 检查过度拟合
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 检查过度拟合相关的知识,希望对你有一定的参考价值。
from sklearn.metrics import mean_absolute_error
from sklearn.tree import DecisionTreeRegressor
def get_mae(max_leaf_nodes, train_X, val_X, train_y, val_y):
model = DecisionTreeRegressor(max_leaf_nodes=max_leaf_nodes, random_state=0)
model.fit(train_X, train_y)
preds_val = model.predict(val_X)
mae = mean_absolute_error(val_y, preds_val)
return(mae)
# compare MAE with differing values of max_leaf_nodes
for max_leaf_nodes in [5, 50, 500, 5000]:
my_mae = get_mae(max_leaf_nodes, train_X, val_X, train_y, val_y)
print("Max leaf nodes: %d \t\t Mean Absolute Error: %d" %(max_leaf_nodes, my_mae))
以上是关于python 检查过度拟合的主要内容,如果未能解决你的问题,请参考以下文章
python 过度拟合以及如何控制它
机器学习中的过度拟合术语
在机器学习中过度拟合术语
过度拟合
过度拟合问题
避免过度拟合之正则化(转)