Skip to content
Snippets Groups Projects
Commit 0a994a46 authored by Luigi Sbailo's avatar Luigi Sbailo
Browse files

Generate dataset

parents
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
from sklearn.datasets import make_blobs
import numpy as np
import math
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
n_samples = 500
random_state = 0
X, y = make_blobs(n_samples=n_samples,
random_state=random_state,
centers=[[0, 0],
[0,0],
[0,0],
[0,0]
])
blob = 0
transformation = [[1,0],[0,5]]
X=np.where (y==blob, np.dot(transformation,X.T), X.T).T
X[:,0]=np.where (y==blob, X[:,0]+X[:,1]**2/20, X[:,0])
theta = 0.15 * math.pi
transformation = [[np.cos(theta),-np.sin(theta)],[np.sin(theta),np.cos(theta)]]
X=np.where (y==blob, np.dot(transformation,X.T), X.T).T
blob = 1
transformation = [[1,0],[0,3]]
X=np.where (y==blob, np.dot(transformation,X.T), X.T).T
X[:,0]=np.where (y==blob, X[:,0]+X[:,1]**2/10, X[:,0])
theta = 0.95 * math.pi
transformation = [[np.cos(theta),-np.sin(theta)],[np.sin(theta),np.cos(theta)]]
X = np.where (y==blob, np.dot(transformation,X.T), X.T).T
X = np.where (y==blob, np.add(X,np.concatenate([13*np.ones([len(X),1]),10*np.ones([len(X),1])],axis=1)).T,X.T).T
blob = 2
transformation = [[1,0],[0,3]]
X=np.where (y==blob, np.dot(transformation,X.T), X.T).T
X[:,0]=np.where (y==blob, X[:,0]+X[:,1]**2/10, X[:,0])
theta = 0.15 * math.pi
transformation = [[np.cos(theta),-np.sin(theta)],[np.sin(theta),np.cos(theta)]]
X = np.where (y==blob, np.dot(transformation,X.T), X.T).T
X = np.where (y==blob, np.add(X,np.concatenate([-3*np.ones([len(X),1]),25*np.ones([len(X),1])],axis=1)).T,X.T).T
blob = 3
transformation = [[0.2,0],[0,10]]
X=np.where (y==blob, np.dot(transformation,X.T), X.T).T
theta = 0.05 * math.pi
transformation = [[np.cos(theta),-np.sin(theta)],[np.sin(theta),np.cos(theta)]]
X = np.where (y==blob, np.dot(transformation,X.T), X.T).T
X = np.where (y==blob, np.add(X,np.concatenate([-6*np.ones([len(X),1]),-1*np.ones([len(X),1])],axis=1)).T,X.T).T
```
%% Cell type:code id: tags:
``` python
plt.scatter(X[:,0],X[:,1],c=y)
```
%% Output
<matplotlib.collections.PathCollection at 0x7fa8ddcf7cd0>
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment