<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Learning module Predicting Seagrass Habitats With Machine Learning: I'm getting the following Python error trying to train the random forest classifier in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324678#M25249</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this what you are following?&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://learn.arcgis.com/en/projects/predict-seagrass-habitats-with-machine-learning/" title="https://learn.arcgis.com/en/projects/predict-seagrass-habitats-with-machine-learning/"&gt;Predict Seagrass Habitats with Machine Learning | Learn ArcGIS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;some bugs in the instructions... don't know if they have been corrected in the instructions&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/223883-i-am-working-on-the-predict-seagrass-habitats-with-machine-learning-module-by-esri-i-am-working-in-arcpro-when-i-get-to-the-python-code-its-gives-me-this-error"&gt;https://community.esri.com/thread/223883-i-am-working-on-the-predict-seagrass-habitats-with-machine-learning-module-by-esri-i-am-working-in-arcpro-when-i-get-to-the-python-code-its-gives-me-this-error&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Apr 2020 08:58:41 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2020-04-12T08:58:41Z</dc:date>
    <item>
      <title>Learning module Predicting Seagrass Habitats With Machine Learning: I'm getting the following Python error trying to train the random forest classifier</title>
      <link>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324677#M25248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's where I am in the module:&lt;/P&gt;&lt;H2 style="color: #4c4c4c; background-color: #ffffff; font-size: 1.9994rem; margin: -145px 0px 0.75rem; padding-top: 175px;" id="toc-hId-1675182497"&gt;Train your random forest classifier&lt;/H2&gt;&lt;P style="color: #4c4c4c; background-color: #ffffff; margin-bottom: 1.5rem;"&gt;Now that you have split your data, you'll train your random forest classifier using the training data you have created.&lt;/P&gt;&lt;DIV class=""&gt;&lt;OL class="" style="font-size: 0.9375rem; margin-bottom: 1.55rem; padding: 0px 0px 1em;"&gt;&lt;LI style="margin-top: 0.75em; padding: 0.3em 0.25em 0.25em 2.5em;"&gt;&lt;SPAN style="margin-bottom: 1.55rem;"&gt;Create the variable&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;rfco&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to show the results of running the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;RandomForestClassifier&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;command to create 500 trees. Then use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;.fit&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;argument to apply the forest results to the training data.&lt;/SPAN&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE class=""&gt;rfco = RandomForestClassifier(n_estimators = &lt;SPAN class="" style="color: #1c00cf;"&gt;500&lt;/SPAN&gt;, oob_score = &lt;SPAN class="" style="color: #aa0d91;"&gt;True&lt;/SPAN&gt;) rfco.fit(train_set[predictVars], indicator)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI style="margin-top: 0.75em; padding: 0.3em 0.25em 0.25em 2.5em;"&gt;&lt;SPAN style="margin-bottom: 1.55rem;"&gt;Run the classification again using the test dataset. Create the attribute&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;seagrassPred&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to store this data with a 1 for occurrence and a 0 for no occurrence.&lt;/SPAN&gt;&lt;DIV class=""&gt;&lt;P style="font-size: 1em; margin-bottom: 1.5rem;"&gt;The test data is 90 percent of the United States coastal data that was not used to train the model, and will show the accuracy of your prediction.&lt;/P&gt;&lt;DIV class=""&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE class=""&gt;seagrassPred = rfco.predict(test_set[predictVars])&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI style="margin-top: 0.75em; padding: 0.3em 0.25em 0.25em 2.5em;"&gt;&lt;SPAN style="margin-bottom: 1.55rem;"&gt;Use the results of the classification to check the efficiency of the model by calculating prediction accuracy and estimation error.&lt;/SPAN&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE class=""&gt;test_seagrass = test_set[classVar].as_matrix() test_seagrass = test_seagrass.flatten() error = NUM.sum(NUM.abs(test_seagrass - seagrassPred))/len(seagrassPred) * &lt;SPAN class="" style="color: #1c00cf;"&gt;100
-------
&lt;/SPAN&gt;&lt;/CODE&gt;&lt;STRONG&gt;Here's the last few entries in my Python log:&lt;/STRONG&gt;

test_set&lt;SPAN class=""&gt; = &lt;/SPAN&gt;data.drop&lt;SPAN class=""&gt;(&lt;/SPAN&gt;train_set.index&lt;SPAN class=""&gt;)&lt;/SPAN&gt;
indicator&lt;SPAN class=""&gt;, &lt;/SPAN&gt;_&lt;SPAN class=""&gt; = &lt;/SPAN&gt;PD.factorize&lt;SPAN class=""&gt;(&lt;/SPAN&gt;train_set&lt;SPAN class=""&gt;[&lt;/SPAN&gt;classVar&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;]])&lt;/SPAN&gt;
&lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;'Training Data Size = '&lt;SPAN class=""&gt; &lt;/SPAN&gt;&lt;SPAN class=""&gt;+&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;&lt;SPAN class=""&gt;str&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;train_set.shape&lt;/SPAN&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;]))&lt;/SPAN&gt;&lt;SPAN class=""&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;'Test Data Size = '&lt;SPAN class=""&gt; &lt;/SPAN&gt;&lt;SPAN class=""&gt;+&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;&lt;SPAN class=""&gt;str&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;test_set.shape&lt;/SPAN&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;]))&lt;/SPAN&gt;
Training Data Size = 1000
Test Data Size = 9000
rfco&lt;SPAN class=""&gt; = &lt;/SPAN&gt;RandomForestClassifier&lt;SPAN class=""&gt;(&lt;/SPAN&gt;n_estimators&lt;SPAN class=""&gt; = &lt;/SPAN&gt;&lt;SPAN class=""&gt;500&lt;/SPAN&gt;&lt;SPAN class=""&gt;, &lt;/SPAN&gt;oob_score&lt;SPAN class=""&gt; = &lt;/SPAN&gt;&lt;SPAN class=""&gt;True&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;rfco.fit&lt;SPAN class=""&gt;(&lt;/SPAN&gt;train_set&lt;SPAN class=""&gt;[&lt;/SPAN&gt;predictVars&lt;SPAN class=""&gt;], &lt;/SPAN&gt;indicator&lt;SPAN class=""&gt;)&lt;/SPAN&gt;
seagrassPred&lt;SPAN class=""&gt; = &lt;/SPAN&gt;rfco.predict&lt;SPAN class=""&gt;(&lt;/SPAN&gt;test_set&lt;SPAN class=""&gt;[&lt;/SPAN&gt;predictVars&lt;SPAN class=""&gt;])&lt;/SPAN&gt;
test_seagrass&lt;SPAN class=""&gt; = &lt;/SPAN&gt;test_set&lt;SPAN class=""&gt;[&lt;/SPAN&gt;classVar&lt;SPAN class=""&gt;].&lt;/SPAN&gt;as_matrix&lt;SPAN class=""&gt;()&lt;/SPAN&gt;test_seagrass&lt;SPAN class=""&gt; = &lt;/SPAN&gt;test_seagrass.flatten&lt;SPAN class=""&gt;()&lt;/SPAN&gt;error&lt;SPAN class=""&gt; = &lt;/SPAN&gt;NUM&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;sum&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;NUM&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;abs&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;test_seagrass&lt;SPAN class=""&gt; &lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;seagrassPred&lt;SPAN class=""&gt;))/&lt;/SPAN&gt;&lt;SPAN class=""&gt;len&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;seagrassPred&lt;SPAN class=""&gt;) &lt;/SPAN&gt;&lt;SPAN class=""&gt;*&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;&lt;SPAN class=""&gt;100&lt;/SPAN&gt;
&lt;STRONG&gt;Traceback (most recent call last):&lt;/STRONG&gt;
&lt;STRONG&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/STRONG&gt;
&lt;STRONG&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;File "C:\Users\brian\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\pandas\core\generic.py", line 5274, in __getattr__&lt;/STRONG&gt;
&lt;STRONG&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;return object.__getattribute__(self, name)&lt;/STRONG&gt;
&lt;STRONG&gt;AttributeError: 'DataFrame' object has no attribute 'as_matrix'&lt;/STRONG&gt;

I'm concerned it might be a file path problem that I can't do anything about. 
I'm working in ArcPro from a Windows server 2012R2, so the actual file path to Documents may differ from what it would be on a stand-alone machine.
I'm new to Python but can sort of follow along.

&lt;A href="https://community.esri.com/migrated-users/214531" target="_blank"&gt;Kathy Cappelli&lt;/A&gt;‌ I saw on a related thread that you're the person responsible for this cool module.&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:23:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324677#M25248</guid>
      <dc:creator>BrianOrt</dc:creator>
      <dc:date>2021-12-11T15:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Learning module Predicting Seagrass Habitats With Machine Learning: I'm getting the following Python error trying to train the random forest classifier</title>
      <link>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324678#M25249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this what you are following?&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://learn.arcgis.com/en/projects/predict-seagrass-habitats-with-machine-learning/" title="https://learn.arcgis.com/en/projects/predict-seagrass-habitats-with-machine-learning/"&gt;Predict Seagrass Habitats with Machine Learning | Learn ArcGIS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;some bugs in the instructions... don't know if they have been corrected in the instructions&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/223883-i-am-working-on-the-predict-seagrass-habitats-with-machine-learning-module-by-esri-i-am-working-in-arcpro-when-i-get-to-the-python-code-its-gives-me-this-error"&gt;https://community.esri.com/thread/223883-i-am-working-on-the-predict-seagrass-habitats-with-machine-learning-module-by-esri-i-am-working-in-arcpro-when-i-get-to-the-python-code-its-gives-me-this-error&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Apr 2020 08:58:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324678#M25249</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2020-04-12T08:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Learning module Predicting Seagrass Habitats With Machine Learning: I'm getting the following Python error trying to train the random forest classifier</title>
      <link>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324679#M25250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan,&lt;/P&gt;&lt;P&gt;Yes, the Predict Seagrass Habitats... module is what I'm working through, and I did find the thread you refer to prior to posting my question, but thanks anyway for sending it. In that case, the OP's question stemmed from naming an attribute 02 (with zero) instead of O2 (with letter O).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having a different issue, with calling up the method,&amp;nbsp;.as_matrix. I have since found this information, saying that as_matrix is no longer included in Python versions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/52382440/python-method-as-matrix-will-be-removed-in-a-future-version-use-values-inste" title="https://stackoverflow.com/questions/52382440/python-method-as-matrix-will-be-removed-in-a-future-version-use-values-inste"&gt;scikit learn - Python: Method .as_matrix will be removed in a future version. Use .values instead - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think perhaps I need to learn how to replace as_matrix with &lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;.values() or&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;.to_numpy() before I can proceed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;The deprecation of .values happened after the publication of the Seagrass module I'm trying to learn from.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Apr 2020 20:46:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324679#M25250</guid>
      <dc:creator>BrianOrt</dc:creator>
      <dc:date>2020-04-12T20:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Learning module Predicting Seagrass Habitats With Machine Learning: I'm getting the following Python error trying to train the random forest classifier</title>
      <link>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324680#M25251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Follow-up: I replaced the .as_matrix method with .to_numpy and got... a result. The accuracy estimates were exactly opposite of what they were supposed to have been using .as_matrix, so I&amp;nbsp;would take a wild guess to say that .to_numpy might have reversed two columns in the matrix. By the end of the learning module, my map looked "right." Still, I'd like to know what happened between .as_matrix and .to_numpy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2020 21:06:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-module-predicting-seagrass-habitats-with/m-p/324680#M25251</guid>
      <dc:creator>BrianOrt</dc:creator>
      <dc:date>2020-04-23T21:06:17Z</dc:date>
    </item>
  </channel>
</rss>

