make_classification创建用于分类的数据集,官方文档

例子:

### 创建模型
def create_model(): # 生成数据
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=10000, # 样本个数
n_features=25, # 特征个数
n_informative=3, # 有效特征个数
n_redundant=2, # 冗余特征个数(有效特征的随机组合)
n_repeated=0, # 重复特征个数(有效特征和冗余特征的随机组合)
n_classes=3, # 样本类别
n_clusters_per_class=1, # 簇的个数
random_state=0) print("原始特征维度",X.shape) # 读取数据
print("读取数据")
#import pandas as pd
#data = pd.read_csv(datapath) # 数据划分
print("数据划分")
from sklearn.model_selection import train_test_split
global x_train,x_valid,x_test,y_train,y_valid,y_test
x_train,x_test,y_train,y_test = train_test_split(X,y,random_state = 33,test_size = 0.25)
x_train,x_valid,y_train,y_valid = train_test_split(x_train,y_train,random_state = 33,test_size = 0.25) # 创建模型
print("创建模型")
from sklearn.linear_model import LogisticRegression
global model
model = LogisticRegression(penalty = 'l2').fit(x_train,y_train) ### 保存模型
def save_model():
print("保存模型")
from sklearn.externals import joblib
joblib.dump(model,'model.pkl') ### 模型验证
def validate_model():
print("模型验证")
print(model.score(x_valid,y_valid)) ### 模型预测
def predict_model():
print("模型预测")
global pred
pred = model.predict_proba(x_test)
print(pred) if __name__ == "__main__":
create_model()
save_model()
validate_model()
predict_model()

  

from sklearn.datasets import make_classification创建分类数据集的更多相关文章

  1. 实验一 使用sklearn的决策树实现iris鸢尾花数据集的分类

    使用sklearn的决策树实现iris鸢尾花数据集的分类 要求: 建立分类模型,至少包含4个剪枝参数:max_depth.min_samples_leaf .min_samples_split.max ...

  2. sklearn提供的自带的数据集

    sklearn 的数据集有好多个种 自带的小数据集(packaged dataset):sklearn.datasets.load_<name> 可在线下载的数据集(Downloaded ...

  3. Python——sklearn提供的自带的数据集

    sklearn提供的自带的数据集 sklearn 的数据集有好多个种 自带的小数据集(packaged dataset):sklearn.datasets.load_<name> 可在线下 ...

  4. 【sklearn】网格搜索 from sklearn.model_selection import GridSearchCV

    GridSearchCV用于系统地遍历模型的多种参数组合,通过交叉验证确定最佳参数. 1.GridSearchCV参数    # 不常用的参数 pre_dispatch 没看懂 refit 默认为Tr ...

  5. 【sklearn】from sklearn.extermals import joblib(保存模型和加载模型)

    原创博文,转载请注明出处! sklearn中保存和加载模型的方法 1.载入模块 from sklearn.externals joblib. model = joblib. # -*- coding: ...

  6. (数据科学学习手札21)sklearn.datasets常用功能详解

    作为Python中经典的机器学习模块,sklearn围绕着机器学习提供了很多可直接调用的机器学习算法以及很多经典的数据集,本文就对sklearn中专门用来得到已有或自定义数据集的datasets模块进 ...

  7. sklearn训练感知器用iris数据集

    简化版代码 from sklearn import datasets import numpy as np #获取data和类标 iris = datasets.load_iris() X = iri ...

  8. 特征选取1-from sklearn.feature_selection import SelectKBest

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  9. sklearn datasets模块学习

    sklearn.datasets模块主要提供了一些导入.在线下载及本地生成数据集的方法,可以通过dir或help命令查看,我们会发现主要有三种形式:load_<dataset_name>. ...

随机推荐

  1. centos配置yum源为中国镜像源

    有时候CentOS默认的yum源不一定是国内镜像,导致yum在线安装及更新速度不是很理想.这时候需要将yum源设置为国内镜像站点.国内主要开源的开源镜像站点应该是网易和阿里云了. 修改CentOS默认 ...

  2. JAVA基础补漏--List

    Arraylist 通过对ArrayList的源码的查看,他的底层实现是对数组进行数据的操作,所以他的数据特点同数组. 查询快,因为他的内存区域为一个整块,可直接根据索引进行查询. 增删慢,因为每次增 ...

  3. RunLoop Note

    I. Begin from Apple Document Apple describes the priciples of runloop in Threading Programming Guide ...

  4. Centos中使用Jenkins执行gulp命令:command not found

    在Centos操作系统,使用Jenkins的pipeline执行发布流程:jenkinsfile如下: stage("前端项目构架gulp") { steps { dir('src ...

  5. HTML符号大全

      HTML特殊字符编码大全:往网页中输入特殊字符,需在html代码中加入以&开头的字母组合或以&#开头的数字.下面就是以字母或数字表示的特殊符号大全.                 ...

  6. 使用python编写微信跳一跳的自动脚本

    实现思路: 调用adb命令,截图 寻找小小人的底部中心点role(从下到上扫描,直到找到小小人相同像素的点,至于小小人像素点rgb是什么,可以使用photoshop查看) 寻找棋盘最高点top,然后寻 ...

  7. 1059: [ZJOI2007]矩阵游戏 二分图匹配

    https://www.lydsy.com/JudgeOnline/problem.php?id=1059 裸的二分图匹配,行列匹配即可 /****************************** ...

  8. 三十一 Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行、scrapy-splash、splinter

    1.chrome谷歌浏览器无界面运行 chrome谷歌浏览器无界面运行,主要运行在Linux系统,windows系统下不支持 chrome谷歌浏览器无界面运行需要一个模块,pyvirtualdispl ...

  9. 1023: Pong’s Birds(概率)

    1023: Pong’s Birds 时间限制: 1 Sec  内存限制: 128 MB提交: 94  解决: 21[提交][状态][讨论版] 题目描述 In order to train his b ...

  10. 玲珑oj 1129 ST

    1129 - 喵哈哈村的战斗魔法师丶坏坏い月 Time Limit:3s Memory Limit:256MByte Submissions:490Solved:107 DESCRIPTION 坏坏い ...