I'm currently building a model to forcast weather using kaggle Istanbul datasets. I've downloaded and loaded the csv file. I select all the interesting columns, convert them, add code to categorical data and so on.
df = pd.read_csv('/content/Istanbul Weather Data.csv',sep=",") #store our dataFrame into Df
df = df[["DateTime","Condition","Rain","MaxTemp","MinTemp","AvgWind","AvgHumidity","AvgPressure"]]
df["DateTime"] = pd.to_datetime(df["DateTime"].str.replace(".","/"))
#Now let's associate a code to our str data which are categorical :
#Condition : sunny = 0, Partly cloudy = 1, overcast =2, cloudy=3, patchy rain possible=4
#Rain : nothing = 0, rain = 1, snow = 2( for another dataset)
for ind in df.index:
if df['Rain'][ind] != 0.0 :
df['Rain'][ind] = 1.0
else:
df['Rain'][ind] = 0.0
if df['Condition'][ind]== "Sunny":
df['Condition'][ind] = 0.0
elif df['Condition'][ind] == "Partly cloudy" :
df['Condition'][ind] = 1.0
elif df['Condition'][ind] == "Overcast" :
df['Condition'][ind] = 2.0
elif df['Condition'][ind] == "Cloudy" :
df['Condition'][ind] = 3.0
else :
df['Condition'][ind] = 4.0
df['Rain'] = df['Rain'].astype(int)
df['Condition'] = df['Condition'].astype(int)
df.head()
Then I extract my features (and convert it into ndarray) and my labels :
df = df[["Condition","Rain","MaxTemp","MinTemp","AvgWind","AvgHumidity","AvgPressure"]]
df_features = df.copy()
df_labels = df_features.pop('Condition')
df_features = np.array(df_features)
df_features
Then I want to write my model :
model = tf.keras.Sequential([
tf.keras.layers.Dense(units=64, input_shape=(6,)),
tf.keras.layers.Dense(units=5, activation='softmax')
])
model.compile(optimizer=tf.keras.optimizers.Adam(lr=0.01),
loss='categorical_crossentropy')
model.fit(df_features,df_labels,epochs=30)
When I want to fit it I got this error :
ValueError: Shapes (None, 1) and (None, 5) are incompatible
I don't know how to choose the right input_shape or how to reshape my dataset...
If anyone has a hint I would glad to listen it !
And if you have some recommandations to improve or optimize my model that would be cool if you tell me it !
Thanks in advance !
Regards,
Baptiste ZLOCH
question from:
https://stackoverflow.com/questions/65887701/how-to-choose-an-input-shape-in-tensorflow