作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想开始 udacity 的机器学习类(class)。所以我下载了 ud120-projects-master.zip 文件并将其解压到我的下载文件夹中。我已经安装了 anaconda jupyter 笔记本(python 2.7)。
第一个迷你项目是Naïve-Bayes,所以我打开了jupyter笔记本和%load nb_author_id.py以转换为.ipynb但我想我必须首先运行tools文件夹中的startup.py来提取数据。
所以我运行了startup.ipynb。
# %load startup.py
print
print "checking for nltk"
try:
import nltk
except ImportError:
print "you should install nltk before continuing"
print "checking for numpy"
try:
import numpy
except ImportError:
print "you should install numpy before continuing"
print "checking for scipy"
try:
import scipy
except:
print "you should install scipy before continuing"
print "checking for sklearn"
try:
import sklearn
except:
print "you should install sklearn before continuing"
print
print "downloading the Enron dataset (this may take a while)"
print "to check on progress, you can cd up one level, then execute <ls -lthr>"
print "Enron dataset should be last item on the list, along with its current size"
print "download will complete at about 423 MB"
import urllib
url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
urllib.urlretrieve(url, filename="../enron_mail_20150507.tgz")
print "download complete!"
print
print "unzipping Enron dataset (this may take a while)"
import tarfile
import os
os.chdir("..")
tfile = tarfile.open("enron_mail_20150507.tgz", "r:gz")
tfile.extractall(".")
print "you're ready to go!"
但是出现错误......
checking for nltk
checking for numpy
checking for scipy
checking for sklearn
downloading the Enron dataset (this may take a while)
to check on progress, you can cd up one level, then execute <ls -lthr>
Enron dataset should be last item on the list, along with its current size
download will complete at about 423 MB
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-1-c30fe1ced56a> in <module>()
32 import urllib
33 url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
---> 34 urllib.urlretrieve(url, filename="../enron_mail_20150507.tgz")
35 print "download complete!"
36
这是 nb_author_id.py 的:
# %load nb_author_id.py
#!/usr/bin/python
"""
This is the code to accompany the Lesson 1 (Naive Bayes) mini-project.
Use a Naive Bayes Classifier to identify emails by their authors
authors and labels:
Sara has label 0
Chris has label 1
"""
import sys
from time import time
sys.path.append("../tools/")
from email_preprocess import preprocess
### features_train and features_test are the features for the training
### and testing datasets, respectively
### labels_train and labels_test are the corresponding item labels
features_train, features_test, labels_train, labels_test = preprocess()
#########################################################
### your code goes here ###
#########################################################
错误/警告
C:\Users\jr31964\AppData\Local\Continuum\Anaconda2\lib\site-packages\sklearn\cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
no. of Chris training emails: 7936
no. of Sara training emails: 7884
如何开始朴素贝叶斯迷你项目以及需要采取哪些先决条件。
最佳答案
由于我认为类(class)是在 Python 3 中进行的,所以我建议在 python 3 中创建一个 conda 环境。即使您有 python 2 的基本 python 安装,您也可以执行此操作。这应该可以帮助您将所有类(class)代码转换为python 3 到你的 python 2。
conda create --name UdacityCourseEnvironment python=3.6
# to get into your new environment (mac/linux)
source activate UdacityCourseEnvironment
# to get into your new environment (windows)
activate UdacityCourseEnvironment
# When you need new packages inside your new environment
conda install nameOfPackage
关于python-2.7 - 如何在 Anaconda Jupyter 笔记本和 Python 2.7 上开始 Udacity 的机器学习类(class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42154481/
我是一名优秀的程序员,十分优秀!