I need to check whether an object is from the sklearn
library. Basically, I need to check if a model belongs to a specific library so I can create a general pattern based on it's type.
I need to check that if I receive a model
object that it belongs to the sklearn
library.
For example,
if isinstance(model, sklearn):
#do something
I would like to avoid try drilling down to checking types of specific models.
For example,
from sklearn.linear_model import LinearRegression
from sklearn.cluster import FeatureAgglomeration
if isinstance(model, sklearn.linear_model.LinearRegression):
#to something
if isinstance(model, sklearn.cluster.FeatureAgglomeration):
#to something
The above are acceptable models. However, sklearn
has too many models and is constantly changing. I would just like to check if its from the sklearn
library.