質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

299閲覧

reshape(-1,1)

tomatoto11

総合スコア10

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/04/16 10:12

前提・実現したいこと

reshape(-1,1)を使いたいのですがどのように使ったらいいのかわかりません!
教えてください、お願いします!

発生している問題・エラーメッセージ

エラーメッセージ ValueError Traceback (most recent call last) <ipython-input-26-9f692dcedeec> in <module>() 1 np.reshape(-1,1) ----> 2 num_rooms_std=sc_x.transform([5.0]) 3 price_std=lr.predict(num_rooms_std) 4 print("Price in $1000s: %.3f" % sc_y.inverse_transform(price_std)) ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/preprocessing/data.py in transform(self, X, y, copy) 679 copy = copy if copy is not None else self.copy 680 X = check_array(X, accept_sparse='csr', copy=copy, warn_on_dtype=True, --> 681 estimator=self, dtype=FLOAT_DTYPES) 682 683 if sparse.issparse(X): ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator) 439 "Reshape your data either using array.reshape(-1, 1) if " 440 "your data has a single feature or array.reshape(1, -1) " --> 441 "if it contains a single sample.".format(array)) 442 array = np.atleast_2d(array) 443 # To ensure that array flags are maintained ValueError: Expected 2D array, got 1D array instead: array=[5.]. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

該当のソースコード

python

1num_rooms_std=sc_x.transform([5.0]) 2price_std=lr.predict(num_rooms_std) 3print("Price in $1000s: %.3f" % sc_y.inverse_transform(price_std))

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

meg_

2020/04/16 11:36

「reshape(-1,1)を使いたい」のは何故ですか? 実行可能(検証可能)なコードを提示してください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問