Why the output data result not the same for Random Forest The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsRandom forest model gives same result for all test data, Next step?NLTK: Tuning LinearSVC classifier accuracy? - Looking for better approaches/advicesSKNN regression problemWhy `max_features=n_features` does not make the Random Forest independent of number of trees?Consistently inconsistent cross-validation results that are wildly different from original model accuracyWrong train/test split strategyTensorflow regression predicting 1 for all inputsIs a 100% model accuracy on out-of-sample data overfitting?ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Random Forest, Duplicating Data increases Accuracy. Why?

How did passengers keep warm on sail ships?

What information about me do stores get via my credit card?

Why did Peik Lin say, "I'm not an animal"?

Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time?

Why are PDP-7-style microprogrammed instructions out of vogue?

One-dimensional Japanese puzzle

What aspect of planet Earth must be changed to prevent the industrial revolution?

Do working physicists consider Newtonian mechanics to be "falsified"?

"... to apply for a visa" or "... and applied for a visa"?

Simulating Exploding Dice

Working through the single responsibility principle (SRP) in Python when calls are expensive

Mortgage adviser recommends a longer term than necessary combined with overpayments

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What force causes entropy to increase?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

My body leaves; my core can stay

Why not take a picture of a closer black hole?

Can the DM override racial traits?

Why doesn't a hydraulic lever violate conservation of energy?

Python - Fishing Simulator

How many cones with angle theta can I pack into the unit sphere?

Single author papers against my advisor's will?

Student Loan from years ago pops up and is taking my salary

Is there a writing software that you can sort scenes like slides in PowerPoint?



Why the output data result not the same for Random Forest



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsRandom forest model gives same result for all test data, Next step?NLTK: Tuning LinearSVC classifier accuracy? - Looking for better approaches/advicesSKNN regression problemWhy `max_features=n_features` does not make the Random Forest independent of number of trees?Consistently inconsistent cross-validation results that are wildly different from original model accuracyWrong train/test split strategyTensorflow regression predicting 1 for all inputsIs a 100% model accuracy on out-of-sample data overfitting?ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Random Forest, Duplicating Data increases Accuracy. Why?










0












$begingroup$


May I know how to modify my Python programming thus it will be get the same result as refer to the attached image file?



import numpy as np
from sklearn import datasets as data
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
def load_data(feature_len = 4):
return data.load_iris()['data'][:, :feature_len], data.load_iris()['target']
def tr_te_split(data, target, test_ratio = .2):
return train_test_split(data, target, test_size=test_ratio, random_state=0)
def build_model():
return DecisionTreeClassifier(criterion='entropy'), RandomForestClassifier(criterion='entropy', n_estimators=10, random_state=1)
def train(model, x, y):
model.fit(x, y)
print(" Training Accuracy = ".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
return model
def evaluate(model, x, y):
print(" Testing Accuracy = n".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
return accuracy_score(model.predict(x), y)
def main():
data, target = load_data()

tree_score = []
rf_score = []
for feature_len in range(1, data.shape[-1] + 1):
print("Use features.".format(feature_len))
data, target = load_data(feature_len)
x_tr, x_te, y_tr, y_te = tr_te_split(data, target, .4)

tree_model, rf_model = build_model()

tree_model_trained = train(tree_model, x_tr, y_tr)
tree_score.append(evaluate(tree_model_trained, x_te, y_te))

rf_model_trained = train(rf_model, x_tr, y_tr)
rf_score.append(evaluate(rf_model_trained, x_te, y_te))

# draw
tree_plt = plt
tree_plt.plot(tree_score)
tree_plt.xlabel('Number of features')
tree_plt.xticks([0,1,2,3],('1','2','3','4'))
tree_plt.ylabel('Accuracy')
tree_plt.title('Decision Tree')
tree_plt.show()

rf_plt = plt
rf_plt.plot(rf_score)
rf_plt.xlabel('Number of features')
rf_plt.xticks([0,1,2,3],('1','2','3','4'))
rf_plt.ylabel('Accuracy')
plt.yticks(np.arange(0.90, 0.95, 0.01))
rf_plt.title('Ransom Forest')
rf_plt.show()

if __name__ == '__main__':
main()


Please see the image file -



enter image description here



Please help me on this case









share







New contributor




vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    0












    $begingroup$


    May I know how to modify my Python programming thus it will be get the same result as refer to the attached image file?



    import numpy as np
    from sklearn import datasets as data
    from sklearn.model_selection import train_test_split
    from sklearn.tree import DecisionTreeClassifier
    from sklearn.ensemble import RandomForestClassifier
    from sklearn.metrics import accuracy_score
    import matplotlib.pyplot as plt
    def load_data(feature_len = 4):
    return data.load_iris()['data'][:, :feature_len], data.load_iris()['target']
    def tr_te_split(data, target, test_ratio = .2):
    return train_test_split(data, target, test_size=test_ratio, random_state=0)
    def build_model():
    return DecisionTreeClassifier(criterion='entropy'), RandomForestClassifier(criterion='entropy', n_estimators=10, random_state=1)
    def train(model, x, y):
    model.fit(x, y)
    print(" Training Accuracy = ".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
    return model
    def evaluate(model, x, y):
    print(" Testing Accuracy = n".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
    return accuracy_score(model.predict(x), y)
    def main():
    data, target = load_data()

    tree_score = []
    rf_score = []
    for feature_len in range(1, data.shape[-1] + 1):
    print("Use features.".format(feature_len))
    data, target = load_data(feature_len)
    x_tr, x_te, y_tr, y_te = tr_te_split(data, target, .4)

    tree_model, rf_model = build_model()

    tree_model_trained = train(tree_model, x_tr, y_tr)
    tree_score.append(evaluate(tree_model_trained, x_te, y_te))

    rf_model_trained = train(rf_model, x_tr, y_tr)
    rf_score.append(evaluate(rf_model_trained, x_te, y_te))

    # draw
    tree_plt = plt
    tree_plt.plot(tree_score)
    tree_plt.xlabel('Number of features')
    tree_plt.xticks([0,1,2,3],('1','2','3','4'))
    tree_plt.ylabel('Accuracy')
    tree_plt.title('Decision Tree')
    tree_plt.show()

    rf_plt = plt
    rf_plt.plot(rf_score)
    rf_plt.xlabel('Number of features')
    rf_plt.xticks([0,1,2,3],('1','2','3','4'))
    rf_plt.ylabel('Accuracy')
    plt.yticks(np.arange(0.90, 0.95, 0.01))
    rf_plt.title('Ransom Forest')
    rf_plt.show()

    if __name__ == '__main__':
    main()


    Please see the image file -



    enter image description here



    Please help me on this case









    share







    New contributor




    vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      0












      0








      0





      $begingroup$


      May I know how to modify my Python programming thus it will be get the same result as refer to the attached image file?



      import numpy as np
      from sklearn import datasets as data
      from sklearn.model_selection import train_test_split
      from sklearn.tree import DecisionTreeClassifier
      from sklearn.ensemble import RandomForestClassifier
      from sklearn.metrics import accuracy_score
      import matplotlib.pyplot as plt
      def load_data(feature_len = 4):
      return data.load_iris()['data'][:, :feature_len], data.load_iris()['target']
      def tr_te_split(data, target, test_ratio = .2):
      return train_test_split(data, target, test_size=test_ratio, random_state=0)
      def build_model():
      return DecisionTreeClassifier(criterion='entropy'), RandomForestClassifier(criterion='entropy', n_estimators=10, random_state=1)
      def train(model, x, y):
      model.fit(x, y)
      print(" Training Accuracy = ".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
      return model
      def evaluate(model, x, y):
      print(" Testing Accuracy = n".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
      return accuracy_score(model.predict(x), y)
      def main():
      data, target = load_data()

      tree_score = []
      rf_score = []
      for feature_len in range(1, data.shape[-1] + 1):
      print("Use features.".format(feature_len))
      data, target = load_data(feature_len)
      x_tr, x_te, y_tr, y_te = tr_te_split(data, target, .4)

      tree_model, rf_model = build_model()

      tree_model_trained = train(tree_model, x_tr, y_tr)
      tree_score.append(evaluate(tree_model_trained, x_te, y_te))

      rf_model_trained = train(rf_model, x_tr, y_tr)
      rf_score.append(evaluate(rf_model_trained, x_te, y_te))

      # draw
      tree_plt = plt
      tree_plt.plot(tree_score)
      tree_plt.xlabel('Number of features')
      tree_plt.xticks([0,1,2,3],('1','2','3','4'))
      tree_plt.ylabel('Accuracy')
      tree_plt.title('Decision Tree')
      tree_plt.show()

      rf_plt = plt
      rf_plt.plot(rf_score)
      rf_plt.xlabel('Number of features')
      rf_plt.xticks([0,1,2,3],('1','2','3','4'))
      rf_plt.ylabel('Accuracy')
      plt.yticks(np.arange(0.90, 0.95, 0.01))
      rf_plt.title('Ransom Forest')
      rf_plt.show()

      if __name__ == '__main__':
      main()


      Please see the image file -



      enter image description here



      Please help me on this case









      share







      New contributor




      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      May I know how to modify my Python programming thus it will be get the same result as refer to the attached image file?



      import numpy as np
      from sklearn import datasets as data
      from sklearn.model_selection import train_test_split
      from sklearn.tree import DecisionTreeClassifier
      from sklearn.ensemble import RandomForestClassifier
      from sklearn.metrics import accuracy_score
      import matplotlib.pyplot as plt
      def load_data(feature_len = 4):
      return data.load_iris()['data'][:, :feature_len], data.load_iris()['target']
      def tr_te_split(data, target, test_ratio = .2):
      return train_test_split(data, target, test_size=test_ratio, random_state=0)
      def build_model():
      return DecisionTreeClassifier(criterion='entropy'), RandomForestClassifier(criterion='entropy', n_estimators=10, random_state=1)
      def train(model, x, y):
      model.fit(x, y)
      print(" Training Accuracy = ".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
      return model
      def evaluate(model, x, y):
      print(" Testing Accuracy = n".format(str(model.__class__).split('.')[-1].split("'")[0], model.score(x, y)))
      return accuracy_score(model.predict(x), y)
      def main():
      data, target = load_data()

      tree_score = []
      rf_score = []
      for feature_len in range(1, data.shape[-1] + 1):
      print("Use features.".format(feature_len))
      data, target = load_data(feature_len)
      x_tr, x_te, y_tr, y_te = tr_te_split(data, target, .4)

      tree_model, rf_model = build_model()

      tree_model_trained = train(tree_model, x_tr, y_tr)
      tree_score.append(evaluate(tree_model_trained, x_te, y_te))

      rf_model_trained = train(rf_model, x_tr, y_tr)
      rf_score.append(evaluate(rf_model_trained, x_te, y_te))

      # draw
      tree_plt = plt
      tree_plt.plot(tree_score)
      tree_plt.xlabel('Number of features')
      tree_plt.xticks([0,1,2,3],('1','2','3','4'))
      tree_plt.ylabel('Accuracy')
      tree_plt.title('Decision Tree')
      tree_plt.show()

      rf_plt = plt
      rf_plt.plot(rf_score)
      rf_plt.xlabel('Number of features')
      rf_plt.xticks([0,1,2,3],('1','2','3','4'))
      rf_plt.ylabel('Accuracy')
      plt.yticks(np.arange(0.90, 0.95, 0.01))
      rf_plt.title('Ransom Forest')
      rf_plt.show()

      if __name__ == '__main__':
      main()


      Please see the image file -



      enter image description here



      Please help me on this case







      machine-learning python random-forest





      share







      New contributor




      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 mins ago









      vokoyovokoyo

      11




      11




      New contributor




      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      vokoyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          vokoyo is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49224%2fwhy-the-output-data-result-not-the-same-for-random-forest%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          vokoyo is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          vokoyo is a new contributor. Be nice, and check out our Code of Conduct.












          vokoyo is a new contributor. Be nice, and check out our Code of Conduct.











          vokoyo is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49224%2fwhy-the-output-data-result-not-the-same-for-random-forest%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Францішак Багушэвіч Змест Сям'я | Біяграфія | Творчасць | Мова Багушэвіча | Ацэнкі дзейнасці | Цікавыя факты | Спадчына | Выбраная бібліяграфія | Ушанаванне памяці | У філатэліі | Зноскі | Літаратура | Спасылкі | НавігацыяЛяхоўскі У. Рупіўся дзеля Бога і людзей: Жыццёвы шлях Лявона Вітан-Дубейкаўскага // Вольскі і Памідораў з песняй пра немца Адвакат, паэт, народны заступнік Ашмянскі веснікВ Минске появится площадь Богушевича и улица Сырокомли, Белорусская деловая газета, 19 июля 2001 г.Айцец беларускай нацыянальнай ідэі паўстаў у бронзе Сяргей Аляксандравіч Адашкевіч (1918, Мінск). 80-я гады. Бюст «Францішак Багушэвіч».Яўген Мікалаевіч Ціхановіч. «Партрэт Францішка Багушэвіча»Мікола Мікалаевіч Купава. «Партрэт зачынальніка новай беларускай літаратуры Францішка Багушэвіча»Уладзімір Іванавіч Мелехаў. На помніку «Змагарам за родную мову» Барэльеф «Францішак Багушэвіч»Памяць пра Багушэвіча на Віленшчыне Страчаная сталіца. Беларускія шыльды на вуліцах Вільні«Krynica». Ideologia i przywódcy białoruskiego katolicyzmuФранцішак БагушэвічТворы на knihi.comТворы Францішка Багушэвіча на bellib.byСодаль Уладзімір. Францішак Багушэвіч на Лідчыне;Луцкевіч Антон. Жыцьцё і творчасьць Фр. Багушэвіча ў успамінах ягоных сучасьнікаў // Запісы Беларускага Навуковага таварыства. Вільня, 1938. Сшытак 1. С. 16-34.Большая российская1188761710000 0000 5537 633Xn9209310021619551927869394п

          Partai Komunis Tiongkok Daftar isi Kepemimpinan | Pranala luar | Referensi | Menu navigasidiperiksa1 perubahan tertundacpc.people.com.cnSitus resmiSurat kabar resmi"Why the Communist Party is alive, well and flourishing in China"0307-1235"Full text of Constitution of Communist Party of China"smengembangkannyas

          ValueError: Expected n_neighbors <= n_samples, but n_samples = 1, n_neighbors = 6 (SMOTE) The 2019 Stack Overflow Developer Survey Results Are InCan SMOTE be applied over sequence of words (sentences)?ValueError when doing validation with random forestsSMOTE and multi class oversamplingLogic behind SMOTE-NC?ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)SmoteBoost: Should SMOTE be ran individually for each iteration/tree in the boosting?solving multi-class imbalance classification using smote and OSSUsing SMOTE for Synthetic Data generation to improve performance on unbalanced dataproblem of entry format for a simple model in KerasSVM SMOTE fit_resample() function runs forever with no result