尝试将数据框列传递给 ANN 时出现 ValueError
ValueError when trying to pass a dataframe column to ANN
在尝试将我的数据拟合到我的 sklearn ANN 模型中时,我不断收到值错误。错误指出“ValueError:未知标签类型:(数组([0.836,0.741,0.789,...,0.74,0.812,0.748]),)”
x = df[['danceability', 'energy', 'loudness', 'tempo']].values
y = df['valence'].values
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.25)
scaler = StandardScaler()
scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
mlp = MLPClassifier(hidden_layer_sizes=(10, 10, 10), max_iter=1000)
mlp.fit(X_train, y_train)
传递的所有 5 列都包含浮点值,其中 4 列包括仅包含 0 到 1 之间的值的化合价。我尝试使用 np.array(__).reshape(-1,1)等等,但我不确定未知标签类型是什么意思。
根据 scikit-learn documentation
"When doing classification in scikit-learn, y is a vector of integers
or strings."
而不是行:
y = df['valence'].values
试试这个:
y = np.asarray(df['valence'], dtype="|S6")
在尝试将我的数据拟合到我的 sklearn ANN 模型中时,我不断收到值错误。错误指出“ValueError:未知标签类型:(数组([0.836,0.741,0.789,...,0.74,0.812,0.748]),)”
x = df[['danceability', 'energy', 'loudness', 'tempo']].values
y = df['valence'].values
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.25)
scaler = StandardScaler()
scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
mlp = MLPClassifier(hidden_layer_sizes=(10, 10, 10), max_iter=1000)
mlp.fit(X_train, y_train)
传递的所有 5 列都包含浮点值,其中 4 列包括仅包含 0 到 1 之间的值的化合价。我尝试使用 np.array(__).reshape(-1,1)等等,但我不确定未知标签类型是什么意思。
根据 scikit-learn documentation
"When doing classification in scikit-learn, y is a vector of integers or strings."
而不是行:
y = df['valence'].values
试试这个:
y = np.asarray(df['valence'], dtype="|S6")