<jupyter_start><jupyter_text>We use the following representation to collect the datasetage - agebp - blood pressuresg - specific gravityal - albuminsu - sugarrbc - red blood cellspc - pus cellpcc - pus cell clumpsba - bacteriabgr - blood glucose randombu - blood ureasc - serum creatininesod - sodiumpot - potassiumhemo - hemoglobinpcv - packed cell volumewc - white blood cell countrc - red blood cell counthtn - hypertensiondm - diabetes mellituscad - coronary artery diseaseappet - appetitepe - pedal edemaane - anemiaclass - class<jupyter_code>#shape of data
data.shape
data.head()
#list of column name
data_column = ['sg', 'al' , 'sc' , 'hemo' , 'pcv' , 'wc' , 'rc' , 'htn' , 'classification']

#taking only features present in data_colimn
df = data.drop([column for column in data.columns if not column in data_column] , axis=1)
    
df.head()
#calculating nan values
df.isna().sum()

#removing nan values
df = df.dropna(axis=0)
#df.isna().sum()
#trsnform non numeric data
for column in df.columns:
    if df[column].dtype == np.number:
        continue
    df[column] = LabelEncoder().fit_transform(df[column])
df.head()
#splitting the data foe testing and training
x = df.drop(['classification'] ,axis= 1)
y = df['classification']
#scaling
#using min-max-scaler this converts the data in to 0 to 1
x_scaler = MinMaxScaler()
x_scaler.fit(x)   #fit the data for the x dataframe
column_name = x.columns #stores the columns name
x[column_name] = x_scaler.transform(x) #will transform the x dataform across the columns
#splitting the data in train and test set
x_train  ,x_test,y_train ,y_test = train_test_split(x , y ,test_size=0.2 ,shuffle=True )
#building the model
#Sequential groups a linear stack of layers into a tf.keras.Model.
#Sequential provides training and inference features on this model.
#Dense layer is the regular deeply connected neural network layer. It is most common and frequently used layer
#Initializers define the way to set the initial random weights of Keras layers.

model = Sequential()
model.add(Dense(256 ,input_dim=len(x.columns), kernel_initializer = k.initializers.random_normal(seed =13), activation = 'relu'))
model.add(Dense(1,activation= 'hard_sigmoid'))
#comppile the model
#loss function are of mant types
#for more info :- https://data-flair.training/blogs/compile-evaluate-predict-model-in-keras/

model.compile(loss= 'binary_crossentropy' , optimizer = 'adam' , metrics=['accuracy'])
#train the model
training = model.fit(x_train,y_train , epochs=2000 ,batch_size = x_train.shape[0])
#saving the model
model.save('chronic_kidney_disease.model')
#visualizing the model in loss and accuracy
plt.plot(training.history['accuracy'])
plt.plot(training.history['loss'])
plt.title('MODEL ACCURACY AND LOSS')
plt.xlabel('EPOCH')
plt.ylabel('ACCURACY AND LOSS')
plt.show()
print(f'training data shape :{x_train.shape}')
print(f'training data shape :{x_test.shape}')
pred = model.predict(x_test)
pred = [1 if y>0.5 else 0 for y in pred]
pred
y_test = [i for i in y_test]
print(f'ACTUAL VALUES: {y_test}')
print(f'PREDICTED VALUE: {pred}')<jupyter_output>ACTUAL VALUES: [0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]
PREDICTED VALUE: [0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]
{'fraction_non_alphanumeric': 0.13159437280187572, 'fraction_numerical': 0.03458382180539273, 'mean_word_length': 4.650662251655629, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '410844', 'license': 'MIT', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1205, 'n_words': 429, 'path': 'kidnry_disease_prediction.ipynb', 'repo_name': 'Hemant2801/chronic_kidney_disease_detection', 'size': '3412'}