<jupyter_start><jupyter_text>Missing Values & Duplicates<jupyter_code>data.isnull().sum()
data.duplicated().sum()
data[["age","height","weight","ap_hi","ap_lo"]].boxplot()<jupyter_output><empty_output><jupyter_text>Some Feature Engineering<jupyter_code>data["age"]=(data["age"]/365).values.astype(int)
data["bmi"]=data["weight"]/((data["height"]/100)**2)
data.head()
data.drop(["height","weight"],axis=1,inplace=True)
data.head()
data[["age","ap_hi","ap_lo","bmi"]].boxplot()<jupyter_output><empty_output><jupyter_text>Outlier Handling<jupyter_code>data_num=data[["age","ap_hi","ap_lo","bmi"]]
Q1 = data_num.quantile(0.25)
Q3 = data_num.quantile(0.75)
IQR = Q3 - Q1
print(IQR)
out_rows=((data_num < (Q1 - 1.5 * IQR)) |(data_num > (Q3 + 1.5 * IQR))).any(axis=1) 
out_rows
data=data[~out_rows]
data.head()
data[["age","ap_hi","ap_lo","bmi"]].boxplot()<jupyter_output><empty_output><jupyter_text>Descriptive Analysis<jupyter_code>data[["age","ap_hi","ap_lo","bmi"]].describe()
data["cardio"].value_counts()
sns.countplot(data["cardio"])
plt.show()
plt.figure(figsize=(12,7))
sns.countplot(x="age",hue="cardio",data=data)
plt.show()
sns.boxplot(x="cardio",y="bmi",data=data)
plt.show()
sns.heatmap(data[["age","ap_hi","ap_lo","bmi"]].corr(),annot=True,vmax=1,vmin=-1)
plt.show()
sns.pairplot(data[["age","ap_hi","ap_lo","bmi"]])
plt.show()
df=data[["age","ap_hi","ap_lo","bmi"]]
df["cardio"]=["Yes" if m==1 else "No" for m in data["cardio"]]
df.head()
sns.pairplot(df,hue="cardio")
plt.show()<jupyter_output><empty_output><jupyter_text>Machine Learning<jupyter_code>data.head()
data.drop("id",axis=1,inplace=True)
data=data.reindex(columns=["age","ap_hi","ap_lo","bmi","gender","cholesterol","gluc","smoke","alco","active","cardio"])
data.head()
data["gender"].value_counts()
data["cholesterol"].value_counts()
data["gluc"].value_counts()
data["smoke"].value_counts()
data["alco"].value_counts()
data["active"].value_counts()
data["cardio"].value_counts()<jupyter_output><empty_output><jupyter_text>Label Encoding<jupyter_code>le=LabelEncoder()
le
data["gender"]=le.fit_transform(data["gender"])
data.head()<jupyter_output><empty_output><jupyter_text>One Hot Encoding<jupyter_code>ohe=OneHotEncoder()
ohe
ohot_encoded1=ohe.fit_transform(data["cholesterol"].values.reshape(len(data["cholesterol"].values),1)).toarray()
ohot_encoded1=ohot_encoded1[:,1:].astype(int)
df_ohot1=pd.DataFrame(ohot_encoded1,columns=["Above Nor Chol","Well Above Nor Chol"])
df_ohot1.head()
ohot_encoded2=ohe.fit_transform(data["gluc"].values.reshape(len(data["gluc"].values),1)).toarray()
ohot_encoded2=ohot_encoded2[:,1:].astype(int)
df_ohot2=pd.DataFrame(ohot_encoded2,columns=["Above Nor Gluc","Well Above Nor Gluc"])
df_ohot2.head()
data.reset_index(inplace=True)
data.drop("index",axis=1,inplace=True)
x=pd.concat([data.iloc[:,:10],df_ohot1,df_ohot2],axis=1)
x.head()
x.drop(["cholesterol","gluc"],axis=1,inplace=True)
x=x.values
y=data.iloc[:,10].values<jupyter_output><empty_output><jupyter_text>Standardizing Neumerical Features<jupyter_code>sc=StandardScaler()
x[:,:4]=sc.fit_transform(x[:,:4])<jupyter_output><empty_output><jupyter_text>Train Test Splitting<jupyter_code>x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)<jupyter_output><empty_output><jupyter_text>Modeling<jupyter_code>model1=KNeighborsClassifier(n_neighbors=50)
model2=LogisticRegression()
model3=SVC(kernel="rbf",C=1)
model4=RandomForestClassifier(n_estimators=500)

T1=("knn",model1)
T2=("lgr",model2)
T3=("svm",model3)
T4=("rf",model4)

model=VotingClassifier(estimators=[T1,T2,T3,T4],voting="hard")
model.fit(x_train,y_train)
y_pred=model.predict(x_test)
accuracy_score(y_test,y_pred)
confusion_matrix(y_test,y_pred)
print(classification_report(y_test,y_pred))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21695364238410597, 'fraction_numerical': 0.022251655629139073, 'mean_word_length': 16.24200913242009, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '559293', 'license': 'BSL-1.0', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1598, 'n_words': 120, 'path': 'AIML - Project 06.ipynb', 'repo_name': 'ranmuni345/My-Python-Project', 'size': '3775'}