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

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

新規登録して質問してみよう
ただいま回答率
85.46%
機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

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

Q&A

解決済

1回答

857閲覧

エラーの対処方法がわからない

os-t

総合スコア20

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

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

0グッド

0クリップ

投稿2020/04/13 07:19

編集2020/04/13 12:11

前提・実現したいこと

Wineデータセットを読み込み、MinMaaxスケーリングをしたい。

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

ValueError Traceback (most recent call last) <ipython-input-163-4541c75c7333> in <module> 1 from sklearn.preprocessing import MinMaxScaler 2 mms = MinMaxScaler() ----> 3 X_train_norm = mms.fit_transform(X_train) 4 X_test_norm = mms.transform(X_test) ~\anaconda3\lib\site-packages\sklearn\base.py in fit_transform(self, X, y, **fit_params) 569 if y is None: 570 # fit method of arity 1 (unsupervised transformation) --> 571 return self.fit(X, **fit_params).transform(X) 572 else: 573 # fit method of arity 2 (supervised transformation) ~\anaconda3\lib\site-packages\sklearn\preprocessing\_data.py in fit(self, X, y) 337 # Reset internal state before fitting 338 self._reset() --> 339 return self.partial_fit(X, y) 340 341 def partial_fit(self, X, y=None): ~\anaconda3\lib\site-packages\sklearn\preprocessing\_data.py in partial_fit(self, X, y) 371 X = check_array(X, 372 estimator=self, dtype=FLOAT_DTYPES, --> 373 force_all_finite="allow-nan") 374 375 data_min = np.nanmin(X, axis=0) ~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator) 554 "Reshape your data either using array.reshape(-1, 1) if " 555 "your data has a single feature or array.reshape(1, -1) " --> 556 "if it contains a single sample.".format(array)) 557 558 # in the future np.flexible dtypes will be handled like object dtypes ValueError: Expected 2D array, got 1D array instead: array=[13.71 12.22 13.27 13.16 13.86 12.85 13.84 13.3 13.05 12.51 12.29 12.77 12.96 13.67 13.16 12.37 12.47 11.81 13.24 14.1 11.61 12.99 12.77 13.48 11.46 12.07 11.82 13.45 12.2 13.05 13.17 12.08 12.17 12.42 11.87 12.21 13.94 14.1 12.67 14.75 12.25 12.85 13.73 14.06 13.63 12.33 13.82 12.08 13.03 14.37 13.17 12.72 14.39 13.34 11.66 11.84 12.86 13.75 12.53 13.11 14.38 14.23 12. 13.23 14.38 14.12 12. 12.34 13.48 13.29 13.41 13.71 12.37 13.2 11.45 13.62 13.88 12.42 12.81 12.58 13.83 13.07 12.7 13.77 12.84 12.37 13.51 13.87 12.08 13.58 13.08 11.79 12.45 13.68 13.52 13.5 12.87 14.02 12.29 12.08 12.7 11.03 13.32 14.13 13.49 11.84 13.05 12.72 12.82 13.4 14.22 13.72 12.93 11.64 12.29 11.65 13.28 12.93 13.86 11.82 12.37 12.42 13.9 14.16]. 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

1df_wine = pd.read_csv( 2 'https://raw.githubusercontent.com/tirthajyoti/Machine-Learning-with-Python/master/Datasets/wine.data.csv', header = 0) 3 4df_wine.columns = ['Class label', 'Alcohol', 'Malic acid', 'Ash', 5 'Alcalinity of ash', 'Magnesium', 'Total phenols', 'Flavanoids', 6 'Nonflavanoid phenols', 'Proanthocyanis', 'Color intenesity', 'Hue', 7 'OD280/OD315 of diluted wines', 'Proline'] 8 9 10print('Class labels', np.unique(df_wine['Class label'])) 11df_wine.head() 12 13from sklearn.model_selection import train_test_split 14X, y = df_wine.iloc[:, 1].values, df_wine.iloc[:, 0].values 15 16X_train, X_test, y_train, y_test = \ 17 train_test_split(X, y, test_size = 0.3, random_state = 0) 18 19from sklearn.preprocessing import MinMaxScaler 20mms = MinMaxScaler() 21X_train_norm = mms.fit_transform(X_train) 22X_test_norm = mms.transform(X_test)

試したこと

教科書(Python machine learning 2nd edition)では、random_state = 0の直後にstratify = y、'~ csv'の直後にheader = Noneが入っており、それぞれエラーが発生していましたが、それは削除することで解決しました。しかし、このエラーだけはどのように解決すればよいのかがわかりません。
わかる方、お願いします。

補足情報(ツールのバージョンなど)

anaconda JupiterLab 1.2.6

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

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

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

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

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

meg_

2020/04/13 11:34

エラーメッセージに「Reshape your data either using array.reshape(-1, 1)」とありますが、こちらは試されましたか?
os-t

2020/04/14 06:04

Xとyのところにreshapeをつけるとエラーが消えました。ありがとうございます。
guest

回答1

0

自己解決

解決しました。ありがとうございます。

投稿2020/04/14 06:05

os-t

総合スコア20

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問