history heatmap of each gene across generations

Skip to first unread message

Florin Andrei

Jan 2, 2024, 7:39:21 PMJan 2
to deap-users
I'm using Deap for feature selection for regression models. The meaning of each gene is important - it's whether a certain feature in the data is selected or not. I've found it useful to track the evolution of the mean value of each gene across all generations. It shows which genes are found immediately useful (or not), versus those that are more marginal. I have not seen this done before, so I'm posting it here in case it's useful.

I've started with a trivial example and just added on top of it:

Before the main loop, I initialize the array that will collect the mean values for the genes:

generations_max = 40
gene_values_mean = np.zeros((generations_max, X.shape[1] - 1))
for g in tqdm(range(1, generations_max + 1), desc='generation'):
    # main loop

At the end of the main loop I collect the mean values:

gene_values_mean[g - 1, :] = np.array(pop).mean(axis=0)

After all is done, I display the mean values as a heat map:

gvm_df = pd.DataFrame(gene_values_mean, columns=X_features, index=range(1, gene_values_mean.shape[0] + 1))
fig, ax = plt.subplots(1, 1, figsize=(10, 7), layout='constrained')
sns.heatmap(gvm_df.T, vmin=0.0, vmax=1.0, cmap='viridis', cbar=True, ax=ax)
fig.suptitle('Population average of gene values after each generation')

It looks like this:


Hopefully someone will find this useful.


Reply all
Reply to author
0 new messages