莫烦scikit-learn学习自修第六天【特征值矩阵标准化】
1.代码实战
#!/usr/bin/env python #!_*_coding:UTF-8 _*_ import numpy as np from sklearn import preprocessing from sklearn.cross_validation import train_test_split from sklearn.datasets.samples_generator import make_classification from sklearn.svm import SVC import matplotlib.pyplot as plt # 生成样本数据 X, y = make_classification(n_samples=300, # 生层300条训练数据 n_features=2, # 生成两个特征值 n_redundant=0, n_informative=2, # 特征值中有两个是相关的 random_state=22, # 每次运行该脚本生成的数据是一样的 n_clusters_per_class=1, scale=100) # 将特征值矩阵进行标准化,使得特征值小于或等于1 X = preprocessing.scale(X) # 将样本分为训练数据和测试数据 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # 创建训练模型 df = SVC() # 开始训练 df.fit(X_train, y_train) # 使用测试数据对训练结果进行评估 print df.score(X_test, y_test)
结果:
/Users/liudaoqiang/PycharmProjects/numpy/venv/bin/python /Users/liudaoqiang/Project/python_project/sklearn-day06/normalization.py /Users/liudaoqiang/PycharmProjects/numpy/venv/lib/python2.7/site-packages/sklearn/cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20. "This module will be removed in 0.20.", DeprecationWarning) 0.966666666667 Process finished with exit code 0
注意:
对特征值进行标准化后,训练评估打分为0.9以上,不进行特征值标准化,训练评估打分为0.5以下
莫烦scikit-learn学习自修第六天【特征值矩阵标准化】的更多相关文章
- 莫烦大大TensorFlow学习笔记(9)----可视化
一.Matplotlib[结果可视化] #import os #os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf i ...
- 莫烦theano学习自修第六天【回归】
1. 代码实现 from __future__ import print_function import theano import theano.tensor as T import numpy a ...
- 机器学习-scikit learn学习笔记
scikit-learn官网:http://scikit-learn.org/stable/ 通常情况下,一个学习问题会包含一组学习样本数据,计算机通过对样本数据的学习,尝试对未知数据进行预测. 学习 ...
- 莫烦python教程学习笔记——总结篇
一.机器学习算法分类: 监督学习:提供数据和数据分类标签.--分类.回归 非监督学习:只提供数据,不提供标签. 半监督学习 强化学习:尝试各种手段,自己去适应环境和规则.总结经验利用反馈,不断提高算法 ...
- 老男孩python学习自修第六天【pycharm的使用】
1.在工程右键可选新建文件夹,包盒python文件 文件夹和包的区别在于,包包含一个空的__init__.py文件,而文件夹没有 2.pycharm的断点调试 点击Debug表示进入调试状态 点击Re ...
- 莫烦大大keras学习Mnist识别(4)-----RNN
一.步骤: 导入包以及读取数据 设置参数 数据预处理 构建模型 编译模型 训练以及测试模型 二.代码: 1.导入包以及读取数据 #导入包 import numpy as np np.random.se ...
- 莫烦大大keras学习Mnist识别(3)-----CNN
一.步骤: 导入模块以及读取数据 数据预处理 构建模型 编译模型 训练模型 测试 二.代码: 导入模块以及读取数据 #导包 import numpy as np np.random.seed(1337 ...
- 莫烦大大TensorFlow学习笔记(8)----优化器
一.TensorFlow中的优化器 tf.train.GradientDescentOptimizer:梯度下降算法 tf.train.AdadeltaOptimizer tf.train.Adagr ...
- 莫烦python教程学习笔记——保存模型、加载模型的两种方法
# View more python tutorials on my Youtube and Youku channel!!! # Youtube video tutorial: https://ww ...
随机推荐
- IPS简单使用方法
转载:http://blog.csdn.net/zhou1862324/article/details/17512191 IPS(incident packaging service)是11G的新特性 ...
- P1553 数字反转(升级版)(模拟)
花了2个小时,写的..mmp只想说,还是我太菜了. #include<iostream> #include<cstring> using namespace std; ]; i ...
- 010_React-组件的生命周期详解
ReactJS 的核心思想是组件化,即按功能封装成一个一个的组件,各个组件维护自己的状态和 UI,当状态发生变化时,会自定重新渲染整个组件,多个组件一起协作共同构成了 ReactJS 应用. 为了能够 ...
- Spring Security(二十二):6.4 Method Security
From version 2.0 onwards Spring Security has improved support substantially for adding security to y ...
- # 20175329 2018-2019-2 《Java程序设计》第二周学习总结
# 学号 2018-2019-3<Java程序设计>第三周学习总结 ## 教材学习内容总结 第二三章与我们所学习的C语言有很多的相似点,在这里我想主要就以我所学习的效果来讨论一下JAVA与 ...
- SVM-笔记(1)
1 目的 SVM推导是从讨论最优超平面开始的,即为了得到一个能够划分不同超平面的面,即公式1: \begin{equation}w^Tx+b=0 \tag{1} \end{equation} 这个公式 ...
- Insider Dev Tour(2018.06.28)
时间:2018.06.28地点:北京金茂万丽酒店
- 反射那些基础-Class
目录 1 Class 类是什么? 2 如何获取 Class 对象 2.1 Object.getClass() 2.2 .class 语法 2.3 Class.forName() 2.4 通过包装类的 ...
- el-date-picker 快捷日期简单计算
const oneDaySeconds = 3600 * 1000 * 24 pickerOptions: { shortcuts: [ { text: '今天', onClick(picker) { ...
- [C#]关于DataDirectory的一些思考
笔者在使用Entity Framework中的Scaffolding机制自动创建拓展名为mdf的数据库及表单时,遇到如下的错误: A file activation error occurred. T ...