简体   繁体   中英

How to solve ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection' in Google Colaboratory?

I am trying to design a decision surface of decision trees trained on pairs of features in my dataset in Google Colaboratory.

Example Code:

import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.inspection import DecisionBoundaryDisplay
iris = load_iris()

But colab produces a error like, ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection' (/usr/local/lib/python3.7/dist-packages/sklearn/inspection/ init .py).

How can I solve this problem in Google Colab?

Thanks.

DecisionBoundaryDisplay was added in sklearn v1.1. At present, Colab has sklearn v1.0.2 by default, and you can't upgrade because sklv1.1 requires python>=v3.8 but Colab has with python3.7.15.

There are a few posts here already about upgrading the python version of Colab; start at Install Python 3.8 kernel in Google Colaboratory and view Linked/Related questions as needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM