博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
机器学习模型的保存和读取
阅读量:4303 次
发布时间:2019-05-27

本文共 678 字,大约阅读时间需要 2 分钟。

import osfrom sklearn.ensemble import RandomForestClassifierfrom sklearn import datasetsfrom sklearn.metrics import accuracy_scoreimport picklefrom sklearn.model_selection import train_test_splitsheet = datasets.load_wine()x,y=sheet.data,sheet.targetclf = RandomForestClassifier(n_estimators=14,random_state=1,max_depth=5)xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.2,random_state=1)clf.fit(xtrain,ytrain)# 保存模型file_path = os.path.dirname(os.path.realpath(__file__))with open ('clf.pickle', 'wb') as f:	pickle.dump(clf,f)# 读取模型with open ('clf.pickle', 'rb') as f:	clf = pickle.load(f)	y_pred=clf.predict(xtest)	print(accuracy_score(ytest,y_pred))```python在这里插入代码片

转载地址:http://ywhws.baihongyu.com/

你可能感兴趣的文章
动态分区最佳实践(一定要注意实践场景)
查看>>
HIVE—索引、分区和分桶的区别
查看>>
Hive进阶总结(听课总结)
查看>>
大数据领域两大最主流集群管理工具Ambari和Cloudera Manger
查看>>
Sqoop往Hive导入数据实战
查看>>
Mysql到HBase的迁移
查看>>
Sqoop import进阶
查看>>
Hive语句是如何转化成MapReduce任务的
查看>>
Hive创建table报错:Permission denied: user=lenovo, access=WRITE, inode="":suh:supergroup:rwxr-xr-x
查看>>
Hive执行job时return code 2排查
查看>>
hive常用函数及数据结构介绍
查看>>
Hive面试题干货(亲自跟着做了好几遍,会了的话对面试大有好处)
查看>>
力扣题解-230. 二叉搜索树中第K小的元素(递归方法,中序遍历解决)
查看>>
力扣题解-123. 买卖股票的最佳时机 III(动态规划)
查看>>
Django 源码阅读:服务启动(wsgi)
查看>>
Django 源码阅读:url解析
查看>>
Docker面试题(一)
查看>>
第一轮面试题
查看>>
2020-11-18
查看>>
Docker面试题(二)
查看>>