为了账号安全,请及时绑定邮箱和手机立即绑定

蟒蛇错误。ImportError:没有名为 feature_format 的模块

蟒蛇错误。ImportError:没有名为 feature_format 的模块

一只斗牛犬 2022-06-14 16:22:37
我正在从 Udacity 课程中学习回归,"Intro to Machine Learning"并且正在完成其中的迷你项目。我复制了项目的代码,编写了回归部分,作为代码的一部分,并尝试在 Python 2 中的 Jupyter Notebook 上运行它。不幸的是,我收到了以下错误。    ImportError                               Traceback (most recent call last)    <ipython-input-8-433cee6c5e25> in <module>()         15 import pickle         16 sys.path.append("../tools/")    ---> 17 from feature_format import featureFormat, targetFeatureSplit         18 dictionary = pickle.load( open("../final_project/final_project_dataset_modified.pkl", "r") )         19     ImportError: No module named feature_format我正在处理的代码如下:加载/格式化数据集的修改版本(为什么要修改?我们已经删除了一些麻烦点,你会发现自己在异常值迷你项目中)。绘制一个小散点图训练/测试数据n您在指示处填写回归代码:    #!/usr/bin/python    import sys    import pickle    sys.path.append("../tools/")    from feature_format import featureFormat, targetFeatureSplit    dictionary = pickle.load( open("../final_project/final_project_dataset_modified.pkl", "r") )    ### list the features you want to look at--first item in the     ### list will be the "target" feature    features_list = ["bonus", "salary"]    data = featureFormat( dictionary, features_list, remove_any_zeroes=True)    target, features = targetFeatureSplit( data )    ### training-testing split needed in regression, just like classification    from sklearn.cross_validation import train_test_split    feature_train, feature_test, target_train, target_test = train_test_split(features, target, test_size=0.5, random_state=42)    train_color = "b"    test_color = "r"    ### Your regression goes here!    ### Please name it reg, so that the plotting code below picks it up and     ### plots it correctly. Don't forget to change the test_color above from "b" to    ### "r" to differentiate training points from test points.    from sklearn import linear_model    reg = linear_model.LinearRegression()    reg.fit(feature_train,target_train)
查看完整描述

2 回答

?
交互式爱情

TA贡献1712条经验 获得超3个赞

原因

ImportError: No module named feature_format表示没有名为 的模块feature_format

该模块已在您正在使用的存储库中定义ud120-projects/tools/feature_format.py

解决方案 1

模块的路径feature_format在第 3 行中声明k_means_cluster.py。作为传递给的参数sys.path.append

将路径从相对路径更改为绝对路径,例如sys.path.append("ud120-projects/tools/")

解决方案 2

一切都好做这个简单的把戏。
克隆 GitHub 存储库

git clone https://github.com/udacity/ud120-projects.git

转到ud120-projects/k_means/目录

cd ud120-projects/k_means/

然后是 python2 的 python 脚本

python k_means_cluster.py


查看完整回答
反对 回复 2022-06-14
?
POPMUISE

TA贡献1765条经验 获得超5个赞

尝试添加:


import sys

!{sys.executable} -m pip install feature_format

在导入 feature_format 之前。这个“应该”安装它。


查看完整回答
反对 回复 2022-06-14
  • 2 回答
  • 0 关注
  • 104 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号