<jupyter_start><jupyter_text>AQ10 Quotient<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from google.colab import drive
drive.mount('/drive')
##preparing the data
df_adol = pd.read_csv("/drive/My Drive/Colab Notebooks/Autism-Adol-Data.csv",na_values="?")
df_child = pd.read_csv("/drive/My Drive/Colab Notebooks/Autism-Child-Data.csv",na_values="?")
df_adol.head()
df_child.head()
df_adol.info()
df_child.info()
##Calculate the distribution
autism_adol = (len(df_adol[df_adol['Class/ASD']=='YES'])/(len(df_adol)))
autism_child = (len(df_child[df_child['Class/ASD']=='YES'])/(len(df_child)))
print("Adol: ",autism_adol)
print("Child: ",autism_child)
##Joining the data
df_full = pd.concat([df_child,df_adol],axis=0)
df_full.head()
##missing value seems is occured randomly in ethnicty and relation, we will dropped row with missing value
df_full = df_full.dropna()
df_full.info()
##dropping age_desc and seperate features and target
df_features = df_full.drop(columns=["age_desc","Class/ASD"],axis=1)
df_target = df_full["Class/ASD"]
df_features.head()
##Scaling Age and Result
from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler()
numerical = ['age', 'result']

features_minmax_transform = pd.DataFrame(data = df_features)
features_minmax_transform[numerical] = scaler.fit_transform(df_features[numerical])
features_minmax_transform.head()
## Encoding
#One-hot encode the 'features_minmax_transform' data using pandas.get_dummies()
features_final = pd.get_dummies(features_minmax_transform)
#encode target
df_target = df_target.apply(lambda x: 1 if x=='YES' else 0)
#result
features_final.head()
#Splitting
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(features_final, df_target, train_size=0.80, random_state=1)
# Show the results of the split
print("Training set has {} samples.".format(X_train.shape[0]))
print("Testing set has {} samples.".format(X_test.shape[0]))<jupyter_output>Training set has 276 samples.
Testing set has 70 samples.<jupyter_text>Modelling 1<jupyter_code>## SVM Modelling

from sklearn.metrics import fbeta_score
from sklearn.metrics import accuracy_score
from sklearn.metrics import make_scorer
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
def f_beta_score(y_true, y_predict):
    return fbeta_score(y_true, y_predict, beta = 0.5)
clf = SVC(random_state=1)
parameters = {'C':range(1,6),'kernel':['linear','poly','rbf','sigmoid'],'degree':range(1,6)}
# Make an fbeta_score scoring object using make_scorer()
scorer = make_scorer(f_beta_score)
# Perform grid search on the classifier using 'scorer' as the scoring method using GridSearchCV()
grid_obj = GridSearchCV(estimator = clf, param_grid = parameters, scoring = scorer)
# Fit the grid search object to the training data and find the optimal parameters using fit()
grid_fit = grid_obj.fit(X_train, y_train)
# Get the estimator
best_clf = grid_fit.best_estimator_
# Make predictions using the unoptimized and model
predictions = (clf.fit(X_train, y_train)).predict(X_test)
best_predictions = best_clf.predict(X_test)
# Report the before-and-afterscores
print("Unoptimized model\n------")
print("Accuracy score on testing data: {:.4f}".format(accuracy_score(y_test, predictions)))
print("F-score on testing data: {:.4f}".format(fbeta_score(y_test, predictions, beta = 0.5)))
print("\nOptimized Model\n------")
print("Final accuracy score on the testing data: {:.4f}".format(accuracy_score(y_test, best_predictions)))
print("Final F-score on the testing data: {:.4f}".format(fbeta_score(y_test, best_predictions, beta = 0.5)))
print("Final Parameter: ",best_clf)

## Full Model
clf_aq = SVC(C=2,kernel='linear')
clf_aq.fit(X_train, y_train)
prediction = clf_aq.predict(X_test)
print("Accuracy score on testing data: {:.4f}".format(accuracy_score(y_test, prediction)))
print("F-score on testing data: {:.4f}".format(fbeta_score(y_test, prediction, beta = 0.5)))
## Preparing for testing
input_aq = X_test.iloc[0:1]
input_aq<jupyter_output><empty_output><jupyter_text>BAPQ Quotient<jupyter_code>df_quotient = pd.read_csv("/drive/My Drive/Colab Notebooks/QUOTIENT_RAW.csv")<jupyter_output><empty_output><jupyter_text>Processing DataBased on this paper (https://www.researchgate.net/publication/6651835_The_Broad_Autism_Phenotype_Questionnaire), there are some questions that must be reversed, we will prepared it first<jupyter_code>cols_to_reversed = ['a1','a3','a4','a5','a7','a8','a10','a12',
                    'pl3','pl9','pl12','r1','r5','r6','r10']
for cols in cols_to_reversed:
  df_quotient[cols] = df_quotient[cols].apply(lambda x: 1 if x==6 else 2 if x==5 else 3 if x==4
                                     else 4 if x==3 else 5 if x==2 else 6)<jupyter_output><empty_output><jupyter_text>Personality Trait Weighting<jupyter_code>## calculate the scoring personality
df_quotient['Aloof Score'] = df_quotient[['a1','a2','a3','a4','a5','a6','a7','a8','a9','a10','a11','a12']].mean(axis=1)
df_quotient['Pragmatic Score'] = df_quotient[['pl1','pl2','pl3','pl4','pl5','pl6','pl7','pl8','pl9','pl10','pl11','pl12']].mean(axis=1)
df_quotient['Rigid Score'] = df_quotient[['r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12']].mean(axis=1)
#making the label
score = np.array(df_quotient[['Aloof Score','Pragmatic Score','Rigid Score']])
label = []
for i in range(len(score)):
  result = score[i].argmax(axis=0)
  label.append(result)
df_quotient['Label'] = pd.DataFrame(label)
df_quotient.head()
## encode gender
df_quotient["Geschlecht"].value_counts()
df_quotient_filtered = df_quotient[df_quotient['Geschlecht']!=3]
df_quotient_filtered = df_quotient_filtered.reset_index(drop=True)
df_quotient_filtered['Gender'] = df_quotient_filtered['Geschlecht'].apply(lambda x: "Male" if x==1 else "Female")
#seperating features and label
df_features = df_quotient_filtered.drop(columns=['Unnamed: 0','Geschlecht','Aloof Score',	'Pragmatic Score',	'Rigid Score', 'Label'],axis=1)
df_label = df_quotient_filtered['Label']
##Scaling Answer
from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler()
numerical = ['a1','a2','a3','a4','a5','a6','a7','a8','a9','a10','a11','a12',
             'pl1','pl2','pl3','pl4','pl5','pl6','pl7','pl8','pl9','pl10','pl11','pl12',
             'r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12']

features_minmax_transform = pd.DataFrame(data = df_features)
features_minmax_transform[numerical] = scaler.fit_transform(df_features[numerical])
features_minmax_transform.head()
# encode Gender
features_final = pd.get_dummies(features_minmax_transform)
features_final.head()<jupyter_output><empty_output><jupyter_text>Modelling 2<jupyter_code>#Splitting
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(features_final, df_label, train_size=0.80, random_state=1)
# Show the results of the split
print("Training set has {} samples.".format(X_train.shape[0]))
print("Testing set has {} samples.".format(X_test.shape[0]))
clf1 = SVC(random_state=1,decision_function_shape='ovo')
parameters = {'C':range(1,6),'kernel':['linear','poly','rbf','sigmoid'],'degree':range(1,6)}
# Make an fbeta_score scoring object using make_scorer()
#scorer = make_scorer(f_beta_score)
# Perform grid search on the classifier using 'scorer' as the scoring method using GridSearchCV()
grid_obj = GridSearchCV(estimator = clf, param_grid = parameters)
# Fit the grid search object to the training data and find the optimal parameters using fit()
grid_fit = grid_obj.fit(X_train, y_train)
# Get the estimator
best_clf = grid_fit.best_estimator_
# Make predictions using the unoptimized and model
predictions = (clf1.fit(X_train, y_train)).predict(X_test)
best_predictions = best_clf.predict(X_test)
# Report the before-and-afterscores
print("Unoptimized model\n------")
print("Accuracy score on testing data: {:.4f}".format(accuracy_score(y_test, predictions)))
print("\nOptimized Model\n------")
print("Final accuracy score on the testing data: {:.4f}".format(accuracy_score(y_test, best_predictions)))
print("Final Parameter: ",best_clf)
clf_bapq = SVC(random_state=1,decision_function_shape='ovo',C=3,kernel='poly',degree=1)
clf_bapq.fit(X_train, y_train)
predictions = clf_bapq.predict(X_test)
predictions
## preparing for the test
input_bapq = X_test.iloc[0:1]
input_bapq<jupyter_output><empty_output><jupyter_text>Combining Result Based on several research, we conclude several topics for each kind of autism<jupyter_code>topic_aloof = ['Music','Design','Marketing']
topic_prag = ['Lifestyle','Business']
topic_rigid = ['Photography','Tech']
autism_level = clf_aq.predict(input_aq)
personality_level = clf_bapq.predict(input_bapq) 
autism_level = autims_level[0]
personality_level = personality_level[0]
if autism_level == 0 :
  print("Autism Tendency Is Not Detected")
else:
  print("Autism Tendecy Is Detected")

if personality_level == 0:
  print("Personality Trait: Aloof")
  print("We suggest to search the courses with the following topics:")
  for topics in topic_aloof:
    print(topics)
elif personality_level == 0:
  print("Personality Trait: Pragmatic")
  print("We suggest to search the courses with the following topics:")
  for topics in topic_prag:
    print(topics)
else:
  print("Personality Trait: Rigid")
  print("We suggest to search the courses with the following topics:")
  for topics in topic_rigid:
    print(topics)<jupyter_output>Autism Tendecy Is Detected
Personality Trait: Rigid
We suggest to search the courses with the following topics:
Photography
Tech
{'fraction_non_alphanumeric': 0.14513440300062513, 'fraction_numerical': 0.020941862888101688, 'mean_word_length': 7.420175438596491, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '134351', 'license': 'MIT', 'n_tokens_mistral': 3514, 'n_tokens_neox': 3368, 'n_words': 726, 'path': 'Autism_and_Personality_Trait_Classification.ipynb', 'repo_name': 'RizkiRachmadi/BuildWithAI', 'size': '9598'}