本文整理汇总了Python中sklearn.datasets.make_circles函数的典型用法代码示例。如果您正苦于以下问题:Python make_circles函数的具体用法?Python make_circles怎么用?Python make_circles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_circles函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:ctralie,项目名称:ripser,代码行数:28,代码来源:test_ripser.py
示例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)
开发者ID:ctralie,项目名称:ripser,代码行数:28,代码来源:test_ripser_sklearn.py
示例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')
开发者ID:ntduong,项目名称:ML,代码行数:7,代码来源:kernel_pca.py
示例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."
开发者ID:ewestern,项目名称:machine_learning,代码行数:35,代码来源:generate_dataset.py
示例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
开发者ID:ilanman,项目名称:blogposts,代码行数:27,代码来源:kernel_trick.py
示例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()
开发者ID:SanchitAggarwal,项目名称:Sandbox,代码行数:59,代码来源:spectral_clustering.py
示例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()
开发者ID:ilanman,项目名称:blogposts,代码行数:8,代码来源:kernel_trick.py
示例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()
开发者ID:nkt1546789,项目名称:CCPM,代码行数:8,代码来源:CCPM.py
示例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))
开发者ID:adolenc,项目名称:topotext,代码行数:8,代码来源:benchmark_toy.py
示例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
开发者ID:cuissai,项目名称:Learning,代码行数:58,代码来源:nntoy_examples.py
示例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
开发者ID:AkiraKane,项目名称:Python,代码行数:9,代码来源:classifier_comparison.py
示例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()]
开发者ID:wdm0006,项目名称:sklearn-extensions,代码行数:9,代码来源:example.py
示例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)
开发者ID:Claire-Ling-Liu,项目名称:scikit-learn,代码行数:10,代码来源:test_kernel_pca.py
示例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)
开发者ID:henrywoo,项目名称:scikit-learn,代码行数:11,代码来源:test_forest.py
示例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)
开发者ID:AndreasMadsen,项目名称:course-02460,代码行数:11,代码来源:2d_significant.py
示例16: test_gridsearch_pipeline_precomputed
def test_gridsearch_pipeline_precomputed():
# Test if we can do a grid-search to find parameters to separate
# circles with a perceptron model using a precomputed kernel.
X, y = make_circles(n_samples=400, factor=0.3, noise=0.05, random_state=0)
kpca = KernelPCA(kernel="precomputed", n_components=2)
pipeline = Pipeline([("kernel_pca", kpca), ("Perceptron", Perceptron())])
param_grid = dict(Perceptron__n_iter=np.arange(1, 5))
grid_search = GridSearchCV(pipeline, cv=3, param_grid=param_grid)
X_kernel = rbf_kernel(X, gamma=2.0)
grid_search.fit(X_kernel, y)
assert_equal(grid_search.best_score_, 1)
开发者ID:Claire-Ling-Liu,项目名称:scikit-learn,代码行数:11,代码来源:test_kernel_pca.py
示例17: gen_test_data
def gen_test_data() :
################################################################
# using sklearn #
################################################################
N = 500
#features,labels = ds.make_classification(n_samples = N,n_features = 2,n_informative = 2,n_redundant = 0,n_clusters_per_class = 1,class_sep = 2,shift = 2.2)
features,labels = ds.make_circles(n_samples = N)
#features,labels = ds.make_moons(n_samples = N)
labels[labels == 0] = -1
features = auto_np.array(features) * 4.0
labels = auto_np.array(labels).reshape(features.shape[0],1)
return features,labels
开发者ID:fenss,项目名称:tat_algorithm,代码行数:12,代码来源:tat_nn_with_autograd.py
示例18: makeSimpleDatasets
def makeSimpleDatasets(n_samples=1500): # from sklearn example
np.random.seed(0)
# Generate datasets. We choose the size big enough to see the scalability
# of the algorithms, but not too big to avoid too long running times
n_samples = 1500
noisy_circles = datasets.make_circles(n_samples=n_samples, factor=.5,
noise=.05)
noisy_moons = datasets.make_moons(n_samples=n_samples, noise=.05)
blobs = datasets.make_blobs(n_samples=n_samples, random_state=8)
no_structure = np.random.rand(n_samples, 2), None
return [noisy_circles, noisy_moons, blobs, no_structure]
开发者ID:dblalock,项目名称:flock,代码行数:12,代码来源:clusters.py
示例19: get_dataset
def get_dataset(dataset, n_samples):
if dataset == "Noisy Circles":
return datasets.make_circles(n_samples=n_samples, factor=0.5, noise=0.05)
elif dataset == "Noisy Moons":
return datasets.make_moons(n_samples=n_samples, noise=0.05)
elif dataset == "Blobs":
return datasets.make_blobs(n_samples=n_samples, random_state=8)
elif dataset == "No Structure":
return np.random.rand(n_samples, 2), None
开发者ID:ChunHungLiu,项目名称:bokeh,代码行数:12,代码来源:main.py
示例20: get_dataset
def get_dataset(dataset, n_samples):
# Generate the new data:
if dataset=='Noisy Circles':
X, y = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05)
elif dataset=='Noisy Moons':
X, y = datasets.make_moons(n_samples=n_samples, noise=.05)
elif dataset=='Blobs':
X, y = datasets.make_blobs(n_samples=n_samples, random_state=8)
else:
X, y = np.random.rand(n_samples, 2), None
return X, y
开发者ID:ContinuumIO,项目名称:webinar-examples,代码行数:12,代码来源:cluster2.py
注:本文中的sklearn.datasets.make_circles函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论