text_plain_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import MinMaxScaler

from sklearn.preprocessing import OrdinalEncoder

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('/kaggle/input/autism-screening-for-toddlers/Toddler Autism dataset July 2018.csv')

df.shape

df.sample(5)

df = df.rename(columns={'Class/ASD Traits ': 'ASD'})

x = df.drop('Case_No', axis=1)
x = x.drop('Ethnicity', axis=1)
x = x.drop('ASD', axis=1)
y = df['ASD']

obj_cols = x_train.select_dtypes(include='object').columns
obj_cols

float_cols = x_train.select_dtypes(include='int64').columns
float_cols

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
le.fit(y_train)

y_train_processed = le.transform(y_train)
y_test_processed = le.transform(y_test)

from sklearn.preprocessing import OrdinalEncoder
oe = OrdinalEncoder(categories=[x_train[i].unique() for i in obj_cols])
oe.fit(x_train[obj_cols])
x_train_cat_encoded = oe.transform(x_train[obj_cols])
x_test_cat_encoded = oe.transform(x_test[obj_cols])

from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit(x_train[float_cols])
x_train_float_encoded = scaler.transform(x_train[float_cols])
x_test_float_encoded = scaler.transform(x_test[float_cols])

x_train_processed = np.hstack((x_train_cat_encoded, x_train_float_encoded))
x_test_processed = np.hstack((x_test_cat_encoded, x_test_float_encoded))

feature_names = np.concatenate([obj_cols, float_cols])

x_train_final = pd.DataFrame(x_train_processed, columns=feature_names)

from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr.fit(x_train_processed, y_train_processed)
y_pred = lr.predict(x_test_processed)

def pretty_confusion_matrix(y_test, y_pred, labels=['Not_Diagnosed_with_ASD', 'ASD_Diagnosed']):
    cm = confusion_matrix(y_test, y_pred)
    pred_labels = ['Predicted ' + i for i in labels]
    df = pd.DataFrame(cm, columns=pred_labels, index=labels)
    return df

results_plot = pretty_confusion_matrix(y_test_processed, y_pred, ['Not_Diagnosed_with_ASD', 'ASD_Diagnosed'])
results_plot