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

          ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)2019 Community Moderator ElectionError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)Error 'Expected 2D array, got 1D array instead:'ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Steps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

          Ружовы пелікан Змест Знешні выгляд | Пашырэнне | Асаблівасці біялогіі | Літаратура | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 змена/ 22697590 Сістэматыкана ВіківідахВыявына Вікісховішчы174693363011049382

          Illegal assignment from SObject to ContactFetching String, Id from Map - Illegal Assignment Id to Field / ObjectError: Compile Error: Illegal assignment from String to BooleanError: List has no rows for assignment to SObjectError on Test Class - System.QueryException: List has no rows for assignment to SObjectRemote action problemDML requires SObject or SObject list type error“Illegal assignment from List to List”Test Class Fail: Batch Class: System.QueryException: List has no rows for assignment to SObjectMapping to a user'List has no rows for assignment to SObject' Mystery