python机器学习4-5代码及运行结果
来源:互联网 发布:uu淘宝店 编辑:程序博客网 时间:2024/06/10 05:55
import urllib.requestimport matplotlib.pyplot as plotfrom math import sqrt, cos, logtarget_url = ("http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv")data = urllib.request.urlopen(target_url)xList = []labels = []names = []firstLine = Truefor line in data: if firstLine == True: names = line.strip().split(";".encode(encoding='utf-8')) firstLine = False else: row = line.strip().split(";".encode(encoding='utf-8')) labels.append(float(row[-1])) row.pop() floatRow = [float(num) for num in row] xList.append(floatRow) xExtended = []alchCol = len(xList[1])for row in xList: newRow = list(row) alch = row[alchCol - 1]#获取每一行的最后一列数 newRow.append((alch -7) * (alch - 7) / 10)#第一个新属性是((alch - 7) * (alch - 7)) /10,基本上新属性取酒精值的平方 newRow.append(5 * log(alch - 7)) newRow.append(cos(alch)) xExtended.append(newRow)nrow = len(xList)v1 = [xExtended[j][alchCol -1] for j in range(nrow)]for i in range(4):#range与索引相一致,i为0,1,2,3 v2 = [xExtended[j][alchCol - 1 + i] for j in range(nrow)] plot.scatter(v1, v2)plot.xlabel("Alcohol")plot.ylabel(("Extension Functions of Alcohol"))plot.show()
图片显示效果如下:
阅读全文
0 0
- python机器学习4-5代码及运行结果
- python机器学习4-4代码及运行结果
- python机器学习4-6代码及运行结果
- python机器学习及实战代码13-16,程序运行时出现提醒及修改
- python机器学习4—2代码详解及修改
- Python 1行代码实现文本分类(实战笔记),含代码详细说明及运行结果
- 《python机器学习及实践》书籍代码练习
- Python机器学习-感知机原理及代码实现
- python机器学习3-5代码
- python机器学习4-3代码讲解
- 模拟ATM代码及运行结果截图
- 《python机器学习及实践-从零开始通往kaggle竞赛之路(代码Python 3.6 版)》chapter2.1.1.4
- Python机器学习及实践:
- python机器学习与实战中运行代码出现警告的处理
- Qwidget透明相关(仅一点点)附代码及运行结果
- cs231n assigment1 KNN部分代码运行结果及分析
- 机器学习实战 第二章KNN(1)python代码及注释
- KNN算法Python实现(代码来自机器学习实战)及注释
- SPOJ 1557 GSS2 线段树
- 字符串数组的相互转换
- Mac下python路径
- tomcat管理界面登录无法进入
- Tensorflow + ResNet101 + fasterRcnn 训练自己的模型 数据(一)
- python机器学习4-5代码及运行结果
- Eclipse里调出Tomcat server视图
- linux下一个C++线程安全的单例模式
- map函数的应用:UVa156-Ananagrams
- FFmpeg的编译与运行
- python学习刷题
- Android:dimen尺寸资源文件的使用
- 第一次在linux下安装CUDD包及遇见的问题
- ubuntu 17.04 下安装openssh-server报错