میخام یک فایل زیپ به اسم  ADNI:​
 Copy of WGS_Omni2.5M_20140220.zip
​که omni 2.5 داده های الزایمر می باشد میخام برای پیش بینی الزایمر استفاده کنم . 
فرمت داخلشم 
 WGS_Omni25_BIN_wo_ConsentsIssues.bed/bim/fam 
می باشد .
ورکفلو ام اینه :
# Workflow

[data:image/svg+xml,%3csvg%20width='28'%20height='28'%20viewBox='0%200%2028%2028'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M26.9425%202.94265C27.4632%202.42195%2027.4632%201.57773%2026.9425%201.05703C26.4218%200.536329%2025.5776%200.536329%2025.0569%201.05703L22.5713%203.54256C21.1213%202.59333%2019.5367%202.43378%2018.1753%202.64006C16.5495%202.88638%2015.1127%203.66838%2014.3905%204.39053L12.3905%206.39053C12.1405%206.64058%2012%206.97972%2012%207.33334C12%207.68697%2012.1405%208.0261%2012.3905%208.27615L19.7239%2015.6095C20.2446%2016.1302%2021.0888%2016.1302%2021.6095%2015.6095L23.6095%2013.6095C24.3316%2012.8873%2025.1136%2011.4505%2025.36%209.82475C25.5663%208.46312%2025.4066%206.87827%2024.4571%205.42807L26.9425%202.94265Z'%20fill='%233c4555'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M12.276%2012.9426C12.7967%2012.4219%2012.7967%2011.5777%2012.276%2011.057C11.7553%2010.5363%2010.9111%2010.5363%2010.3904%2011.057L8.66651%2012.7809L8.27615%2012.3905C8.0261%2012.1405%207.68697%2012%207.33334%2012C6.97972%2012%206.64058%2012.1405%206.39053%2012.3905L4.39053%2014.3905C3.66838%2015.1127%202.88638%2016.5495%202.64006%2018.1753C2.43377%2019.5367%202.59333%2021.1214%203.54262%2022.5714L1.05703%2025.057C0.536329%2025.5777%200.536329%2026.4219%201.05703%2026.9426C1.57773%2027.4633%202.42195%2027.4633%202.94265%2026.9426L5.42817%2024.4571C6.87835%2025.4066%208.46315%2025.5663%209.82475%2025.36C11.4505%2025.1136%2012.8873%2024.3316%2013.6095%2023.6095L15.6095%2021.6095C16.1302%2021.0888%2016.1302%2020.2446%2015.6095%2019.7239L15.2188%2019.3332L16.9426%2017.6093C17.4633%2017.0886%2017.4633%2016.2444%2016.9426%2015.7237C16.4219%2015.203%2015.5777%2015.203%2015.057%2015.7237L13.3332%2017.4475L10.5521%2014.6665L12.276%2012.9426Z'%20fill='%23FF7C00'/%3e%3c/svg%3e](data:image/svg+xml,%3csvg%20width='28'%20height='28'%20viewBox='0%200%2028%2028'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M26.9425%202.94265C27.4632%202.42195%2027.4632%201.57773%2026.9425%201.05703C26.4218%200.536329%2025.5776%200.536329%2025.0569%201.05703L22.5713%203.54256C21.1213%202.59333%2019.5367%202.43378%2018.1753%202.64006C16.5495%202.88638%2015.1127%203.66838%2014.3905%204.39053L12.3905%206.39053C12.1405%206.64058%2012%206.97972%2012%207.33334C12%207.68697%2012.1405%208.0261%2012.3905%208.27615L19.7239%2015.6095C20.2446%2016.1302%2021.0888%2016.1302%2021.6095%2015.6095L23.6095%2013.6095C24.3316%2012.8873%2025.1136%2011.4505%2025.36%209.82475C25.5663%208.46312%2025.4066%206.87827%2024.4571%205.42807L26.9425%202.94265Z'%20fill='%233c4555'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M12.276%2012.9426C12.7967%2012.4219%2012.7967%2011.5777%2012.276%2011.057C11.7553%2010.5363%2010.9111%2010.5363%2010.3904%2011.057L8.66651%2012.7809L8.27615%2012.3905C8.0261%2012.1405%207.68697%2012%207.33334%2012C6.97972%2012%206.64058%2012.1405%206.39053%2012.3905L4.39053%2014.3905C3.66838%2015.1127%202.88638%2016.5495%202.64006%2018.1753C2.43377%2019.5367%202.59333%2021.1214%203.54262%2022.5714L1.05703%2025.057C0.536329%2025.5777%200.536329%2026.4219%201.05703%2026.9426C1.57773%2027.4633%202.42195%2027.4633%202.94265%2026.9426L5.42817%2024.4571C6.87835%2025.4066%208.46315%2025.5663%209.82475%2025.36C11.4505%2025.1136%2012.8873%2024.3316%2013.6095%2023.6095L15.6095%2021.6095C16.1302%2021.0888%2016.1302%2020.2446%2015.6095%2019.7239L15.2188%2019.3332L16.9426%2017.6093C17.4633%2017.0886%2017.4633%2016.2444%2016.9426%2015.7237C16.4219%2015.203%2015.5777%2015.203%2015.057%2015.7237L13.3332%2017.4475L10.5521%2014.6665L12.276%2012.9426Z'%20fill='%23FF7C00'/%3e%3c/svg%3e)

[data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='576'%20height='576'%20viewBox='0%200%20576%20576'%20fill='none'%3e%3cpath%20d='M287.5%20229L86%20344.5L287.5%20460L489%20344.5L287.5%20229Z'%20stroke='url(%23paint0_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='round'/%3e%3cpath%20d='M287.5%20116L86%20231.5L287.5%20347L489%20231.5L287.5%20116Z'%20stroke='url(%23paint1_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='round'/%3e%3cpath%20d='M86%20344L288%20229'%20stroke='url(%23paint2_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='bevel'/%3e%3cdefs%3e%3clinearGradient%20id='paint0_linear_102_7'%20x1='60'%20y1='341'%20x2='429.5'%20y2='344'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3clinearGradient%20id='paint1_linear_102_7'%20x1='513.5'%20y1='231'%20x2='143.5'%20y2='231'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3clinearGradient%20id='paint2_linear_102_7'%20x1='60'%20y1='344'%20x2='428.987'%20y2='341.811'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3c/defs%3e%3c/svg%3e](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='576'%20height='576'%20viewBox='0%200%20576%20576'%20fill='none'%3e%3cpath%20d='M287.5%20229L86%20344.5L287.5%20460L489%20344.5L287.5%20229Z'%20stroke='url(%23paint0_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='round'/%3e%3cpath%20d='M287.5%20116L86%20231.5L287.5%20347L489%20231.5L287.5%20116Z'%20stroke='url(%23paint1_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='round'/%3e%3cpath%20d='M86%20344L288%20229'%20stroke='url(%23paint2_linear_102_7)'%20stroke-width='59'%20stroke-linejoin='bevel'/%3e%3cdefs%3e%3clinearGradient%20id='paint0_linear_102_7'%20x1='60'%20y1='341'%20x2='429.5'%20y2='344'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3clinearGradient%20id='paint1_linear_102_7'%20x1='513.5'%20y1='231'%20x2='143.5'%20y2='231'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3clinearGradient%20id='paint2_linear_102_7'%20x1='60'%20y1='344'%20x2='428.987'%20y2='341.811'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20stop-color='%23F9D100'/%3e%3cstop%20offset='1'%20stop-color='%23F97700'/%3e%3c/linearGradient%3e%3c/defs%3e%3c/svg%3e)

**Comprehensive Workflow for Predicting Alzheimer's Disease Using Genomic SNP Data**

---

### **1. Data Acquisition and Preparation**

- **Obtain ADNI Genetic Data:**
    - Download the SNP ADNI Omni 2.5 dataset in PLINK format (.bed, .bim, .fam).
- **Load Data:**
    - Use PLINK to load the data and view basic statistics.
- **Data Alignment:**
    - Align the data with other datasets (if necessary) using SNP positions from the .bim file.

### **2. Quality Control and Preprocessing**

- **Sample and Variant Filtering (PLINK):**
    - **Individuals:** Remove individuals with high missing genotypes (`-mind 0.02`), and check for unexpected gender mismatches.
    - **Variants:** Filter out SNPs with low call rates (`-geno 0.02`), rare allele frequencies (`-maf 0.01`), and those not in Hardy-Weinberg equilibrium (`-hwe 1e-6`).
- **Identity-By-Descent (IBD) Analysis:**
    - Calculate relatedness (`-genome`), and filter out closely related individuals (e.g., IBD > 0.25).
- **Imputation:**
    - Impute missing genotypes using an appropriate reference panel (e.g., 1000 Genomes Project) utilizing software such as IMPUTE2.

### **3. Genomic Analysis and GWAS**

- **Principal Component Analysis (PCA):**
    - Perform PCA (`-pca`) to identify and correct for population stratification. Visualize results to check for potential confounding effects.
- **Conduct GWAS:**
    - Use logistic regression in PLINK for case-control analysis of Alzheimer's disease, including principal components as covariates to account for stratification:
        
        `plink --bfile SNP_QC --logistic --covar PCA_results.eigenvec --covar-number 1-10 --out gwas_results`
        

### **4. Feature Selection**

- **Identify Significant SNPs:**
    - Based on GWAS results, select SNPs that meet specified p-value thresholds (e.g., <0.05).
- **Refine Feature Set:**
    - Use machine learning feature selection methods like Recursive Feature Elimination or LASSO to derive the most informative SNPs that predict Alzheimer's.

### **5. Machine Learning Modeling**

- **Data Splitting:**
    - Split the dataset into training (70%), validation (15%), and test sets (15%).
- **Model Training:**
    - Train multiple models using standard libraries (e.g., scikit-learn in Python):
        - **Support Vector Machine (SVM):** Use with proper kernel functions (e.g., RBF).
        - **Random Forest (RF):** Good for feature importances and handling non-linear relations.
        - **Decision Trees (DT):** For interpretability.
- **Hyperparameter Tuning:**
    - Use techniques like GridSearchCV for optimal parameters.
        
        `from sklearn.model_selection import GridSearchCV`
        
- **Cross-Validation:**
    - Employ k-fold cross-validation (e.g., 10-fold) to ensure the robustness of each model.

### **6. Model Evaluation**

- **Performance Metrics:**
    - Evaluate models using AUC-ROC curves, accuracy, precision, and recall.
    - Compare model performance to establish the best-performing approach for predicting Alzheimer's disease.
- **Feature Importance:**
    - Calculate and visualize feature importances from models like RF using SHAP (SHapley Additive exPlanations) values for interpretability.

### **7. Interpretation and Visualization**

- **Visualize Predictive Modeling Results:**
    - Use plots such as ROC curves, confusion matrices, and Manhattan plots for GWAS results.
- **Interpret Predictions:**
    - Analyze significant SNPs contributing to the model's predictions and understand their biological relevance using tools like BiomaRt or functional annotation tools.

### **8. Reporting and Ethical Considerations**

- **Prepare Comprehensive Report:**
    - Summarize methodology, model results, significant SNPs, and biological interpretations.
- **Consider Ethical Implications:**
    - Ensure ethical considerations in reporting genetic risk information are addressed, maintaining participant confidentiality and data security.

### Conclusion

This workflow provides a comprehensive approach to analyze genomic SNP data for Alzheimer's disease prediction using robust machine learning techniques. Each step emphasizes quality control, model evaluation, and ethical reporting, generating reliable results while considering biological interpretations of the findings.

**Alignment with Your Machine Learning Pipeline**
1. **Problem Definition**
    ◦ **1.1**: Clearly defined as a **classification** problem (predicting Alzheimer's disease presence).
    ◦ **1.2**: Stated goals include identifying genetic predispositions, potentially leading to better understanding, prevention, and intervention strategies for Alzheimer's disease.
    ◦ **1.3**: Identified data needs include SNP genotype data and associated clinical and demographic data (age, sex).
    ◦ **1.4**: Acknowledges ADNI as the data source, discussing the reliability and relevance of this dataset.
    ◦ **1.5**: Data quality evaluation is implied through quality control checks and validation of SNP data.
2. **Data Acquisition & Preparation**
    ◦ **2.1**: Clear methods for data collection from the ADNI database are outlined.
    ◦ **2.2**: Data exploration is included, encompassing descriptive statistics, PCA for stratification analysis, and data visualization methods.
    ◦ **2.2.1 to 2.2.4**: Although not explicitly defined as separate sections, similar aspects of data exploration are addressed (plausible statistics, PCA evaluation, documentation of findings).
3. **Data Preprocessing**
    ◦ **3.1**: Data cleaning steps like handling missing values, outliers, and inconsistencies are detailed in the QC section.
    ◦ **3.2**: Feature engineering is highlighted, including feature transformation (e.g., SNP representation) and selection methods.
4. **Data Splitting**
    ◦ **4.1**: Clearly outlined the need to split the dataset into **training**, **validation**, and **test** sets.
    ◦ **4.2**: Suggested ratios such as 70/15/15 are commented on; you can adjust based on the specific dataset size.
    ◦ **4.3**: Implicitly addresses data leakage by specifying separate validation and test sets for evaluation and tuning.
5. **Problem-Solving Methods**
    ◦ **5.1**: Detailed model selection criteria (SVM, Random Forest, etc.) aligns with your encouragement to consider diverse algorithms.
    ◦ **5.2**: Model training, including cross-validation and hyperparameter tuning, is emphasized to ensure model robustness and avoid overfitting.
    ◦ **5.3**: Evaluation of models using metrics (AUC, accuracy, precision) is integrated, with a recommendation for cross-validation for reliable estimates.
    ◦ **5.4**: Compares model performance across different algorithms to select the best-performing model.
6. **Result Improvement**
    ◦ **6.1**: The workflow promotes iteration (re-evaluating previous phases) to refine the model continuously.
    ◦ **6.2**: Mention of ensemble methods is included as a strategy for potentially enhancing predictive performance.
    ◦ **6.3**: Actively addresses overfitting concerns using regularization techniques and other strategies.
    ◦ **6.4**: Encourages documentation of improvements and iterations made throughout the process.
7. **Deployment and Monitoring**
    ◦ **7.1**: Outlines the importance of deploying the model into a production environment, which is crucial for operationalizing the machine learning pipeline.
    ◦ **7.2**: Discusses performance monitoring post-deployment, emphasizing the need for ongoing evaluation and retraining as necessary.
**Conclusion**
The comprehensive workflow for predicting Alzheimer's disease successfully passes through all sections outlined in your standard machine learning pipeline:
• It provides a clear foundation for understanding the problem, explores data thoroughly, implements meticulous preprocessing, and sets robust structures for model training, evaluation, improvement, and deployment.
• Each phase is logically sequenced, ensuring dependencies are respected and the workflow remains cohesive and actionable.
This alignment ensures that the proposed workflow is both methodologically sound and tailored to the specific context of using genomic data for predicting Alzheimer's disease, while adhering to your established machine learning project framework.

---

---

---

---

---

---

---

---

---

**3. Data Preparation**
• **Install Required Software:**
    ◦ Install [PLINK](https://www.cog-genomics.org/plink/2.0/) for data manipulation and [Python](https://www.python.org/downloads/) with libraries like `pandas`, `scikit-learn`, `numpy`, and `matplotlib`.
    ◦ Use Anaconda for easier package management: [Anaconda Distribution](https://www.anaconda.com/products/distribution).
• ** Load the Data**

`import pandas as pd
import numpy as np

# Assuming the data is in PLINK format, we will load it into a DataFrame
# You may need to convert .bed/.bim/.fam into a combined DataFrame
!plink --bfile dataset_prefix --recode A --out dataset_converted

# Now load the converted .csv file (you need to convert it to CSV format)
data = pd.read_csv('dataset_converted.csv')
print(data.head())`

- • **Objective**: Predict the risk of Alzheimer's disease based on SNP genetic data.
- • **Where to get the data**:
    - ◦ Visit the [ADNI website](http://adni.loni.usc.edu/) and register to access datasets. Download the SNP data files in PLINK format (.bed, .bim, .fam).
- 
- •
    
    **Install Required Software:**
    
    - ◦ Install [PLINK](https://www.cog-genomics.org/plink/2.0/) for data manipulation and [Python](https://www.python.org/downloads/) with libraries like `pandas`, `scikit-learn`, `numpy`, and `matplotlib`.
    - ◦ Use Anaconda for easier package management: [Anaconda Distribution](https://www.anaconda.com/products/distribution).
- 
- 
- •
    - * Load the Data**

---

### **4. Data Exploration**

- **Explore Basic Statistics**:
    
    `# Calculate descriptive statistics
    print(data.describe())
    
    # Check for missing values
    print(data.isnull().sum())`
    
- **Visualize the Data**:
    
    `import matplotlib.pyplot as plt
    import seaborn as sns
    
    # Create visualizations to observe distributions
    plt.figure(figsize=(12, 6))
    sns.histplot(data['Your SNP Column'])
    plt.title('Distribution of SNP Values')
    plt.show()`
    

---

### **5. Data Preprocessing**

- **Cleaning the Data**:
    - Handle missing values using imputation or deletion.
    
    `# Example of mean imputation
    data.fillna(data.mean(), inplace=True)`
    
- **Feature Engineering**:
    - Create additional features if necessary (e.g., interaction terms).
    
    `# Creating interaction terms (if applicable)
    data['Interaction'] = data['Feature1'] * data['Feature2']`
    

---

### **6. Data Splitting**

- **Split the Data into Train, Validation, and Test Sets**:

`from sklearn.model_selection import train_test_split

# Separate features and target variable
X = data.drop('Target', axis=1)  # Features
y = data['Target']                # Target variable

# Split the dataset
X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.3, random_state=42)
X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42)`

---

### **7. Model Training & Selection**

- **Select and Train Machine Learning Model**:
- For this example, we will use a Random Forest classifier for prediction.

`from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report

model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Validate the model
y_val_pred = model.predict(X_val)
print("Validation Accuracy: ", accuracy_score(y_val, y_val_pred))
print(classification_report(y_val, y_val_pred))`

---

### **8. Model Evaluation**

- **Test the Model on Unseen Data**:

`y_test_pred = model.predict(X_test)
print("Test Accuracy: ", accuracy_score(y_test, y_test_pred))
print(classification_report(y_test, y_test_pred))`

---

### **9. Result Improvement**

- **Hyperparameter Tuning** (Optional):

`from sklearn.model_selection import GridSearchCV

param_grid = {
    'n_estimators': [50, 100, 200],
    'max_depth': [None, 10, 20, 30]
}

grid_search = GridSearchCV(RandomForestClassifier(random_state=42), param_grid, cv=3, scoring='accuracy')
grid_search.fit(X_train, y_train)
print("Best Parameters: ", grid_search.best_params_)`

---

### **10. Deployment**

- To deploy, you can save your model using `joblib` or `pickle`:

`import joblib
joblib.dump(model, 'alzheimer_prediction_model.pkl')`

- Next, you may create a simple Flask API to serve predictions.

---

### Project Output Summary

1. **Data Access**: Retrieved data from ADNI in .bed, .bim, and .fam format.
2. **Data Manipulation**: Converted data to CSV and loaded it into a pandas DataFrame.
3. **Data Exploration**: Evaluated descriptive statistics and visualized distributions.
4. **Data Cleaning**: Addressed missing values using mean imputation.
5. **Feature Engineering**: Generated interaction terms from the features.
6. **Data Splitting**: Divided the dataset into training, validation, and test sets.
7. **Model Training**: Trained a Random Forest model and achieved validation accuracy.
8. **Model Evaluation**: Successfully tested the model on unseen data and reviewed performance metrics.
9. **Model Tuning**: Identified optimal hyperparameters to enhance model performance.
10. **Model Deployment**: Saved the model for future predictions and prepared for API deployment.
نمونه کدمم اینه :
یک سری نمونه کدم دارم :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, confusion_matrix

# Function to read BED file
def read_bed_file(bed_file, bim_file, fam_file):
    # Read BIM
    bim_df = pd.read_csv(bim_file, sep="\t", header=None)
    # Read FAM
    fam_df = pd.read_csv(fam_file, sep="\t", header=None)
    
    # Read BED (binary file)
    # Note: You’ll presumably either need a library to read binary files or rely on manual handling based on the structure.
    with open(bed_file, 'rb') as bed:
        bed_data = bed.read()
    
    # Convert binary data to SNP genotypes
    n_samples = fam_df.shape[0]
    n_snps = bim_df.shape[0]
    genotypes = np.zeros((n_samples, n_snps))
    
    # Here, you would need to convert the binary data
    # The conversion of binary data to genotypes is tricky; 
    # it depends on the encoding used in the BED format (e.g., 0, 1, 2).
    
    # Example of filling genotypes (actual logic will depend)
    # You would determine the encoding and fill genotypes accordingly.

    return bim_df, fam_df, genotypes

# Use the function to read your files
bim_df, fam_df, genotypes = read_bed_file('QC5.bed', 'QC5.bim', 'QC5.fam')

# Assuming fam_df has the second column as phenotype
phenotypes = fam_df.iloc[:, 1]  # Adjust this index according to your actual data

# Create DataFrame for genotypes
genotypes_df = pd.DataFrame(genotypes, columns=bim_df.iloc[:, 1])

# Merge phenotype and genotype data
merged_data = pd.concat([fam_df.iloc[:, 0:2], genotypes_df], axis=1)
merged_data.columns = ['FID', 'IID'] + list(bim_df.iloc[:, 1])

# Data exploration and visualization
print(merged_data.isnull().sum())

plt.figure(figsize=(8, 6))
sns.countplot(x='Phenotype', data=merged_data)
plt.title('Phenotype Distribution')
plt.show()

# Feature selection
features = merged_data.iloc[:, 2:]  # All SNP columns
labels = phenotypes  # Labels

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.2, random_state=42)

# Scale the features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Convert to DataFrame for easier handling
X_train_scaled_df = pd.DataFrame(X_train_scaled, columns=features.columns)
X_test_scaled_df = pd.DataFrame(X_test_scaled, columns=features.columns)

# Save processed data to CSV files
X_train_scaled_df.to_csv('X_train_scaled.csv', index=False)
X_test_scaled_df.to_csv('X_test_scaled.csv', index=False)
pd.Series(y_train).to_csv('y_train.csv', index=False)
pd.Series(y_test).to_csv('y_test.csv', index=False)

print("Data processing complete. Files saved: X_train_scaled.csv, X_test_scaled.csv, y_train.csv, y_test.csv")

# Optionally, you can train a model like Random Forest
model = RandomForestClassifier()
model.fit(X_train_scaled, y_train)

# Predictions
y_pred = model.predict(X_test_scaled)

# Evaluation
print(classification_report(y_test, y_pred))
conf_matrix = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(8, 6))
sns.heatmap(conf_matrix, annot=True, fmt='d')
plt.title('Confusion Matrix')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()

میخام بدون # و توضیح یک کد کامل بدون اینکه هیچ مرحله ای رو میس کنی پشت هم بنویسی