text_html_output_1.png
from sklearn.decomposition import PCA

from sklearn.decomposition import PCA

from sklearn.preprocessing import StandardScaler

from statsmodels.stats.outliers_influence import variance_inflation_factor

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

final_data = pd.read_csv('/kaggle/input/new-01-05-2023-update-1/new_final_updated_dataset.csv')
final_data.columns

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
final_data.drop('Unnamed: 0', axis=1, inplace=True)
final_data

final_copy = final_data.copy(deep=True)
final_copy

final_copy.drop(['lncRNA', 'miRNA'], axis=1, inplace=True)
final_copy

X = final_copy.drop('label', axis=1)
vif_data = pd.DataFrame()
vif_data['feature'] = X.columns
vif_data['VIF'] = [variance_inflation_factor(X.values, i) for i in range(len(X.columns))]
vif_data

X.drop(list(vif_data[vif_data['VIF'] > vif_data['VIF'].mean()]['feature']), axis=1, inplace=True)
X

vif_data = pd.DataFrame()
vif_data['feature'] = X.columns
vif_data['VIF'] = [variance_inflation_factor(X.values, i) for i in range(len(X.columns))]
vif_data

sc = StandardScaler()
X = sc.fit_transform(X)
pca = PCA(n_components=182)
X_pca = pca.fit_transform(X)
explained_variance = pca.explained_variance_ratio_
explained_variance

plt.rcParams['figure.figsize'] = (12, 6)
fig, ax = plt.subplots()
xi = np.arange(0, 182, step=1)
y = np.cumsum(explained_variance)
plt.ylim(0.0, 1.1)
plt.plot(xi, y, marker='o', linestyle='--', color='b')
plt.xlabel('Number of Components')
plt.xticks(np.arange(0, 182, step=5))
plt.ylabel('Cumulative variance (%)')
plt.title('The number of components needed to explain variance')
plt.axhline(y=0.98, color='r', linestyle='-')
plt.text(0.5, 0.85, '98% cut-off threshold', color='red', fontsize=16)
ax.grid(axis='x')
plt.show()