I have been given a task to generate a dataset that is shaped in three interleaving half circles.I have generated 2 half circles using make_moons() function available in "sklearn" library but cant figure out how to make three such half circles.
Code:
X, y=make_moons(n_samples=(300,300),noise=0.1)
df=pd.DataFrame(dict(x=X[:,0], y=X[:,1],label=y ))
colors={0:'red', 1:'blue',2:'green'}
fig,ax=plt.subplots()
grouped=df.groupby('label')
for key, group in grouped:
group.plot(ax=ax,kind='scatter',x='x',y='y',label=key,color=colors[key
plt.show()
I tried to increase the dimension in sample size but it gives an error that "n_samples can be either an int or a two-element tuple."
here is a function that makes a dataset with an arbitrary number of moons. You can specify vertical shift with the
y_shift
parameter.