sklearn predict: IndexingError: ('Too many indexers', 'occurred at index ')












0












$begingroup$


use_cols = ['FIRST_NAME', 'LAST_NAME', 'PERSON_STATUS', 'DIVISION_NAME',
'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER', 'IDENTIFY_DATE',
'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA',
'LAST_LOGIN_DATE', 'ASSET_NAME', 'AUDIT_ID',
'REVIEWER_ACTION', 'USER ID', 'LABELED_ROLE', 'REVIEW_ACTION']
prediction_col = ['REVIEW_ACTION']

categorical_features = ['DIVISION_NAME', 'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER',
'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA', 'LAST_LOGIN_DATE',
'USER ID', 'LABELED_ROLE']

categorical_transformer = Pipeline(steps=[
('si', SimpleImputer(strategy='constant', fill_value='missing')),
('ohe', OneHotEncoder(handle_unknown='ignore'))],remainder='passthrough')

preprocessor = ColumnTransformer(
transformers=[
('cat', categorical_transformer, categorical_features)])

rf = Pipeline(steps=[('preprocessor', preprocessor),
('rfc', RandomForestClassifier(n_estimators=100))
])


So I let several fields
Then I try to run the prediction



df['rf_prediction'] = df[categorical_features].apply(rf.predict)


and get the error:



IndexingError: ('Too many indexers', 'occurred at index DIVISION_NAME') 


I suspect that this has something to do with the columns being 'passthrough' but I'm not sure how to resolve it. I don't want to process some of these columns but want them in the results when I write the file so that I can validate the results.









share







New contributor




Harvey 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$


    use_cols = ['FIRST_NAME', 'LAST_NAME', 'PERSON_STATUS', 'DIVISION_NAME',
    'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER', 'IDENTIFY_DATE',
    'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA',
    'LAST_LOGIN_DATE', 'ASSET_NAME', 'AUDIT_ID',
    'REVIEWER_ACTION', 'USER ID', 'LABELED_ROLE', 'REVIEW_ACTION']
    prediction_col = ['REVIEW_ACTION']

    categorical_features = ['DIVISION_NAME', 'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER',
    'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA', 'LAST_LOGIN_DATE',
    'USER ID', 'LABELED_ROLE']

    categorical_transformer = Pipeline(steps=[
    ('si', SimpleImputer(strategy='constant', fill_value='missing')),
    ('ohe', OneHotEncoder(handle_unknown='ignore'))],remainder='passthrough')

    preprocessor = ColumnTransformer(
    transformers=[
    ('cat', categorical_transformer, categorical_features)])

    rf = Pipeline(steps=[('preprocessor', preprocessor),
    ('rfc', RandomForestClassifier(n_estimators=100))
    ])


    So I let several fields
    Then I try to run the prediction



    df['rf_prediction'] = df[categorical_features].apply(rf.predict)


    and get the error:



    IndexingError: ('Too many indexers', 'occurred at index DIVISION_NAME') 


    I suspect that this has something to do with the columns being 'passthrough' but I'm not sure how to resolve it. I don't want to process some of these columns but want them in the results when I write the file so that I can validate the results.









    share







    New contributor




    Harvey 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$


      use_cols = ['FIRST_NAME', 'LAST_NAME', 'PERSON_STATUS', 'DIVISION_NAME',
      'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER', 'IDENTIFY_DATE',
      'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA',
      'LAST_LOGIN_DATE', 'ASSET_NAME', 'AUDIT_ID',
      'REVIEWER_ACTION', 'USER ID', 'LABELED_ROLE', 'REVIEW_ACTION']
      prediction_col = ['REVIEW_ACTION']

      categorical_features = ['DIVISION_NAME', 'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER',
      'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA', 'LAST_LOGIN_DATE',
      'USER ID', 'LABELED_ROLE']

      categorical_transformer = Pipeline(steps=[
      ('si', SimpleImputer(strategy='constant', fill_value='missing')),
      ('ohe', OneHotEncoder(handle_unknown='ignore'))],remainder='passthrough')

      preprocessor = ColumnTransformer(
      transformers=[
      ('cat', categorical_transformer, categorical_features)])

      rf = Pipeline(steps=[('preprocessor', preprocessor),
      ('rfc', RandomForestClassifier(n_estimators=100))
      ])


      So I let several fields
      Then I try to run the prediction



      df['rf_prediction'] = df[categorical_features].apply(rf.predict)


      and get the error:



      IndexingError: ('Too many indexers', 'occurred at index DIVISION_NAME') 


      I suspect that this has something to do with the columns being 'passthrough' but I'm not sure how to resolve it. I don't want to process some of these columns but want them in the results when I write the file so that I can validate the results.









      share







      New contributor




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







      $endgroup$




      use_cols = ['FIRST_NAME', 'LAST_NAME', 'PERSON_STATUS', 'DIVISION_NAME',
      'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER', 'IDENTIFY_DATE',
      'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA',
      'LAST_LOGIN_DATE', 'ASSET_NAME', 'AUDIT_ID',
      'REVIEWER_ACTION', 'USER ID', 'LABELED_ROLE', 'REVIEW_ACTION']
      prediction_col = ['REVIEW_ACTION']

      categorical_features = ['DIVISION_NAME', 'PERSON_TYPE', 'JOB_CHANGE', 'JOB_TRANSFER',
      'SSO', 'USER_ID', 'ASSET_ID', 'ROLE', 'HPA', 'LAST_LOGIN_DATE',
      'USER ID', 'LABELED_ROLE']

      categorical_transformer = Pipeline(steps=[
      ('si', SimpleImputer(strategy='constant', fill_value='missing')),
      ('ohe', OneHotEncoder(handle_unknown='ignore'))],remainder='passthrough')

      preprocessor = ColumnTransformer(
      transformers=[
      ('cat', categorical_transformer, categorical_features)])

      rf = Pipeline(steps=[('preprocessor', preprocessor),
      ('rfc', RandomForestClassifier(n_estimators=100))
      ])


      So I let several fields
      Then I try to run the prediction



      df['rf_prediction'] = df[categorical_features].apply(rf.predict)


      and get the error:



      IndexingError: ('Too many indexers', 'occurred at index DIVISION_NAME') 


      I suspect that this has something to do with the columns being 'passthrough' but I'm not sure how to resolve it. I don't want to process some of these columns but want them in the results when I write the file so that I can validate the results.







      scikit-learn pipelines





      share







      New contributor




      Harvey 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




      Harvey 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




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









      asked 8 mins ago









      HarveyHarvey

      11




      11




      New contributor




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





      New contributor





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






      Harvey 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.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          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
          });


          }
          });






          Harvey 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%2f45355%2fsklearn-predict-indexingerror-too-many-indexers-occurred-at-index-name%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








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










          draft saved

          draft discarded


















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













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












          Harvey 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%2f45355%2fsklearn-predict-indexingerror-too-many-indexers-occurred-at-index-name%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

          Ponta tanko

          Tantalo (mitologio)

          Erzsébet Schaár