当前位置: 首页 > news >正文

网站备案服务营销网站怎样做

网站备案服务,营销网站怎样做,网站建设的公司怎么做,湘西 网站 建设 公司【Python】数据挖掘与机器学习(一) 大家好 我是寸铁#x1f44a; 总结了一篇【Python】数据挖掘与机器学习(一)sparkles: 喜欢的小伙伴可以点点关注 #x1f49d; 【实验1】预测鲍鱼年龄 问题描述 请从一份数据中预测鲍鱼的年龄#xff0c;数据集在abalone.cvs中#xff…【Python】数据挖掘与机器学习(一) 大家好 我是寸铁 总结了一篇【Python】数据挖掘与机器学习(一)sparkles: 喜欢的小伙伴可以点点关注 【实验1】预测鲍鱼年龄 问题描述 请从一份数据中预测鲍鱼的年龄数据集在abalone.cvs中数据集一共有4177 个样本每个样本有9个特征。其中rings为鲍鱼环数鲍鱼每一年长一环类似树轮是预测 变量sex属性已经经过处理M1表示雄性、F-1表示雌性、I0表示幼体。 有9列数据分别是: 要求 (1)给出回归模型给出线性回归模型的回归系数以及 (2)需要分训练数据与测试数据采用训练数据学习给出R2采用测试数据计算MSE. 代码 import sklearn import tensorflow as tf import numpy as np import pandas import sklearn.model_selection as ms import matplotlib.pyplot as pltdef main():df pandas.read_csv(abalone.csv)df df.valuesy df[:, [-1]].astype(float32) # 提取第9 列x df[:, 1:8].astype(float32) # 提取1-8 列sex df[:, 0].astype(float32) # 取出第0 列后续要转换成2 个哑元male sex 1female sex -1oneMa np.zeros((len(sex), 1), dtypefloat32) # 雄性oneFe np.zeros((len(sex), 1), dtypefloat32) # 雌性oneMa[male] 1oneFe[female] 1ones np.ones((len(x), 1), dtypefloat32) # 全是 1 的向量x np.hstack((ones, oneMa, oneFe, x)) # 凑成一个 X 大矩阵print(x.shape)rows, cols x.shapeweight tf.Variable(tf.random.normal([cols, 1]), nameweight)# 生成一个 包含 bias 的 weight对应 x 的列数def loss_fn(X, y):y_ tf.matmul(X, weight)assert (y.shape y_.shape) # 确认维数一致这一步很容易出错return tf.reduce_mean(tf.square(y_ - y)) / 2x_train, x_test, y_train, y_test ms.train_test_split(x, y, test_size0.3, random_state32)print(x_train.shape)print(x_test.shape)print(y_train.shape)print(y_test.shape)print(weight)yy_ tf.matmul(x_train, weight)err sklearn.metrics.mean_squared_error(y_train, yy_)print(f训练集 MSE {err})y_ tf.matmul(x_test, weight)err sklearn.metrics.mean_squared_error(y_test, y_)print(f测试集 MSE {err}) # 测试集的 MSER2 sklearn.metrics.r2_score(y_train, yy_)print(fR2 {R2})plt.show()【实验2】成年男性的听力实验 数据集hearing_test.csv 是对 5000 名参与者进行了一项实验以研究年龄和身体健康对听力损失的影响尤其是听高音的能力。此数据显示了研究结果对参与者进行了身体能力的评估和评分然后必须进行音频测试通过/不通过以评估他们听到高频的能力。 特征1.年龄age2. 健康得分physical_score 标签1通过/0不通过 要求 (1)采用以下方法读取数据并给出可视化的显示效果 import seaborn as sns import pandas as pd (绘图包, pip install seaborn) import matplotlib.pyplot as plt df pd.read_csv(hearing_test.csv) sns.scatterplot(xage,yphysical_score,datadf,huetest_result) sns.pairplot(df,huetest_result) plt.show() 由于show默认是阻塞看完图后要把它放在代码最后面 (2)采用以下方法得到数据 df df.values x df[:, [0, 1]] 头两列对应age与physical_score - 3 - y df[:, 2] 第三列对应是否通过 (3)把数据拆分为训练集与测试集最后采用测试数据来验证模型 from sklearn.model_selection import train_test_split x_train, x_test, y_train, y_test train_test_split(x, y, test_size0.4, random_state2022) (4)给出Logistic回归分类方法给出二分类模型的权重给出测试数据的散点图 (5)模型性能评估给出训练集与测试集的准确率 Accuracy、精确度 Precision 和召 回率Recall、F1score。 (6)选做给出两类数据的分割直线。 代码 import seaborn as sns import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split from tensorflow.python.ops.confusion_matrix import confusion_matrix from sklearn.metrics import accuracy_score from sklearn.metrics import precision_score from sklearn.metrics import recall_score from sklearn.metrics import f1_scoredf pd.read_csv(hearing_test.csv) testA df[df[test_result] 0].values testB df[df[test_result] 1].values sns.scatterplot(xage, yphysical_score, datadf, huetest_result) sns.pairplot(df, huetest_result) df df.values x df[:, [0, 1]] # 头两列对应 age 与 physical_score y df[:, 2] # 第三列对应是否通过 x_train, x_test, y_train, y_test train_test_split(x, y,test_size0.4, random_state2022) model LogisticRegression(fit_interceptTrue).fit(x_train, y_train) weight model.coef_ bias model.intercept_ print(权重, weight, bias) print(训练集准确率:, model.score(x_train, y_train)) print(测试集准确率:, model.score(x_test, y_test)) y_pred model.predict(x_test) print(混淆矩阵\n, confusion_matrix(y_test, y_pred))print(accuracy:, accuracy_score(y_test, y_pred)) print(precision:, precision_score(y_test, y_pred)) print(recall:, recall_score(y_test, y_pred)) print(f1 score:, f1_score(y_test, y_pred)) x1_boundary, x2_boundary [], []plt.figure() plt.scatter(x1_boundary, x2_boundary, cb, s10) plt.scatter(testA[:, 0], testA[:, 1], cr, s1) plt.scatter(testB[:, 0], testB[:, 1], cg, s1) plt.show() 看到这里的小伙伴恭喜你又掌握了一个技能 希望大家能取得胜利坚持就是胜利 我是寸铁我们下期再见 往期好文 保姆级教程 【保姆级教程】Windows11下go-zero的etcd安装与初步使用 【保姆级教程】Windows11安装go-zero代码生成工具goctl、protoc、go-zero 【Go-Zero】手把手带你在goland中创建api文件并设置高亮 报错解决 【Go-Zero】Error: user.api 27:9 syntax error: expected ‘:‘ | ‘IDENT‘ | ‘INT‘, got ‘(‘ 报错解决方案及api路由注意事项 【Go-Zero】Error: only one service expected goctl一键转换生成rpc服务错误解决方案 【Go-Zero】【error】 failed to initialize database, got error Error 1045 (28000):报错解决方案 【Go-Zero】Error 1045 (28000): Access denied for user ‘root‘‘localhost‘ (using password: YES)报错解决方案 【Go-Zero】type mismatch for field “Auth.AccessSecret“, expect “string“, actual “number“报错解决方案 【Go-Zero】Error: user.api 30:2 syntax error: expected ‘)‘ | ‘KEY‘, got ‘IDENT‘报错解决方案 【Go-Zero】Windows启动rpc服务报错panic:context deadline exceeded解决方案 Go面试向 【Go面试向】defer与time.sleep初探 【Go面试向】defer与return的执行顺序初探 【Go面试向】Go程序的执行顺序 【Go面试向】rune和byte类型的认识与使用 【Go面试向】实现map稳定的有序遍历的方式
http://www.zqtcl.cn/news/608364/

相关文章:

  • 政协网站法治建设版块设计头像 制作 免费
  • wordpress 去除下划线成都seo公司排名
  • 网站移动页面怎么做万网域名管理入口
  • 吴桥网站建设公司wordpress 不收录设置
  • 长安网站建设工作总结信息安全网站建设方案书
  • seo公司网站wordpress 功能块
  • 手机网站分辨率做多大做羞羞的网站
  • 网站挂到国外服务器地址重庆网络公司排行榜
  • 网站seo诊断优化方案好网站的建设标准
  • 惠东县网站建设WordPress版本识别
  • 网站服务器信息查询宝塔系统怎么建设网站
  • 企业做网站需要提供什么资料桂林微物网络科技有限公司
  • 网站建设淘宝评价学校门户网站
  • 网页制作与网站管理amp 网站开发
  • 青岛手机网站建设公司房屋装修预算明细表格
  • 企业内部网站设计手机网站建设费用价格
  • 苏州高端网站建设公司建筑人才网报名平台
  • 商品网站开发需求表乐清公共
  • 省级示范校建设网站网站制作企业有哪些公司
  • 单位做网站怎么做510企业网站系统源码
  • 福建人力资源建设网站未成年在线观看视频播放免费
  • 网站站内logo怎么做朋友圈广告30元 1000次
  • 绍兴做网站北京做公司网站
  • 青浦区网站建设公司商丘网站建设费用
  • 百度网站是怎么建设的wordpress媒体主题
  • 孝感网站建设xgsh国内比百度好的搜索引擎
  • 阅读网站怎样做网站右侧固定标题怎么做
  • 网站开发多少钱农民wordpress acf破解版
  • 厦门网站建设培训云南最便宜的网站建设
  • 吉安手机网站建设html网页布局