本文整理汇总了Python中sklearn.datasets.make_circles函数的典型用法代码示例。如果您正苦于以下问题:Python make_circles函数的具体用法?Python make_circles怎么用?Python make_circles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_circles函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sparse
def test_sparse(self):
np.random.seed(10)
thresh = 1.1
# Do dense filtration with threshold
data = (
datasets.make_circles(n_samples=100)[0]
+ 5 * datasets.make_circles(n_samples=100)[0]
)
res0 = ripser(data, thresh=thresh)
# Convert to sparse matrix first based on threshold,
# then do full filtration
D = makeSparseDM(data, thresh)
res1 = ripser(D, distance_matrix=True)
# The same number of edges should have been added
assert res0["num_edges"] == res1["num_edges"]
dgms0 = res0["dgms"]
dgms1 = res1["dgms"]
I10 = dgms0[1]
I11 = dgms1[1]
idx = np.argsort(I10[:, 0])
I10 = I10[idx, :]
idx = np.argsort(I11[:, 0])
I11 = I11[idx, :]
assert np.allclose(I10, I11)
示例2: test_sparse
def test_sparse(self):
np.random.seed(10)
thresh = 1.1
# Do dense filtration with threshold
data = (
datasets.make_circles(n_samples=100)[0]
+ 5 * datasets.make_circles(n_samples=100)[0]
)
rips0 = Rips(thresh=thresh, maxdim=1)
dgms0 = rips0.fit_transform(data)
# Convert to sparse matrix first based on threshold,
# then do full filtration
rips1 = Rips(maxdim=1)
D = makeSparseDM(data, thresh)
dgms1 = rips1.fit_transform(D, distance_matrix=True)
# The same number of edges should have been added
assert rips0.num_edges_ == rips1.num_edges_
I10 = dgms0[1]
I11 = dgms1[1]
idx = np.argsort(I10[:, 0])
I10 = I10[idx, :]
idx = np.argsort(I11[:, 0])
I11 = I11[idx, :]
assert np.allclose(I10, I11)
示例3: withCircleData
def withCircleData():
np.random.seed(0)
X, Y = make_circles(n_samples=400, noise=.05, factor=.3)
#plotData(X, Y, 'original-circle.png')
#testPCA(X, Y, ncomp=2, dataset='circles')
#myKPCA(X, Y, kernel_type='gauss', c=1, deg=2, ncomp=2, dataset='circles')
myKPCA(X, Y, kernel_type='poly', c=1, deg=10, ncomp=2, dataset='circles')
示例4: main
def main():
args = sys.argv[1:]
dataset_path = None
if args and '-save' in args:
try: dataset_path = args[args.index('-save') + 1]
except: dataset_path = 'dataset.p'
# Generate the dataset
print "...Generating Dataset..."
X1, Y1 = make_circles(n_samples=800, noise=0.07, factor=0.4)
frac0 = len(np.where(Y1 == 0)[0]) / float(len(Y1))
frac1 = len(np.where(Y1 == 1)[0]) / float(len(Y1))
print "Percentage of '0' labels:", frac0
print "Percentage of '1' labels:", frac1
# (Optionally) save the dataset to DATASET_PATH
if dataset_path:
print "...Saving dataset to {0}...".format(dataset_path)
pickle.dump((X1, Y1, frac0, frac1), open(dataset_path, 'wb'))
# Plot the dataset
print "...Showing dataset in new window..."
pl.figure(figsize=(10, 8))
pl.subplots_adjust(bottom=.05, top=.9, left=.05, right=.95)
pl.subplot(111)
pl.title("Our Dataset: N=200, '0': {0} '1': {1} ".format(frac0, frac1), fontsize="large")
pl.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1)
pl.show()
print "...Done."
示例5: generate_data
def generate_data():
def kernel(x1, x2):
return np.array([x1, x2, 2 * x1 ** 2 + 2 * x2 ** 2])
X, Y = make_circles(500, noise=0.12, factor=0.01)
A = X[np.where(Y == 0)]
B = X[np.where(Y == 1)]
X0_orig = A[:, 0]
Y0_orig = A[:, 1]
X1_orig = B[:, 0]
Y1_orig = B[:, 1]
A = np.array([kernel(x, y) for x, y in zip(np.ravel(X0_orig), np.ravel(Y0_orig))])
X0 = A[:, 0]
Y0 = A[:, 1]
Z0 = A[:, 2]
A = np.array([kernel(x, y) for x, y in zip(np.ravel(X1_orig), np.ravel(Y1_orig))])
X1 = A[:, 0]
Y1 = A[:, 1]
Z1 = A[:, 2]
return X0, X1, Y0, Y1, Z0, Z1
示例6: main
def main():
no_of_samples = 400
data = []
data.append( datasets.make_moons(n_samples=no_of_samples, noise=0.05)[0] )
data.append( datasets.make_circles(n_samples=no_of_samples, factor=0.5, noise=0.05)[0] )
# number of clusters we expect
K = 2
for X in data:
# from dataset, create adjacency, degree, and laplacian matrix
adjacency = gaussianDistance( X, sigma=0.1 )
degree = degreeMatrix( adjacency )
L = diag(degree) - adjacency
# perform whitening on the Laplacian matrix
deg_05 = diag( degree ** -0.5 )
L = deg_05.dot( L ).dot( deg_05 )
# use eig to obtain eigenvalues and eigenvectors
eigenvalues, eigenvectors = linalg.eig( L )
# Sort the eigenvalues ascending, the first K zero eigenvalues represent the connected components
idx = eigenvalues.argsort()
eigenvalues.sort()
evecs = eigenvectors[:, idx]
eigenvectors = evecs[:, 0:K]
print eigenvalues[0:K]
color_array = ['b', 'r', 'g', 'y']
fig = pyplot.figure( figsize=(15, 5) )
fig.canvas.set_window_title( 'Difference between K-means and Spectral Clusterings' )
# First perform the normal K-means on the original dataset and plot it out
centroids, labels = scipy.cluster.vq.kmeans2( X, K )
data = c_[X, labels]
ax = fig.add_subplot( 131 )
ax.set_title('K means clustering')
for k in range( 0, K ):
ax.scatter( data[data[:, 2]==k, 0], data[data[:, 2]==k, 1], c=color_array[k], marker='o')
# Then we perform spectral clustering, i.e. K-means on eigenvectors
centroids, labels = scipy.cluster.vq.kmeans2( eigenvectors, K )
data = c_[X, labels]
ax = fig.add_subplot( 132 )
ax.set_title('Spectral clustering')
for k in range( 0, K ):
ax.scatter( data[data[:, 2]==k, 0], data[data[:, 2]==k, 1], c=color_array[k], marker='o')
# Plot out the eigenvectors too
data = c_[eigenvectors, labels]
ax = fig.add_subplot(133)
ax.set_title('K-eigenvectors')
for k in range( 0, K ):
ax.scatter( data[data[:, 2]==k, 0], data[data[:, 2]==k, 1], c=color_array[k], marker='o')
pyplot.show()
示例7: generate_circles
def generate_circles():
X1, Y1 = make_circles(n_samples=500, noise=0.07, factor=0.4)
plt.figure(figsize=(5, 5))
plt.scatter(X1[:, 0], X1[:, 1], c=Y1)
plt.grid(b=True, which="major", linestyle="-", alpha=0.1, color="black")
plt.title("Can this be solved linearly?", size=16)
plt.show()
示例8: main
def main():
n=500
x,y=datasets.make_circles(n_samples=n,factor=.5,noise=.05)
label=CCPMCV().fit(x).label
print "ARI:",adjusted_rand_score(y,label)
figure(1)
scatter(x[:,0],x[:,1],c=label,s=50)
show()
示例9: generate_circles
def generate_circles(n, y_val):
"""
Generates a dataset where points are shaped into two circles,
and labels them with y_val.
"""
X,y = make_circles(n, noise=0.1)
return (X, [y_val] * len(X))
示例10: generate_biclass_data
def generate_biclass_data(data_type, random_state):
""" Generate biclass data to classify
arg : data_type (str) possible type of data
choose any in ["lin_sep", "non_lin_sep", "overlap"]
'lin_sep' : Bi-class, linearly separable data
'non_lin_sep' : Bi-class, non linearly separable data
'overlap' : Bi-class, non linearly separable data with class overlap
random_state (int) seed for numpy.random
"""
# Set seed for reproducible results
np.random.seed(random_state)
# Case 1 : linearly separable data
if data_type == "lin_sep":
mean1 = np.array([0, 2])
mean2 = np.array([2, 0])
cov = np.array([[0.8, 0.6], [0.6, 0.8]])
X1 = np.random.multivariate_normal(mean1, cov, 100)
y1 = np.ones(len(X1))
X2 = np.random.multivariate_normal(mean2, cov, 100)
y2 = np.ones(len(X2)) * -1
X = np.vstack((X1, X2))
y = np.hstack((y1, y2))
# Case 2 : non -linearly separable data
elif data_type == "moons":
X, y = make_moons(n_samples=200, noise=0.2)
elif data_type == "circles":
X, y = make_circles(n_samples=200, noise=0.2, factor=0.5)
# Case 3 : data with overlap between classes
elif data_type == "overlap":
mean1 = np.array([0, 2])
mean2 = np.array([2, 0])
cov = np.array([[1.5, 1.0], [1.0, 1.5]])
X1 = np.random.multivariate_normal(mean1, cov, 100)
y1 = np.ones(len(X1))
X2 = np.random.multivariate_normal(mean2, cov, 100)
y2 = np.ones(len(X2)) * -1
X = np.vstack((X1, X2))
y = np.hstack((y1, y2))
assert(X.shape[0] == y.shape[0])
# Format target to: -1 / +1
targets = set(y.tolist())
t1 = min(targets)
t2 = max(targets)
l1 = np.where(y < t2)
l2 = np.where(y > t1)
y[l1] = -1
y[l2] = 1
return X, y
示例11: loadDatasets
def loadDatasets(linearly_separable):
datasets = [\
make_moons(noise=0.3, random_state=0), \
make_circles(noise=0.2, factor=0.5, random_state=1), \
linearly_separable \
]
return datasets
示例12: make_datasets
def make_datasets():
"""
:return:
"""
return [make_moons(n_samples=200, noise=0.3, random_state=0),
make_circles(n_samples=200, noise=0.2, factor=0.5, random_state=1),
make_linearly_separable()]
示例13: test_gridsearch_pipeline
def test_gridsearch_pipeline():
# Test if we can do a grid-search to find parameters to separate
# circles with a perceptron model.
X, y = make_circles(n_samples=400, factor=0.3, noise=0.05, random_state=0)
kpca = KernelPCA(kernel="rbf", n_components=2)
pipeline = Pipeline([("kernel_pca", kpca), ("Perceptron", Perceptron())])
param_grid = dict(kernel_pca__gamma=2.0 ** np.arange(-2, 2))
grid_search = GridSearchCV(pipeline, cv=3, param_grid=param_grid)
grid_search.fit(X, y)
assert_equal(grid_search.best_score_, 1)
示例14: test_random_trees_dense_type
def test_random_trees_dense_type():
# Test that the `sparse_output` parameter of RandomTreesEmbedding
# works by returning a dense array.
# Create the RTE with sparse=False
hasher = RandomTreesEmbedding(n_estimators=10, sparse_output=False)
X, y = datasets.make_circles(factor=0.5)
X_transformed = hasher.fit_transform(X)
# Assert that type is ndarray, not scipy.sparse.csr.csr_matrix
assert_equal(type(X_transformed), np.ndarray)
示例15: build_datasets
def build_datasets(n_samples=100):
X, y = make_classification(n_samples=n_samples, n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1)
X += 2 * np.random.uniform(size=X.shape)
linearly_separable = (X, y)
names = ['moons', 'circles', 'linear', 'xor']
datasets = [make_moons(n_samples=n_samples, noise=0.3),
make_circles(n_samples=n_samples, noise=0.2, factor=0.5),
linearly_separable,
xor_scale_invariant(n_samples=n_samples)]
return (names, datasets)