ValueError Traceback (most recent call last)
Cell In[14], line 6
4 for i, j in loo.split(X):
5 X_train, X_test = X.iloc[i,:], X.iloc[j,:]
----> 6 X_train=X_train.values.reshape(-1,224,224,1)
7 X_test=X_test.values.reshape(-1,224,224,1)
8 y_train, y_test = y[i], y[j]
I am getting error when i am trying to resize X value.
import numpy as np
import pandas as pd
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
from sklearn.model_selection import LeaveOneOut
from sklearn.preprocessing import MinMaxScaler
dataset=pd.read_csv(“C:/Users/User/Documents/Data/image.csv”)
image_paths = dataset[‘image_path’].values
cholesterol_levels = dataset[‘cholesterol’].values
loo = LeaveOneOut()
Define the CNN model
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation=‘relu’, input_shape=(224, 224, 1
)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, kernel_size=(3, 3), activation=‘relu’))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(128, activation=‘relu’))
model.add(Dense(1))
Compile the model
model.compile(loss=‘mean_squared_error’, optimizer=‘adam’)
X = dataset.iloc[:, :-1]
y = dataset.iloc[:, -1]
Perform LOOCV
predictions =
for i, j in loo.split(X):
X_train, X_test = X.iloc[i,:], X.iloc[j,:]
X_train=X_train.values.reshape(-1,224,224,1)
X_test=X_test.values.reshape(-1,224,224,1)
y_train, y_test = y[i], y[j]
model.fit(X_train, y_train, batch_size=32, epochs=10, verbose=0)
prediction = model.predict(X_test)
predictions.append(prediction)
Evaluate the predictions
predictions = np.array(predictions).flatten()
mse = np.mean((predictions - y) ** 2)
mae = np.mean(np.abs(predictions - y))
r_squared = np.corrcoef(predictions, y)[0, 1] ** 2
print(‘Mean Squared Error (MSE):’, mse)
print(‘Mean Absolute Error (MAE):’, mae)
print(‘R-squared:’, r_squared)
please suggest me
Thanks & Regards