i have feature vector shape x_train.shape
(52, 54)
when train keras model throws me error as:
valueerror: error when checking model input: expected dense_109_input have shape (none, 52) got array shape (52, 54)
i have tried can think of scanned stack overflow problem still persists. code as:
import pandas pd keras.models import sequential keras.layers import dense sklearn.model_selection import train_test_split sklearn.metrics import accuracy_score ##### reading csv ##### data = pd.read_csv('dataset/emotion_data.csv') x = data.ix[:, 4:] y = data['label'] ##### normalizing ##### featurename = list(x) name in featurename: x[name] = (x[name] - min(x[name]))/(max(x[name]) - min(x[name])) x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=3) ##### model ##### model = sequential() model.add(dense(100, input_shape=(54,), activation='relu')) model.add(dense(100, activation='relu')) model.add(dense(1, activation='softmax')) model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy']) model.fit(x_train, y_train) prediction = model.predict(x_test) print(accuracy_score(y_test, prediction))
if interested in data head
in[42]: x_train.head() out[42]: tempo total_beats average_beats chroma_stft_mean chroma_stft_std \ 35 0.438961 0.480897 0.505383 0.504320 0.938452 34 0.520000 0.552580 0.500670 0.581778 0.680247 63 0.477551 0.361328 0.334990 0.705472 0.357676 27 0.477551 0.345419 0.309433 0.492245 0.728405 43 0.520000 0.530305 0.495715 0.306097 0.663995 chroma_stft_var chroma_cq_mean chroma_cq_std chroma_cq_var \ 35 0.932494 0.975206 0.394472 0.366960 34 0.657810 0.654770 0.550766 0.522269 63 0.333977 0.495473 0.618748 0.591578 27 0.707998 0.644147 0.628125 0.601222 43 0.640980 0.591299 0.639918 0.613379 chroma_cens_mean ... zcr_var harm_mean harm_std harm_var \ 35 0.964034 ... 0.381363 0.021468 0.426776 0.225840 34 0.755071 ... 0.213207 0.021598 0.115191 0.031476 63 0.704930 ... 0.197960 0.021620 0.350194 0.163286 27 0.715832 ... 0.247092 0.022253 0.319208 0.140714 43 0.784991 ... 0.221276 0.021777 0.656981 0.471881 perc_mean perc_std perc_var frame_mean frame_std frame_var 35 0.362241 0.673257 0.467421 0.343459 0.174215 0.048846 34 0.365434 0.152561 0.031588 0.091940 0.088991 0.018342 63 0.340043 0.320664 0.116833 0.097610 0.077334 0.015154 27 0.372315 0.604247 0.380492 0.995443 1.000000 1.000000 43 0.377154 0.529161 0.296033 0.122519 0.089255 0.018417 [5 rows x 54 columns]
it seems simple problem. try first layer of network:
keras.add(dense(100, input_shape=(54,), activation='relu'))
your problem came fact input_shape
should input
of single example. have 52 examples of length 54. why there should input_shape=(54,)
.
Comments
Post a Comment