Home › Fóruns › Fórum Machine Learning e Data Science com Python de A à Z › arvore de decisão
- Este tópico contém 1 resposta, 2 vozes e foi atualizado pela última vez 9 meses atrás por
Denny Ceccon.
- AutorPosts
- 16 de junho de 2024 às 15:32 #45435
Boa tarde!! Deu erro, poderia me ajudar identificar, por favor,o problema?
from yellowbrick.classifier import ConfusionMatrix
cm = ConfusionMatrix(arvore_credit)
cm.fit(x_census_treinamento,y_census_treinamento)
cm.score(x_census_teste,y_census_teste)ValueError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_10800\3205665905.py in <module>
2 cm = ConfusionMatrix(arvore_credit)
3 cm.fit(x_census_treinamento,y_census_treinamento)
—-> 4 cm.score(x_census_teste,y_census_teste)~\anaconda3\lib\site-packages\yellowbrick\classifier\confusion_matrix.py in score(self, X, y)
192 “””
193 # Call super to check if fitted and to compute self.score_
–> 194 super(ConfusionMatrix, self).score(X, y)
195
196 # Create predictions from X (will raise not fitted error)~\anaconda3\lib\site-packages\yellowbrick\classifier\base.py in score(self, X, y)
236
237 # This method implements ScoreVisualizer (do not call super).
–> 238 self.score_ = self.estimator.score(X, y)
239 return self.score_
240~\anaconda3\lib\site-packages\sklearn\base.py in score(self, X, y, sample_weight)
649 from .metrics import accuracy_score
650
–> 651 return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
652
653 def _more_tags(self):~\anaconda3\lib\site-packages\sklearn\tree\_classes.py in predict(self, X, check_input)
465 “””
466 check_is_fitted(self)
–> 467 X = self._validate_X_predict(X, check_input)
468 proba = self.tree_.predict(X)
469 n_samples = X.shape[0]~\anaconda3\lib\site-packages\sklearn\tree\_classes.py in _validate_X_predict(self, X, check_input)
431 “””Validate the training data on predict (probabilities).”””
432 if check_input:
–> 433 X = self._validate_data(X, dtype=DTYPE, accept_sparse=”csr”, reset=False)
434 if issparse(X) and (
435 X.indices.dtype != np.intc or X.indptr.dtype != np.intc~\anaconda3\lib\site-packages\sklearn\base.py in _validate_data(self, X, y, reset, validate_separately, **check_params)
583
584 if not no_val_X and check_params.get(“ensure_2d”, True):
–> 585 self._check_n_features(X, reset=reset)
586
587 return out~\anaconda3\lib\site-packages\sklearn\base.py in _check_n_features(self, X, reset)
398
399 if n_features != self.n_features_in_:
–> 400 raise ValueError(
401 f”X has {n_features} features, but {self.__class__.__name__} ”
402 f”is expecting {self.n_features_in_} features as input.”ValueError: X has 108 features, but DecisionTreeClassifier is expecting 3 features as input.
In [ ]:
17 de junho de 2024 às 10:41 #45438Olá André,
Eu executei o notebook desta aula até essa parte do código e deu tudo certo, pela mensagem de erro é possível que você tenha esquecido de executar algum código, tenta de novo desde o início.
- AutorPosts
- Você deve fazer login para responder a este tópico.