1. 导入需要的库
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import cross_val_score
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
2. 导入数据集,探索数据
data = load_breast_cancer()
data
data.data.shape
data.target
#可以看到,乳腺癌数据集有569条记录,30个特征,单看维度虽然不算太高,但是样本量非常少。过拟合的情况可能存在
3. 进行一次简单的建模,看看模型本身在数据集上的效果
rfc = RandomForestClassifier(n_estimators=100,random_state=90)
score_pre = cross_val_score(rfc,data.data,data.target,cv=10

这篇博客通过导入相关库和数据集,探讨了如何使用sklearn的随机森林算法预测乳腺癌。首先进行了初步建模,然后着重调整了n_estimators参数,观察其对模型准确率的影响。接着,为避免耗时的多参数调整,采用网格搜索逐个调整参数,如max_depth,以理解参数对模型性能的具体作用,并应用复杂度-泛化误差方法进行调参。
订阅专栏 解锁全文

557

被折叠的 条评论
为什么被折叠?



