読者です 読者をやめる 読者になる 読者になる

のねのBlog

パソコンやソフト開発で起きた問題など書きます。よろしくお願いします。

DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17

エラーの場合:

reg.predict([27])

正常の場合:
 角カッコの数が2個だった。

reg.predict([[27]])
/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py:386: 
DeprecationWarning: 
Passing 1d arrays as data is deprecated in 0.17 
and willraise ValueError in 0.19.
 Reshape your data either using X.reshape(-1, 1) 
if your data has a single feature 
or X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)

Traceback (most recent call last):
  File "vm_main.py", line 33, in <module>
    import main
  File "/tmp/vmuser_aetkxispzi/main.py", line 2, in <module>
    import studentMain
  File "/tmp/vmuser_aetkxispzi/studentMain.py", line 5, in <module>
    import regressionQuiz as student_code
  File "/tmp/vmuser_aetkxispzi/regressionQuiz.py", line 15, in <module>
    print "katie's net worth prediction:", reg.predict([27,27])
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 200, in predict
    return self._decision_function(X)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 185, in _decision_function
    dense_output=True) + self.intercept_
  File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/extmath.py", line 184, in safe_sparse_dot
    return fast_dot(a, b)
ValueError: shapes (1,2) and (1,1) not aligned: 2 (dim 1) != 1 (dim 0)
katie's net worth prediction:

stackoverflow.com

この記法は, shape に (1, -1) や (-1, 1) を指定すると,
それぞれ2次元の横ベクトルや縦ベクトルを簡便に作ることができます.

引用元、配列の次元数や大きさの操作 — 機械学習の Python との出会い

stackoverflow.com