<jupyter_start><jupyter_text>data-hub:*   [Website](https://data-hub.ir/)*   [Youtube](https://www.youtube.com/channel/UCrBcbQWcD0ortWqHAlP94ug)*   [Github](https://github.com/datahub-ir)*   Telegram Channel: @**data_hub_ir***   Instagram Page: @**data_hub_ir***   Telegram Group:    @**data_jobs**<jupyter_code>import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
df = pd.read_csv('diabetes.csv')
df.shape<jupyter_output><empty_output><jupyter_text>تعداد داده ها کافی است؟<jupyter_code>df.tail()
df.describe()
zero_not_accepted = ['Glucose', 'BloodPressure', 'SkinThickness', 'BMI', 'Insulin']
for column in zero_not_accepted:
    df[column] = df[column].replace(0, np.NaN)
    mean = int(df[column].mean(skipna=True))
    df[column] = df[column].replace(np.NaN, mean)
X = df.drop(axis=1, columns=['Outcome'])
y = df['Outcome']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0, test_size=0.2)
X_train = StandardScaler().fit_transform(X_train)
X_test = StandardScaler().fit_transform(X_test)<jupyter_output><empty_output><jupyter_text>KNN<jupyter_code>knn = KNeighborsClassifier(n_neighbors=11)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
print(accuracy_score(y_test, y_pred))
from sklearn.metrics import classification_report

print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.84      0.89      0.86       107
           1       0.71      0.62      0.66        47

    accuracy                           0.81       154
   macro avg       0.77      0.75      0.76       154
weighted avg       0.80      0.81      0.80       154<jupyter_text>SVM<jupyter_code>from sklearn.svm import SVC
svc = SVC(kernel='linear')
svc.fit(X_train, y_train)
y_pred = svc.predict(X_test)
print(f'accuracy score: {accuracy_score(y_test, y_pred)}')
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.84      0.91      0.87       107
           1       0.74      0.60      0.66        47

    accuracy                           0.81       154
   macro avg       0.79      0.75      0.76       154
weighted avg       0.81      0.81      0.81       154<jupyter_text>Decision Tree<jupyter_code>from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier(max_depth=2)
dt.fit(X_train, y_train)
y_pred = dt.predict(X_test)
print(f'accuracy score: {accuracy_score(y_test, y_pred)}')
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.81      0.87      0.84       107
           1       0.64      0.53      0.58        47

    accuracy                           0.77       154
   macro avg       0.72      0.70      0.71       154
weighted avg       0.76      0.77      0.76       154<jupyter_text>Naive Bayes<jupyter_code>from sklearn.naive_bayes import GaussianNB
nb = GaussianNB()
nb.fit(X_train, y_train)
y_pred = nb.predict(X_test)
print(f'accuracy score: {accuracy_score(y_test, y_pred)}')
print(classification_report(y_test, y_pred))
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, y_pred)
cmtx = pd.DataFrame(
    confusion_matrix(y_test, y_pred, labels=[1, 0]), 
    index=['true:yes', 'true:no'], 
    columns=['pred:yes', 'pred:no']
)
print(cmtx)
from sklearn.metrics import f1_score
f1_score(y_test, y_pred)
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.85      0.84      0.85       107
           1       0.65      0.66      0.65        47

    accuracy                           0.79       154
   macro avg       0.75      0.75      0.75       154
weighted avg       0.79      0.79      0.79       154<jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
lreg = LogisticRegression(random_state=0).fit(X_train, y_train)
y_pred = lreg.predict(X_test)
print(f'accuracy score: {accuracy_score(y_test, y_pred)}')
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.84      0.91      0.87       107
           1       0.74      0.62      0.67        47

    accuracy                           0.82       154
   macro avg       0.79      0.76      0.77       154
weighted avg       0.81      0.82      0.81       154
{'fraction_non_alphanumeric': 0.1023725834797891, 'fraction_numerical': 0.06502636203866433, 'mean_word_length': 2.513117283950617, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '159421', 'license': 'Apache-2.0', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1631, 'n_words': 319, 'path': 'machine learning/codes/04-Classification/Classification.ipynb', 'repo_name': 'mokarramis/courses', 'size': '4552'}