Example_2_5#

Generate data for classification exercises.

!wget --no-cache -O init.py -q https://raw.githubusercontent.com/jdariasl/OTBD/main/content/init.py
import init; init.init(force_download=False)
#!sudo apt install cm-super dvipng texlive-latex-extra texlive-latex-recommended
import numpy as np
import matplotlib.pyplot as plt
from local.lib.Generation import Get_data_class
# Data generation
# ===========================
d = 2                       # Dimensionality of data vector 
mean_x1= np.array([2,2])    # Mean of input data class 1
coef_corr_x1=.2             # Correlation coefficient of input data class 1
var_x1=1.5                  # Variance of input data class 1
mean_x2= np.array([-2,-2])  # Mean of input data class 1
coef_corr_x2=.2             # Correlation coefficient of input data class 1
var_x2=1.5                  # Variance of input data class 1

# Build data struct 
data_class= {'d': d,
             'Mean_x1': mean_x1,
             'Coef_corr_x1': coef_corr_x1,
             'Var_x1': var_x1,
             'Mean_x2': mean_x2,
             'Coef_corr_x2': coef_corr_x2,
             'Var_x2': var_x2}

X,y=Get_data_class(data_class,1000);
i1=np.where(y==1)
i2=np.where(y==-1)
plt.rcParams['text.usetex'] = True
plt.scatter(X[i1,0],X[i1,1],color='r',marker='o', linewidth=3)
plt.scatter(X[i2,0],X[i2,1],color='b',marker='+', linewidth =3)
plt.grid()
plt.xlabel(r'$x_1$')
plt.ylabel(r'$x_2$')
plt.title('Classification problem')
plt.show()
../_images/5899783024c91f4b7be351a01bf5e5b938382f7f74681d17684549a5e2967b12.png