亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

蟒蛇錯誤。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 關注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號