代码之家  ›  专栏  ›  技术社区  ›  Mahin Rahman

我的培训和测试图表保持不变,有人能帮我解释一下,或者解释一下我哪里出错了?

  •  0
  • Mahin Rahman  · 技术社区  · 2 年前

    我正在做一个简单的机器学习项目。在最初的模型中,我的模型是过拟合的,这是我通过谷歌搜索了解到的,并了解过拟合是什么以及如何检测它。然后,我用SMOTE来减少过度合身,并试图找出它是否仍然过度合身。我得到了一个我无法解释的图表,并尝试了几个链接来了解发生了什么,但失败了。 有谁能告诉我这张图是好是坏?(图片和代码如下所示) enter image description here

    def EF_final(x_train, y_train, x_test, y_test):
      train_scores, test_scores = [], []
      values = [i for i in range(1, 21)]
    # evaluate a decision tree for each depth
      for i in values:
        # configure the model
          model_ef = ExtraTreesClassifier(n_estimators = 80, random_state=42, min_samples_split = 2, min_samples_leaf= 1, max_features = 'sqrt', max_depth= 24, bootstrap=False)
        # fit model on the training dataset
          model_ef.fit(x_train, y_train)
        # evaluate on the train dataset
          train_yhat = model_ef.predict(x_train)
          train_acc = accuracy_score(y_train, train_yhat)
          train_scores.append(train_acc)
        # evaluate on the test dataset
          test_yhat = model_ef.predict(x_test)
          test_acc = accuracy_score(y_test, test_yhat)
          test_scores.append(test_acc)
        # summarize progress
          print('>%d, train: %.3f, test: %.3f' % (i, train_acc, test_acc))
    # plot of train and test scores vs tree depth
      plt.plot(values, train_scores, '-o', label='Train')
      plt.plot(values, test_scores, '-o', label='Test')
      plt.legend()
      plt.show()
    
    1 回复  |  直到 2 年前
        1
  •  0
  •   Rohan Thorat    2 年前

    在不查看数据的情况下,不能对模型预测的结果发表评论,但要回答标题问题。
    您似乎在每个循环中配置和创建相同的模型,而不使用变量 i 更改模型深度。甚至模型的random\u状态也是常数,因此您可以预期相同的结果。 考虑将模型配置行切换到

    model_ef = ExtraTreesClassifier(n_estimators = 80,min_samples_split = 2, min_samples_leaf= 1, max_features = 'sqrt', max_depth = i, bootstrap=False)
    

    这将改变图形结果,帮助您选择更好的模型, 但是,如果不知道传递的数据类型,则无法对准确性进行评论。