<jupyter_start><jupyter_text>Classification Here we use the representations created in notebook.2 in the classification<jupyter_code>import sys
sys.path.append('../')
from classifier.classical_classifiers import RFClassifier,SVM
from utility.file_utility import FileUtility<jupyter_output><empty_output><jupyter_text>Example of body-sites classifications<jupyter_code>X=FileUtility.load_sparse_csr('../../MicroPheno_datasets/body-sites/k-mer_representations_labels/6-mers_rate_5000.npz')
Y=FileUtility.load_list('../../MicroPheno_datasets/body-sites/k-mer_representations_labels/labels_phen.txt')


#### Random Forest classifier
MRF = RFClassifier(X, Y)
# results containing the best parameter, confusion metrix, best estimator, results on fold will be stored in this address
MRF.tune_and_eval('../../MicroPheno_datasets/body-sites/classification_results')


#### Support Vector Machine classifier
MSVM = SVM(X, Y)
# results containing the best parameter, confusion metrix, best estimator, results on fold will be stored in this address
MSVM.tune_and_eval('../../MicroPheno_datasets/body-sites/classification_results')<jupyter_output><empty_output><jupyter_text>Confusion matrix<jupyter_code>import matplotlib.pyplot as plt
%pylab inline
%matplotlib inline 
from utility.visualization_utility import create_mat_plot
## load the results
[label_set, conf, best_score_, best_estimator_,cv_results_, best_params_, predictions]=FileUtility.load_obj('../../../git_repos/datasets/results/body-sites/sample-size/6-mers_rate_5000_labels_labels_phen.txt_RF.pickle')
create_mat_plot(conf, ['saliva (o)', 'mid-vagina (u)','a-nares (n)', 'stool (g)', 'p-fornix (u)'], '', 'body-site_confusion', 'Predicted labels' ,'Actual labels', cmap='Purples', filetype='pdf',font_s=8)
[label_set, conf, best_score_, best_estimator_,cv_results_, best_params_]=FileUtility.load_obj('../../datasets/results/eco/classifier/svm_6_restrictedmers_linear.pickle')
label_set=[x.replace('_',' ') for x in label_set]
create_mat_plot(conf, label_set, '', '../../datasets/figures/paper_figures/eco_env_confusion', 'Predicted labels' ,'Actual labels', cmap='Purples', filetype='pdf', rx=80, ry=0, font_s=15)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13466787989080983, 'fraction_numerical': 0.00818926296633303, 'mean_word_length': 7.58984375, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '167933', 'license': 'Apache-2.0', 'n_tokens_mistral': 763, 'n_tokens_neox': 726, 'n_words': 137, 'path': 'notebooks/.ipynb_checkpoints/4. Classification_classical_classifiers-checkpoint.ipynb', 'repo_name': 'ehsanasgari/MicroPheno', 'size': '2198'}