私はデータフレームの列を0と1の間の値になるようにスケールしたいと思っています。これはうまく動作しますが、私に混合メッセージを送信しているMinMaxScaler
。私がやっている:Python/sklearn - preprocessing.MinMaxScaler 1d廃止
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.
わかりましたので、apparentyl 1D配列を有するつもりノーノーすぐにも、それでは試してみましょうされています。このコードの
x = df['Activity'].values #returns a numpy array
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df['Activity'] = pd.Series(x_scaled)
メッセージNUMERO UNOのは警告です助言としてそれを再構築する:
x = df['Activity'].values.reshape(-1, 1)
を今のコードでも実行されません:Exception: Data must be 1-dimensional
がスローされます。だから私は混乱している。すぐに廃止される予定ですが、データも1dでなければなりませんか?これを安全に行う方法は?ここで何が問題なの?
array([ 0.00568953, 0.00634314, 0.00718003, ..., 0.01976002,
0.00575024, 0.00183782])
と整形後:
全体警告:
/usr/local/lib/python3.5/dist-packages/sklearn/preprocessing/data.py:321: 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.
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/preprocessing/data.py:356: 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.
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning)
@sascha
x
によって要求されるように
EDITは、このようになります210
私は再構築エラー:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-132-df180aae2d1a> in <module>()
2 min_max_scaler = preprocessing.MinMaxScaler()
3 x_scaled = min_max_scaler.fit_transform(x)
----> 4 telecom['Activity'] = pd.Series(x_scaled)
/usr/local/lib/python3.5/dist-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
225 else:
226 data = _sanitize_array(data, index, dtype, copy,
--> 227 raise_cast_failure=True)
228
229 data = SingleBlockManager(data, index, fastpath=True)
/usr/local/lib/python3.5/dist-packages/pandas/core/series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
2918 elif subarr.ndim > 1:
2919 if isinstance(data, np.ndarray):
-> 2920 raise Exception('Data must be 1-dimensional')
2921 else:
2922 subarr = _asarray_tuplesafe(data, dtype=dtype)
Exception: Data must be 1-dimensional
は、xの形状を表示します再形成の前後にまた、希望する配列形式のドキュメントを読んでください。 1次元のような入力が常にありますが、それらは1つの行として提示する必要があります(1つのサンプルの場合、実際には2になるように)。 – sascha
@sascha質問が要求通りに更新されました。 –
エラーが驚くことのないpd.Series()行の一部ではないことを確かめてください。私は本当に人々がスタックトレース/エラー全体を投稿しない理由を理解できません...多くの情報は、それ以上のコンテキストなしでエラー自体を表示するだけで失われます。 – sascha