代码之家  ›  专栏  ›  技术社区  ›  Kusek

Google Colab ModuleNotFoundError:没有名为“sklearn.externals.joblib”的模块

  •  0
  • Kusek  · 技术社区  · 3 年前

    我的初始导入看起来是这样的,这个代码块运行得很好。

    # Libraries to help with reading and manipulating data
    import numpy as np
    import pandas as pd
    
    # Libraries to help with data visualization
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.set()
    
    # Removes the limit for the number of displayed columns
    pd.set_option("display.max_columns", None)
    # Sets the limit for the number of displayed rows
    pd.set_option("display.max_rows", 200)
    
    # to split the data into train and test
    from sklearn.model_selection import train_test_split
    
    # to build linear regression_model
    from sklearn.linear_model import LinearRegression
    
    # to check model performance
    from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
    

    但当我尝试执行以下命令时,我得到了错误ModuleNotFoundError:没有名为“sklearn.externals.joblib”的模块

    我试着用!pip为这个错误安装所有模块和其他建议它不起作用。这是谷歌colab,所以不确定我缺少什么

    from mlxtend.feature_selection import SequentialFeatureSelector as SFS
    
    1 回复  |  直到 3 年前
        1
  •  7
  •   anarchy    3 年前

    对于第二部分,您可以这样做来修复它,我也复制了您的其余代码,并添加了底部部分。

    # Libraries to help with reading and manipulating data
    import numpy as np
    import pandas as pd
    
    # Libraries to help with data visualization
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.set()
    
    # Removes the limit for the number of displayed columns
    pd.set_option("display.max_columns", None)
    # Sets the limit for the number of displayed rows
    pd.set_option("display.max_rows", 200)
    
    # to split the data into train and test
    from sklearn.model_selection import train_test_split
    
    # to build linear regression_model
    from sklearn.linear_model import LinearRegression
    
    # to check model performance
    from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
    
    # I changed this part
    !pip install mlxtend
    import joblib
    import sys
    sys.modules['sklearn.externals.joblib'] = joblib
    from mlxtend.feature_selection import SequentialFeatureSelector as SFS
    

    它对我有效。