example datasets in sklearn

来源:互联网 发布:淘宝与京东 编辑:程序博客网 时间:2024/06/05 06:29
  • sklearn.datasets: Datasets¶
    • make_** ⇒ generator
    • load_** ⇒ loader

1. nonlinear example datasets

  • 1.1 half_moon

    产生非线性数据集,比如用以测试核机制的性能;
    核方法最终的使命是:unfold the half-moons(展开)

    from sklearn.datasets import make_moonsX, y = make_moons(n_samples=200, shuffle=True, random_state=123)plt.scatter(X[y==0, 0], X[y==0, 1], color='r', marker='^', alpha=.4)plt.scatter(X[y==1, 0], X[y==1, 1], color='r', marker='o', alpha=.4)plt.show()



  • 1.2 concentric circles

    from sklearn.datasets import make_circlesX, y = make_circles(n_samples=1000, noise=.1, factor=.2, random_state=123)plt.scatter(X[y==0, 0], X[y==0, 1], color='r', marker='^', alpha=.4)plt.scatter(X[y==1, 0], X[y==1, 1], color='b', marker='o', alpha=.4)plt.show()



2. datasets in sklearn

from sklearn import datasets
  • iris
>>> iris = datasets.load_iris()>>> dir(iris)
>>> iris.features_names['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']>>> iris.target_namesarray(['setosa', 'versicolor', 'virginica'],      dtype='<U10')>>> iris.data.shape(150, 4)                    # 训练样本 >>> iris.target.shape(150,)                      # 一维的训练样本
  • digits

    >> digits = datasets.load_digits()>> dir(digits)>> digits.data.target_names...

3. UCI 数据

  • Breast Cancer Wisconsin dataset

    which contains 569 samples of malignant(恶性的) and benign(良性的) tumor cells.

    The first two columns in the dataset store the unique ID numbers of the samples and the corresponding diagnoisi (M=malignant, B=benign), respectively.

    The columns 3-32 contains 30 real-value features that have been computed from digitized images of the cell nuclei, which can be used to build a model to predict whether a tumor is benign or malignant.

    import pandas as pddf = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/'                 'breast-cancer-wisconsin/wdbc.data', header=None)X, y = df.values[:, 2:], df.values[:, 1]
0 0
原创粉丝点击