我正在从 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)
交互式爱情
POPMUISE
相关分类