<コード↓>
from sklearn.ensemble import RandomForestClassifier
trainingdata = [[1, 1], [2, 2], [-1, -1], [-2, -2]]
traininglabel = [1, 1, -1, -1]
testdata = [[3, 3], [-3, -3]]
model = RandomForestClassifier()
model.fit(trainingdata, traininglabel)
output = model.predict(testdata)
コード
for label in output: print label
from sklearn.ensemble import RandomForestClassifier
trainingdata = [[1, 1], [2, 2], [-1, -1], [-2, -2]]
traininglabel = [1, 1, -1, -1]
testdata = [[3, 3], [-3, -3]]
model = RandomForestClassifier()
model.fit(trainingdata, traininglabel)
output = model.predict(testdata)
for label in output: print label
<ターミナルのエラー表示↓>
ターミナルのエラー表示
Traceback (most recent call last):
File "estimation.py", line 3, in
from sklearn.ensemble import RandomForestClassifier
File "/Library/Python/2.7/site-packages/sklearn/init.py", line 57, in
from .base import clone
File "/Library/Python/2.7/site-packages/sklearn/base.py", line 12, in
from .utils.fixes import signature
File "/Library/Python/2.7/site-packages/sklearn/utils/init.py", line 18, in
from ..externals.joblib import cpu_count
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/init.py", line 128, in
from .parallel import Parallel
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/parallel.py", line 30, in
from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 17, in
from .pool import MemmapingPool
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/pool.py", line 23, in
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in
from random import Random as _Random
ImportError: cannot import name Random
Traceback (most recent call last):
File "estimation.py", line 3, in <module>
from sklearn.ensemble import RandomForestClassifier
File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/Library/Python/2.7/site-packages/sklearn/base.py", line 12, in <module>
from .utils.fixes import signature
File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 18, in <module>
from ..externals.joblib import cpu_count
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/__init__.py", line 128, in <module>
from .parallel import Parallel
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/parallel.py", line 30, in <module>
from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 17, in <module>
from .pool import MemmapingPool
File "/Library/Python/2.7/site-packages/sklearn/externals/joblib/pool.py", line 23, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random