sklearn.preprocessing
にMinMaxScaler
を使用してトレーニングとテストデータセットを正規化します。ただし、パッケージはテストデータセットを受け入れていないようです。これを実行するとPython ValueError:シェイプ(124,1)の出力不可オペランドがブロードキャストシェイプと一致しません。(124,13)
import pandas as pd
import numpy as np
# Read in data.
df_wine = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data',
header=None)
df_wine.columns = ['Class label', 'Alcohol', 'Malic acid', 'Ash',
'Alcalinity of ash', 'Magnesium', 'Total phenols',
'Flavanoids', 'Nonflavanoid phenols', 'Proanthocyanins',
'Color intensity', 'Hue', 'OD280/OD315 of diluted wines',
'Proline']
# Split into train/test data.
from sklearn.model_selection import train_test_split
X = df_wine.iloc[:, 1:].values
y = df_wine.iloc[:, 0].values
X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.3,
random_state = 0)
# Normalize features using min-max scaling.
from sklearn.preprocessing import MinMaxScaler
mms = MinMaxScaler()
X_train_norm = mms.fit_transform(X_train)
X_test_norm = mms.transform(X_test)
、私はValueError: operands could not be broadcast together with shapes (124,) (13,) (124,)
とともにDeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise 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.
を取得します。
データを再構成すると、エラーが発生します。
X_test_norm = mms.transform(X_test.reshape(-1, 1))
このように再構成すると、エラーValueError: non-broadcastable output operand with shape (124,1) doesn't match the broadcast shape (124,13)
が返されます。
どのようにこのエラーを解決するための入力は参考になります。
あなたは形状誤差を持っている場合は、あなたがする必要がある最初の事はでは、あなたの問題に入るすべてのアレイの形状が表示されていますこの場合、 'X_train'と' X_test'はもっと多くなるかもしれません。 – hpaulj