Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting TypeError: only integer scalar arrays can be converted to a scalar index on #736

Open
vashist1994 opened this issue Jul 12, 2024 · 2 comments

Comments

@vashist1994
Copy link

I am trying to load the saved model using the following command

automl = AutoML(mode='Explain',results_path='Auto_Ml_testing')
automl.fit(X_train,y_train)

automl = AutoML(results_path='Auto_Ml_testing')

automl.predict(X_test)

but the '.predict' is giving the following error


TypeError Traceback (most recent call last)
Cell In[12], line 1
----> 1 automl.predict(X_test)

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\supervised\automl.py:451, in AutoML.predict(self, X)
434 def predict(self, X: Union[List, numpy.ndarray, pandas.DataFrame]) -> numpy.ndarray:
435 """
436 Computes predictions from AutoML best model.
437
(...)
449 AutoMLException: Model has not yet been fitted.
450 """
--> 451 return self._predict(X)

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\supervised\base_automl.py:1503, in BaseAutoML._predict(self, X)
1502 def _predict(self, X):
-> 1503 predictions = self._base_predict(X)
1504 # Return predictions
1505 # If classification task the result is in column 'label'
1506 # If regression task the result is in column 'prediction'
1507 return (
1508 predictions["label"].to_numpy()
1509 if self._ml_task != REGRESSION
1510 else predictions["prediction"].to_numpy()
1511 )

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\supervised\base_automl.py:1469, in BaseAutoML._base_predict(self, X, model)
1467 predictions = model.predict(X_stacked)
1468 else:
-> 1469 predictions = model.predict(X)
1471 if self._ml_task == BINARY_CLASSIFICATION:
1472 # need to predict the label based on predictions and threshold
1473 neg_label, pos_label = (
1474 predictions.columns[0][11:],
1475 predictions.columns[1][11:],
1476 )

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\supervised\model_framework.py:447, in ModelFramework.predict(self, X)
444 y_predicted = None # np.zeros((X.shape[0],))
445 for ind, learner in enumerate(self.learners):
446 # preprocessing goes here
--> 447 X_data, _, _ = self.preprocessings[ind].transform(X.copy(), None)
448 y_p = learner.predict(X_data)
449 y_p = self.preprocessings[ind].inverse_scale_target(y_p)

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\supervised\preprocessing\preprocessing.py:361, in Preprocessing.transform(self, X_validation, y_validation, sample_weight_validation)
359 for tt in self._text_transforms:
360 if X_validation is not None and tt is not None:
--> 361 X_validation = tt.transform(X_validation)
363 for missing in self._missing_values:
364 if X_validation is not None and missing is not None:

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\supervised\preprocessing\text_transformer.py:36, in TextTransformer.transform(self, X)
34 ii = ~pd.isnull(X[self._old_column])
35 x = X[self._old_column][ii]
---> 36 vect = self._vectorizer.transform(x)
38 for f in self._new_columns:
39 X[f] = 0.0

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\sklearn\feature_extraction\text.py:2118, in TfidfVectorizer.transform(self, raw_documents)
2115 check_is_fitted(self, msg="The TF-IDF vectorizer is not fitted")
2117 X = super().transform(raw_documents)
-> 2118 return self._tfidf.transform(X, copy=False)

File c:\Users\narvashi\projects\STERIS\venv\Lib\site-packages\sklearn\feature_extraction\text.py:1707, in TfidfTransformer.transform(self, X, copy)
1702 X.data += 1.0
1704 if hasattr(self, "idf_"):
1705 # the columns of X (CSR matrix) can be accessed with X.indices and
1706 # multiplied with the corresponding idf value
-> 1707 X.data *= self.idf_[X.indices]
1709 if self.norm is not None:
1710 X = normalize(X, norm=self.norm, copy=False)

TypeError: only integer scalar arrays can be converted to a scalar index

@pplonski
Copy link
Contributor

Thank you for reporting. It might be some bug on our side. Could you please the versions of following packages:

  • scikit-learn
  • numpy
  • pandas
    Thanks.

@liupgd
Copy link

liupgd commented Aug 22, 2024

I have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants