目录
python生成分类数据集
生成blobs数据
moons数据集
circles数据集
python生成回归数据集
from sklearn.datasets.samples_generator import make_blobs
import matplotlib.pyplot as plt
from pandas import DataFrame
X, y = make_blobs(n_samples=100, centers=3, n_features=2)
# n_samples : The total number of points equally divided among clusters.
# n_features : The number of features for each sample.
# centers : The number of centers to generate, or the fixed center locations.
df = 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()
from sklearn.datasets import make_moons
import matplotlib.pyplot as plt
from pandas import DataFrame
X, y = make_moons(n_samples=100, noise=0.1)
df = DataFrame(dict(x=X[:,0], y=X[:,1], label=y))
colors = {0:'red', 1:'blue'}
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()
from sklearn.datasets import make_circles
import matplotlib.pyplot as plt
from pandas import DataFrame
X, y = make_circles(n_samples=100, noise=0.05)
df = DataFrame(dict(x=X[:,0], y=X[:,1], label=y))
colors = {0:'red', 1:'blue'}
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()
from sklearn.datasets import make_regression
import matplotlib.pyplot as plt
X, y = make_regression(n_samples=100, n_features=1, noise=0.1)
plt.scatter(X,y)
plt.show()