PyCaret执行setup时出现AttributeError: module 'pycaret' has no attribute 'utils'
问题描述
成功导入数据集后,执行以下代码时触发AttributeError: module 'pycaret' has no attribute 'utils'错误:
from pycaret.classification import ClassificationExperiment s = ClassificationExperiment() s.setup(data, target = 'Class variable', session_id = 123)
报错详情
Number of times pregnant Plasma glucose concentration a 2 hours in an oral glucose tolerance test Diastolic blood pressure (mm Hg) Triceps skin fold thickness (mm) 2-Hour serum insulin (mu U/ml) Body mass index (weight in kg/(height in m)^2) Diabetes pedigree function Age (years) Class variable 0 6 148 72 35 0 33.6 0.627 50 1 1 1 85 66 29 0 26.6 0.351 31 0 2 8 183 64 0 0 23.3 0.672 32 1 3 1 89 66 23 94 28.1 0.167 21 0 4 0 137 40 35 168 43.1 2.288 33 1 Output exceeds the size limit. Open the full output data in a text editor --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[33], line 3 1 from pycaret.classification import ClassificationExperiment 2 s = ClassificationExperiment() ----> 3 s.setup(data, target = 'Class variable', session_id = 123) File ~/.local/lib/python3.10/site-packages/pycaret/classification/oop.py:781, in ClassificationExperiment.setup(self, data, data_func, target, index, train_size, test_data, ordinal_features, numeric_features, categorical_features, date_features, text_features, ignore_features, keep_features, preprocess, create_date_columns, imputation_type, numeric_imputation, categorical_imputation, iterative_imputation_iters, numeric_iterative_imputer, categorical_iterative_imputer, text_features_method, max_encoding_ohe, encoding_method, rare_to_value, rare_value, polynomial_features, polynomial_degree, low_variance_threshold, group_features, group_names, drop_groups, remove_multicollinearity, multicollinearity_threshold, bin_numeric_features, remove_outliers, outliers_method, outliers_threshold, fix_imbalance, fix_imbalance_method, transformation, transformation_method, normalize, normalize_method, pca, pca_method, pca_components, feature_selection, feature_selection_method, feature_selection_estimator, n_features_to_select, custom_pipeline, custom_pipeline_position, data_split_shuffle, data_split_stratify, fold_strategy, fold, fold_shuffle, fold_groups, n_jobs, use_gpu, html, session_id, system_log, log_experiment, experiment_name, experiment_custom_tags, log_plots, log_profile, log_data, engine, verbose, memory, profile, profile_kwargs) 764 self._prepare_folds( 765 fold_strategy=fold_strategy, 766 fold=fold, 767 fold_shuffle=fold_shuffle, 768 fold_groups=fold_groups, 769 ) 771 self._prepare_column_types( 772 ordinal_features=ordinal_features, 773 numeric_features=numeric_features, (...) 778 keep_features=keep_features, 779 ) --> 781 self._set_exp_model_engines( 782 container_default_engines=get_container_default_engines(), 783 engine=engine, 784 ) 786 # Preprocessing ============================================ >> ... File ~/.local/lib/python3.10/site-packages/pycaret/containers/base_container.py:64, in BaseContainer.get_class_name(self) 63 def get_class_name(self): ---> 64 return pycaret.utils.generic.get_class_name(self.class_def) AttributeError: module 'pycaret' has no attribute 'utils'
期望输出
期望得到PyCaret初始化完成后的配置汇总表,内容包含:
- 目标变量名称
- 训练集/测试集拆分比例
- 特征类型统计(数值型、类别型等)
- 预处理步骤说明
- 交叉验证设置
- 其他实验配置信息
解决方案
- 重新安装并升级PyCaret:该错误通常因版本不兼容或安装不完整导致,执行以下命令重装:
pip uninstall -y pycaret pip install --upgrade pycaret[full] - 检查本地文件冲突:确保当前工作目录下没有名为
pycaret.py的文件,避免覆盖官方库的导入路径。 - 验证安装完整性:进入PyCaret安装目录(如
~/.local/lib/python3.10/site-packages/pycaret),确认utils文件夹存在且结构完整。若缺失,重新执行安装命令。
内容的提问来源于stack exchange,提问作者Murat Sivil
相关产品推荐
相关产品推荐

