我有一个数组数据,该数据具有5000行(图像)和58列(功能)。数组为CSV格式。如何使用CNN进行分类?
我正在尝试以下代码,但出现错误。怎么了?
import keras
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Convolution1D, MaxPooling2D
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
data = pd.read_csv('/home/mahfuz/Documents/AllFeatures.csv')
data.head()
data.iloc[3,1:].values
df_x = data.iloc[:,1:].values
y = data.iloc[:,1].values
df_x = np.array(df_x)
df_y = np.array(y)
df_y
df_y.shape
df_x.shape
x_train, x_test, y_train, y_test = train_test_split(df_x,df_y,test_size=0.2,random_state=4)
model = Sequential()
model.add(Convolution1D(32, (3, 3), input_shape= ( 32, 32, 3)))
model.add(MaxPooling1D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(100))
model.add(Dropout(0.5))
model.add(Dense(10))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',optimizer = 'adadelta', metrices = ['accuracy'])
model.fit(x_train,y_train,validation_data=(x_test,y_test))
model.evaluate(x_test,y_test)
答案 0 :(得分:0)
请问是什么错误? 首先,在Conv1D上,模型中的数据形状为(32,32,3),检查它。 您的图片形状是(32,32,3)还是您的数据形状是(5000,58)?