Closed Vyankatesh-3006 closed 3 weeks ago
Let me integrate Cnn Algo
`# Integrating and save model(Cnn Algo)
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Conv2D, Flatten, MaxPooling2D from tensorflow.keras.utils import to_categorical from sklearn.model_selection import train_test_split from sklearn.preprocessing import MinMaxScaler import pandas as pd import numpy as np
dataset = pd.read_csv('diabetes.csv')
dataset[["Glucose", "BloodPressure", "SkinThickness", "Insulin", "BMI"]] = dataset[["Glucose", "BloodPressure", "SkinThickness", "Insulin", "BMI"]].replace(0, np.NaN) dataset["Glucose"].fillna(dataset["Glucose"].mean(), inplace=True) dataset["BloodPressure"].fillna(dataset["BloodPressure"].mean(), inplace=True) dataset["SkinThickness"].fillna(dataset["SkinThickness"].mean(), inplace=True) dataset["Insulin"].fillna(dataset["Insulin"].mean(), inplace=True) dataset["BMI"].fillna(dataset["BMI"].mean(), inplace=True)
X = dataset.iloc[:, :-1].values # all columns except the last one (Outcome) Y = dataset.iloc[:, -1].values # the last column (Outcome)
X = X.reshape(X.shape[0], X.shape[1], 1, 1)
sc = MinMaxScaler() X = sc.fit_transform(X.reshape(X.shape[0], -1)).reshape(X.shape[0], 8, 1, 1)
Y = to_categorical(Y)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42, stratify=dataset['Outcome']) model = Sequential() model.add(Conv2D(32, kernel_size=(2, 1), activation='relu', input_shape=(8, 1, 1))) model.add(MaxPooling2D(pool_size=(2, 1))) model.add(Conv2D(64, kernel_size=(2, 1), activation='relu')) model.add(Flatten()) model.add(Dense(128, activation='relu')) model.add(Dense(2, activation='softmax')) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) model.fit(X_train, Y_train, epochs=50, batch_size=10, validation_data=(X_test, Y_test)) loss, accuracy = model.evaluate(X_test, Y_test) print(f"Test Accuracy: {accuracy * 100:.2f}%") import pickle with open('model_cnn.pkl', 'wb') as file: pickle.dump(model, file) `
Make Changes in diabetes.ipynb
https://github.com/YashPaithankar/Diabetes-prediction-using-cnn
Contributors please integrate Convolutional Neural Network Algorithm For Better Accuracy.