随机森林过拟合

我使用scikit-learn和分层交叉验证来比较一些分类器。我计算了:准确率、召回率、AUC。

我使用了GridSearchCV进行参数优化,交叉验证设置为5折。

RandomForestClassifier(warm_start= True, min_samples_leaf= 1, n_estimators= 800, min_samples_split= 5,max_features= 'log2', max_depth= 400, class_weight=None)

这是GridSearchCV得到的最佳参数。

我的问题是,我认为我真的过拟合了。例如:

随机森林的标准差(+/-)

  • 精确度:0.99 (+/- 0.06)
  • 敏感性:0.94 (+/- 0.06)
  • 特异性:0.94 (+/- 0.06)
  • B_accuracy:0.94 (+/- 0.06)
  • AUC:0.94 (+/- 0.11)

逻辑回归的标准差(+/-)

  • 精确度:0.88(+/- 0.06)
  • 敏感性:0.79 (+/- 0.06)
  • 特异性:0.68 (+/- 0.06)
  • B_accuracy:0.73 (+/- 0.06)
  • AUC:0.73 (+/- 0.041)

其他分类器的表现看起来更像逻辑回归(因此它们看起来没有过拟合)。

我的交叉验证代码是:

for i,j in enumerate(data):    X.append(data[i][0])    y.append(float(data[i][1]))x=np.array(X)y=np.array(y)def SD(values):    mean=sum(values)/len(values)    a=[]    for i in range(len(values)):        a.append((values[i]-mean)**2)    erg=sum(a)/len(values)    SD=math.sqrt(erg)    return SD,mean    for name, clf in zip(titles,classifiers):    # 遍历所有分类器,计算10折     # 接下来的for循环应该多缩进一个制表符,由于格式问题无法在这里正确显示,抱歉    pre,sen,spe,ba,area=[],[],[],[],[]    for train_index, test_index in skf:        #print train_index, test_index        #获取所有train_index和test_index的索引        #将其转换为列表以避免某些错误        train=train_index.tolist()        test=test_index.tolist()        X_train=[]        X_test=[]        y_train=[]        y_test=[]        for i in train:            X_train.append(x[i])        for i in test:            X_test.append(x[i])         for i in train:            y_train.append(y[i])        for i in test:            y_test.append(y[i])         #clf=clf.fit(X_train,y_train)        #predicted=clf.predict_proba(X_test)        #... 其他代码,计算指标等...

回答:

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注