I am currently working on a project where I have genetic data for patients classified into three different groups. Specifically, I have information on 26 SNPs for each patient. I have recorded each allele using letters. I am trying to decide on the best approach to analyze this data and would appreciate any guidance or suggestions. Firstly, I need help formatting the SNP information for analysis. I have recorded each allele using a comma-separated format (e.g., "A,G"). However, other encoding methods may be more appropriate for analyzing SNP data. Could someone please suggest a suitable encoding method for my data? Additionally, I am interested in performing machine learning and cluster analysis on this dataset to investigate the relationship between genotype and patient group. Please recommend any specific algorithms or packages that may be useful for this type of analysis in either Python or R. Thank you in advance for your help and guidance.

  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Mar 27, 2023 at 11:18
  • 2
    $\begingroup$ Please describe the input, output and type of ML algorithm you see yourself using for this exercise. From your current text, it looks like machine learning is an appealing concept that you'd like to use in your endeavor, but it doesn't look like you have a concrete idea of what you'd like the machine to learn. $\endgroup$
    – Ram RS
    Mar 27, 2023 at 15:33
  • $\begingroup$ The input would be SNPs information, and the output would be the stage of NAFLD. Since combining multiple SNPs can help predict the outcome, I am still determining how to analyze these combined correlations. If you have any ideas of statistical analysis I should research, it would greatly help. About the ML algorithm to use, I would appreciate any recommendations. I could use any supervised ML algorithm but would not know how to find the best-suited one. $\endgroup$ Mar 28, 2023 at 17:48

1 Answer 1


Overview In the first instance unsupervised learning is needed - namely PCA - and strongly recommended to identify a training target. The point of this analysis is the resulting clusters of different 'patients' (?).

How to do it? The first part of the analysis is to perform one-hot-key coding.

import pandas as pd
df = pd.read_csv({'A':['A', 'G', 'C'], 'B':['T', 'A', 'G']})
one_hot_encode = pd.get_dummies(df, columns = ['A', 'B'])

This converts A, G, C, T to numerical values and then gets passed to unsupervised learning.

Supervised learning Moving into supervised ML is not trivial, even with a suitable 'target', unless a simple algorithm such as naive Bayes is used. First I'd do the PCA analysis. ...

Edit the training target could simply be the three patient groups.

  • 1
    $\begingroup$ Thank you for suggesting the one-hot encoding. It has allowed me to perform multiple analyses of the data. As you have said, the training target would be these three patient groups, though I would first like to complete some statistical analysis. What I truly wanted with this statistical analysis was to find a strong enough correlation between the genetic factors (alone or combined) and the stage of the disease (the three groups) to justify the training of the machine learning model. Still, I need help finding how I can search for this combined correlation. $\endgroup$ Mar 28, 2023 at 17:58
  • $\begingroup$ @IsmaelPrieto Your welcome, although upvotes are much preferred. Firstly bug corrected in the one-hot-key code. Supervised ML classification will identify the genetic factors and assign weights to them. The PCA will assess whether a combined analysis is useful in the ML analysis. $\endgroup$
    – M__
    Mar 28, 2023 at 18:11
  • 1
    $\begingroup$ I am sorry, I cannot upvote until 15 reputation. I can, though, accept your answer; that may help. $\endgroup$ Mar 28, 2023 at 18:36
  • $\begingroup$ Thanks @IsmaelPrieto the next question you ask that restriction (20 rep) will (likely) be removed. Basically, in modern ML what you want can singly be done via ML (it's called feature selection/importance). A lot depends on whether you are a pure analyst or you're producing your own data set and analysing that. For pure analytics (its published/public data), the bar is much higher. In your case there will be much more 'leeway'. $\endgroup$
    – M__
    Mar 28, 2023 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.