<jupyter_start><jupyter_text>Contents1&nbsp;&nbsp;TODO:2&nbsp;&nbsp;main()3&nbsp;&nbsp;post-main()4&nbsp;&nbsp;ML Stuff5&nbsp;&nbsp;References &amp; Further Reading:<jupyter_code># import PyTorch
import torch

# standard DS stack
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import pandas as pd
# embed static images in the ipynb
%matplotlib inline 

# neural network package
import torch.nn as nn 
import torch.nn.functional as F

from sklearn import linear_model
import sklearn.preprocessing
import warnings
warnings.filterwarnings('ignore')

# !pip install statsmodels
import statsmodels.api as sm

import os
import time
from IPython.display import clear_output
import preprocessing
import ml_models
import neural_networks<jupyter_output><empty_output><jupyter_text>- NN paper:  - SNPs (number of features) - between 350 and 20,000  - sample size (number of mice) - between 10,000 and 65,000   TODO:1. **Combined dataset**    - [x] Compare the SNP names from the Charles and <NAME> to find out how much they overlap.  - [x] Create a combined dataset for the overlapping SNPs in data/both/.   - [ ] Save the target matrix for the combined dataset as "targets.csv"   - [ ] (optional) Check the coefficient distribution for the combined dataset, i.e. are the top 100 coefs from "C" in the top 200-1000 for "both"?1. **GANs setup**  - Train your GANs on the top 100.1. **NNs**  - [x] Implement dataloader.  - [x] Implement MLP architecture.  - [x] Implement training1. **Evaluate Models**  - [ ] Evaluate each model on without added samples  - [ ] Evaluate each model with added samples---<jupyter_code>%%time
def play():
    for batch in pd.read_csv("data/X.csv", chunksize=4):
        X = batch
        break

    
    # TODO: select the best k features and keep that X_r
    # TODO: Load Y
    # TODO: Train predictive models on X_r
    # TODO: Evaluate models
    # TODO: Add on synthetic samples
    # TODO: train, then evaluate

    return X
play()<jupyter_output>Wall time: 1.33 s<jupyter_text>--- ---  post-`main()`<jupyter_code># Perform the analysis with SNPs selected from SelectKBest.

%time 
from sklearn.feature_selection import SelectKBest, chi2
selectk = SelectKBest(chi2, k=100)

X_dummy = selectk.fit_transform(X_r, Y)
X_dummy.shape, selectk.scores_
torch.topk(torch.Tensor(selectk.scores_), 100)
torch.topk(torch.Tensor(chi2_stats), 100)
SNP_names[np.array(torch.topk(torch.Tensor(chi2_stats), 100)[1])]
X_dummy
chi2_stats, p_vals = chi2(X_r, Y)
chi2_stats, p_vals
X_r.values[:, np.array(torch.topk(torch.Tensor(chi2_stats), 100)[1])]
X_dummy<jupyter_output><empty_output><jupyter_text>ML Stuff<jupyter_code>from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score

def mlmodel(X, Y):
    X_train, X_test, Y_train, Y_test = train_test_split(
        X.astype(float), Y, test_size=0.3, random_state=7)
    model = SGDClassifier(loss='hinge')
    # model = RandomForestClassifier()
    model.fit(X_train, Y_train)
    Y_pred = model.predict(X_test)
    
    kfold = KFold(n_splits=15)
    cv_results = cross_val_score(model, X_train, Y_train, cv=kfold, scoring='accuracy')
    accuracy = metrics.accuracy_score(Y_test, Y_pred)
    print(f"Accuracy: {cv_results.mean():.5f} ({cv_results.std():.5f})\n"
          + f"\nConfusion matrix:\n{confusion_matrix(Y_test, Y_pred)}\n"
          + f"\nClassification report:\n{classification_report(Y_test, Y_pred)}")
    
    fig, ax = plt.subplots(1, 2, figsize=(14, 2*9))
    ax[0].hist(Y_pred.astype(int), color='#1f77b4', label="Y_pred")
    ax[1].hist(Y_test.astype(int), color='cyan', label="True")
    
    for a in ax:
        a.set(xlabel="Phenotype (Y)")
        a.legend()
    plt.show()
    
mlmodel(X_dummy, Y)<jupyter_output>Accuracy: 0.44697 (0.07058)

Confusion matrix:
[[144  54  19]
 [100  95  12]
 [ 40  44  26]]

Classification report:
              precision    recall  f1-score   support

           0       0.51      0.66      0.57       217
           1       0.49      0.46      0.47       207
           2       0.46      0.24      0.31       110

    accuracy                           0.50       534
   macro avg       0.49      0.45      0.45       534
weighted avg       0.49      0.50      0.48       534
{'fraction_non_alphanumeric': 0.1075600617147895, 'fraction_numerical': 0.04187789288075821, 'mean_word_length': 3.47534516765286, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '412086', 'license': 'MIT', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1549, 'n_words': 426, 'path': 'notebooks/Sandbox.ipynb', 'repo_name': 'Unique-Divine/GANs-for-Genomics', 'size': '4544'}