sklearn的detasets模块

from sklearn.datasets.california_housing import fetch_california_housing
housing = fetch_california_housing()
print(housing.DESCR)

一、介绍

对于不同类型的数据集,有三种不同类型的数据集接口。

1、生成数据函数与svmlight loader共享同一规则。

返回一元组tuple(X,y),X为array(n*m), y也为array(n*1)

2、其返回类似于字典类型的数据,有两个key:data与target

3、返回对象的数据描述:DESCR;feature_names; target_names

%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from sklearn.datasets.california_housing import fetch_california_housing
housing = fetch_california_housing()
print(housing.data[0:2])
print(housing.target)
type(housing.target)
print(housing.feature_names)

 

也可如此输入:

from sklearn.datasets import fetch_california_housing


dataset = fetch_california_housing()
X_full, y_full = dataset.data, dataset.target

 

二、数据集介绍

1、toy datasets

这些数据集有助于快速说明scikit中实现的各种算法的行为。然而,它们往往太小,不能代表现实世界中的机器学习任务。

2、sample images

scikit还嵌入了一些样本JPEG图像,这些图像是作者根据知识共享协议发布的。这些图像可用于测试算法和二维数据管道。

默认的图像编码是基于uint8 dtype来节省内存。通常,如果输入首先转换为浮点表示法,机器学习算法的工作效果最好。另外,如果您计划使用matplotlib.pyplpt。imshow不要忘记缩放到0 - 1的范围,如下例所示。

3、Sample generators

此外,scikit-learn还包含各种随机样本生成器,可用于构建控制大小和复杂性的人工数据集。

(1)、Generators for classification and clustering

这些发生器产生一个特征矩阵和相应的离散目标。

1)、single label

make_blob和make_classification都通过为每个类分配一个或多个正常分布的点集群来创建多类数据集。make_blob能够更好地控制每个集群的中心和标准差,并用于演示集群。make_classification主要通过以下方式引入噪声:相关的、冗余的和不提供信息的特征;每个类有多个高斯簇;特征空间的线性变换。

make_gaussian_quantiles将一个高斯簇划分为几乎相等大小的类,由同心圆超球体分隔。make_hastie_10_2生成了一个类似的二进制10维问题。

make_circles和make_moon生成的二维二进制分类数据集对某些算法(例如基于中心的聚类或线性分类)具有挑战性,包括可选的高斯噪声。它们对视觉化很有用。生成具有球形决策边界的高斯数据,用于二进制分类。

2)、multilabel

make_multilabel_classification生成带有多个标签的随机样本,反映了从多个主题中提取的一组单词。每个文档的主题数量来自泊松分布,主题本身来自固定的随机分布。类似地,单词的数量是从Poisson中提取的,单词是从多项中提取的,其中每个主题定义单词的概率分布。对真正的字库混合的简化包括:

  •    每个主题的词分布是独立绘制的,在实际中,所有的词都将受到稀疏基分布的影响,并且是相互关联的。
  •    对于由多个主题生成的文档,所有主题在生成其词包时都是同等权重的。
  •    没有标签的文档是随机的,而不是基本分布的。

(2)、Generators for regression

make_regression生成带有噪声的随机特征的可选稀疏随机线性组合的回归目标。它的信息性特征可能是不相关的,或者等级低(很少的特征占大多数的方差)。

其他的回归生成器从随机特征中确定地生成函数。make_sparse_uncorrelation生成的目标是由四个固定系数的特征线性组合而成的。另一些则显式地编码非线性关系:make_friedman1通过多项式和正弦变换相关联;make_friedman2包括特性乘法和交互;make_friedman3与targe上的arctan转换类似.

补充:

1、Datasets in svmlight / libsvm format

scikit-learn包含用于加载svmlight / libsvm格式数据集的实用函数。在这种格式中,每一行的<标记> <特性id >:<特征值> <特性id >:<特征值> ....这种格式特别适合于稀疏数据集。在这个模块中,X使用scipy稀疏CSR矩阵,y使用numpy数组。

sklearn.datasets 的所有操作;

Loaders

datasets.clear_data_home([data_home])Delete all the content of the data home cache.
datasets.dump_svmlight_file(X, y, f[, …])Dump the dataset in svmlight / libsvm file format.
datasets.fetch_20newsgroups([data_home, …])Load the filenames and data from the 20 newsgroups dataset.
datasets.fetch_20newsgroups_vectorized([…])Load the 20 newsgroups dataset and transform it into tf-idf vectors.
datasets.fetch_california_housing([…])Loader for the California housing dataset from StatLib.
datasets.fetch_covtype([data_home, …])Load the covertype dataset, downloading it if necessary.
datasets.fetch_kddcup99([subset, data_home, …])Load and return the kddcup 99 dataset (classification).
datasets.fetch_lfw_pairs([subset, …])Loader for the Labeled Faces in the Wild (LFW) pairs dataset
datasets.fetch_lfw_people([data_home, …])Loader for the Labeled Faces in the Wild (LFW) people dataset
datasets.fetch_mldata(dataname[, …])Fetch an mldata.org data set
datasets.fetch_olivetti_faces([data_home, …])Loader for the Olivetti faces data-set from AT&T.
datasets.fetch_rcv1([data_home, subset, …])Load the RCV1 multilabel dataset, downloading it if necessary.
datasets.fetch_species_distributions([…])Loader for species distribution dataset from Phillips et.
datasets.get_data_home([data_home])Return the path of the scikit-learn data dir.
datasets.load_boston([return_X_y])Load and return the boston house-prices dataset (regression).
datasets.load_breast_cancer([return_X_y])Load and return the breast cancer wisconsin dataset (classification).
datasets.load_diabetes([return_X_y])Load and return the diabetes dataset (regression).
datasets.load_digits([n_class, return_X_y])Load and return the digits dataset (classification).
datasets.load_files(container_path[, …])Load text files with categories as subfolder names.
datasets.load_iris([return_X_y])Load and return the iris dataset (classification).
datasets.load_linnerud([return_X_y])Load and return the linnerud dataset (multivariate regression).
datasets.load_mlcomp(name_or_id[, set_, …])DEPRECATED: since the http://mlcomp.org/ website will shut down in March 2017, the load_mlcomp function was deprecated in version 0.19 and will be removed in 0.21.
datasets.load_sample_image(image_name)Load the numpy array of a single sample image
datasets.load_sample_images()Load sample images for image manipulation.
datasets.load_svmlight_file(f[, n_features, …])Load datasets in the svmlight / libsvm format into sparse CSR matrix
datasets.load_svmlight_files(files[, …])Load dataset from multiple files in SVMlight format
datasets.load_wine([return_X_y])Load and return the wine dataset (classification).
datasets.mldata_filename(dataname)

Convert a raw name for a data set in a mldata.org filename.

Samples generator

datasets.make_biclusters(shape, n_clusters)Generate an array with constant block diagonal structure for biclustering.
datasets.make_blobs([n_samples, n_features, …])Generate isotropic Gaussian blobs for clustering.
datasets.make_checkerboard(shape, n_clusters)Generate an array with block checkerboard structure for biclustering.
datasets.make_circles([n_samples, shuffle, …])Make a large circle containing a smaller circle in 2d.
datasets.make_classification([n_samples, …])Generate a random n-class classification problem.
datasets.make_friedman1([n_samples, …])Generate the “Friedman #1” regression problem
datasets.make_friedman2([n_samples, noise, …])Generate the “Friedman #2” regression problem
datasets.make_friedman3([n_samples, noise, …])Generate the “Friedman #3” regression problem
datasets.make_gaussian_quantiles([mean, …])Generate isotropic Gaussian and label samples by quantile
datasets.make_hastie_10_2([n_samples, …])Generates data for binary classification used in Hastie et al.
datasets.make_low_rank_matrix([n_samples, …])Generate a mostly low rank matrix with bell-shaped singular values
datasets.make_moons([n_samples, shuffle, …])Make two interleaving half circles
datasets.make_multilabel_classification([…])Generate a random multilabel classification problem.
datasets.make_regression([n_samples, …])Generate a random regression problem.
datasets.make_s_curve([n_samples, noise, …])Generate an S curve dataset.
datasets.make_sparse_coded_signal(n_samples, …)Generate a signal as a sparse combination of dictionary elements.
datasets.make_sparse_spd_matrix([dim, …])Generate a sparse symmetric definite positive matrix.
datasets.make_sparse_uncorrelated([…])Generate a random regression problem with sparse uncorrelated design
datasets.make_spd_matrix(n_dim[, random_state])Generate a random symmetric, positive-definite matrix.
datasets.make_swiss_roll([n_samples, noise, …])Generate a swiss roll dataset.

 参考地址:http://scikit-learn.org/stable/modules/classes.html#module-sklearn.datasets

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在使用 joblib 时,需要导入 sklearn 中的以下模块: ```python from sklearn.externals import joblib ``` 在新版本的 sklearn 中,`externals` 模块已经被移除,建议使用以下方式导入: ```python import joblib ``` 如果你需要使用 scikit-learn 中的某些算法或数据集,还需要导入对应的模块。例如,如果你想使用 `RandomForestClassifier` 算法,可以使用以下语句导入: ```python from sklearn.ensemble import RandomForestClassifier ``` 如果你想使用 `iris` 数据集,可以使用以下语句导入: ```python from sklearn.datasets import load_iris ``` 需要注意的是,不同版本的 scikit-learn 可能具有不同的模块结构,因此在导入模块时需要根据实际情况进行调整。 ### 回答2: 在使用joblib库时,通常需要导入sklearn的以下模块: 1. from sklearn.externals import joblib:这是导入joblib库的主要模块,用于保存和加载Python对象。 2. from sklearn.pipeline import Pipeline:如果在保存或加载Pipeline对象时需要使用joblib库,需要导入Pipeline模块。 3. from sklearn.preprocessing import StandardScaler, LabelEncoder, OneHotEncoder:在保存或加载经过预处理的数据时,可能需要导入数据预处理器的模块,如标准化Scaler、标签编码器LabelEncoder和独热编码器OneHotEncoder,具体根据数据预处理的需求而定。 4. from sklearn.model_selection import GridSearchCV:如果在保存或加载经过网格搜索的模型时需要使用joblib库,需要导入GridSearchCV模块。 5. from sklearn.ensemble import RandomForestClassifier:如果在保存或加载随机森林(Random Forest)分类器时需要使用joblib库,需要导入RandomForestClassifier模块。 需要注意的是,从scikit-learn 0.23版本开始,joblib长期以来被认为是scikit-learn库的一部分,因此可以直接通过`import joblib`导入,而不需要再从`externals`子模块中导入。 ### 回答3: 在使用joblib的时候,我们通常需要导入以下几个sklearn模块: 1. joblib模块:该模块sklearn用于对模型进行持久化和加载的工具。我们需要导入joblib的dump和load函数来保存和加载模型。示例代码如下: ``` from sklearn.externals import joblib ``` 2. sklearn模块:该模块sklearn的主要模块,其中包含了许多机器学习算法和工具函数。我们需要导入相应的算法和函数,根据具体需要进行选择。例如,如果我们想使用支持向量机算法,则需要导入svm模块: ``` from sklearn import svm ``` 3. sklearn.model_selection模块:该模块sklearn用于模型选择和评估的工具。我们需要导入train_test_split函数来进行训练集和测试集的划分。示例代码如下: ``` from sklearn.model_selection import train_test_split ``` 4. sklearn.metrics模块:该模块sklearn用于模型评估的工具。我们需要导入相应的评估指标函数,例如accuracy_score来计算分类准确率。示例代码如下: ``` from sklearn.metrics import accuracy_score ``` 综上所述,我们通常需要导入joblib、sklearnsklearn.model_selection和sklearn.metrics这几个模块来使用joblib和sklearn的相关功能和算法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值