今python機械学習プログラミングをやつているのですが、
2章の時点でエラーがでてしまいます
lang
1import numpy as np 2 3 4class Perceptron(object): 5 """Perceptron classifier. 6 7 Parameters 8 ------------ 9 eta : float 10 Learning rate (between 0.0 and 1.0) 11 n_iter : int 12 Passes over the training dataset. 13 14 Attributes 15 ----------- 16 w_ : 1d-array 17 Weights after fitting. 18 errors_ : list 19 Number of misclassifications in every epoch. 20 21 """ 22 def __init__(self, eta=0.01, n_iter=10): 23 self.eta = eta 24 self.n_iter = n_iter 25 26 def fit(self, X, y): 27 """Fit training data. 28 29 Parameters 30 ---------- 31 X : {array-like}, shape = [n_samples, n_features] 32 Training vectors, where n_samples is the number of samples and 33 n_features is the number of features. 34 y : array-like, shape = [n_samples] 35 Target values. 36 37 Returns 38 ------- 39 self : object 40 41 """ 42 self.w_ = np.zeros(1 + X.shape[1]) 43 self.errors_ = [] 44 45 for _ in range(self.n_iter): 46 errors = 0 47 for xi, target in zip(X, y): 48 update = self.eta * (target - self.predict(xi)) 49 self.w_[1:] += update * xi 50 self.w_[0] += update 51 errors += int(update != 0.0) 52 self.errors_.append(errors) 53 return self 54 55 def net_input(self, X): 56 """Calculate net input""" 57 return np.dot(X, self.w_[1:]) + self.w_[0] 58 59 def predict(self, X): 60 """Return class label after unit step""" 61 return np.where(self.net_input(X) >= 0.0, 1, -1)
le "<stdin>", line 1
def fit(self, X, y):
^
IndentationError: unexpected indent
File "<stdin>", line 1
"""Fit training data. ^
IndentationError: unexpected indent
File "<stdin>", line 1
Parameters ^
IndentationError: unexpected indent
File "<stdin>", line 1
---------- ^
IndentationError: unexpected indent
File "<stdin>", line 1
X : {array-like}, shape = [n_samples, n_features] ^
IndentationError: unexpected indent
File "<stdin>", line 1
Training vectors, where n_samples is the number of samples and ^
IndentationError: unexpected indent
File "<stdin>", line 1
n_features is the number of features. ^
IndentationError: unexpected indent
File "<stdin>", line 1
y : array-like, shape = [n_samples] ^
IndentationError: unexpected indent
File "<stdin>", line 1
Target values. ^
IndentationError: unexpected indent
File "<stdin>", line 1
Returns ^
IndentationError: unexpected indent
File "<stdin>", line 1
------- ^
IndentationError: unexpected indent
File "<stdin>", line 1
self : object ^
IndentationError: unexpected indent
File "<stdin>", line 1
""" ^
こういうエラーがでます
またipythonもインストールしたのですが、
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?
ImportError Traceback (most recent call last)
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/core/shellapp.pyc in <lambda>(key)
196 shell = self.shell
197 if self.pylab:
--> 198 enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
199 key = self.pylab
200 elif self.matplotlib:
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/core/interactiveshell.pyc in enable_pylab(self, gui, import_all, welcome_message)
2972 from IPython.core.pylabtools import import_pylab
2973
-> 2974 gui, backend = self.enable_matplotlib(gui)
2975
2976 # We want to prevent the loading of pylab to pollute the user's
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
2921 """
2922 from IPython.core import pylabtools as pt
-> 2923 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
2924
2925 if gui != 'inline':
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/core/pylabtools.pyc in find_gui_and_backend(gui, gui_select)
258 """
259
--> 260 import matplotlib
261
262 if gui and gui != 'auto':
ImportError: No module named matplotlib
[TerminalIPythonApp] WARNING | Unknown error in handling startup files:
ImportError Traceback (most recent call last)
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/core/shellapp.pyc in _exec_file(self, fname, shell_futures)
326 self.shell.user_ns,
327 shell_futures=shell_futures,
--> 328 raise_exceptions=True)
329 finally:
330 sys.argv = save_argv
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/core/interactiveshell.pyc in safe_execfile(self, fname, *where, **kw)
2467 py3compat.execfile(
2468 fname, glob, loc,
-> 2469 self.compile if kw['shell_futures'] else None)
2470 except SystemExit as status:
2471 # If the call was made with 0 or None exit status (sys.exit(0)
/usr/lib/python2.7/site-packages/ipython-5.0.0-py2.7.egg/IPython/utils/py3compat.pyc in execfile(fname, glob, loc, compiler)
286 where = [ns for ns in [glob, loc] if ns is not None]
287 if compiler is None:
--> 288 builtin_mod.execfile(filename, *where)
289 else:
290 scripttext = builtin_mod.open(fname).read().rstrip() + '\n'
/root/.ipython/profile_default/startup/00-setup.py in <module>()
----> 1 import numpy as np
2 import matplotlib.pyplot as plt
3 import pandas as pd
4 from pandas import Series, DataFrame
ImportError: No module named numpy
以前はcanopyをインストールしていました。
なにかまだミスがのこっているのでしょうか?
pythonが3.4.3のはずなのにpython2.7.5になっているのも
不明です。
python --versionでは
Python 3.4.3
pip --version
pip 8.1.2 from /usr/local/python/lib/python3.4/site-packages (python 3.4)
となります
pythonには
backports-abc==0.4
cycler==0.10.0
decorator==4.0.10
entrypoints==0.2.2
ipykernel==4.3.1
ipython==5.0.0
ipython-genutils==0.1.0
ipywidgets==5.1.5
Jinja2==2.8
jsonschema==2.5.1
jupyter==1.0.0
jupyter-client==4.3.0
jupyter-console==5.0.0
jupyter-core==4.1.0
MarkupSafe==0.23
matplotlib==1.5.1
mistune==0.7.3
nbconvert==4.2.0
nbformat==4.0.1
notebook==4.2.1
numpy==1.11.1
pandas==0.18.1
pexpect==4.2.0
pickleshare==0.7.2
prompt-toolkit==1.0.3
ptyprocess==0.5.1
Pygments==2.1.3
pyparsing==2.1.5
python-dateutil==2.5.3
pytz==2016.4
pyzmq==15.3.0
qtconsole==4.2.1
scikit-learn==0.17.1
scipy==0.17.1
simplegeneric==0.8.1
six==1.10.0
terminado==0.6
tornado==4.3
traitlets==4.2.2
wcwidth==0.1.7
widgetsnbextension==1.2.3
入れています。
すいません。2つよろしくお願します。
後この部分がわからないこの部分調べたとかあれば出しますので、よろしくお願いします。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/13 06:32