Download datasets iris_training.csv from:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/tutorials/monitors

Method: SVR

# -*- coding: utf-8 -*-

import pandas as pd
from sklearn.grid_search import GridSearchCV
from sklearn import svm, datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.utils import shuffle
import numpy as np
from sklearn import metrics
df = pd.read_csv('iris_training.csv', header=0)
parameters = {'kernel':['rbf'], 'gamma':np.logspace(-5, 0, num=6, base=2.0),'C':np.logspace(-5, 5, num=11, base=2.0)}
grid_search = GridSearchCV(svm.SVR(), parameters, cv=10, n_jobs=4, scoring='mean_squared_error') X = df[df.columns.drop('virginica')]
y = df['virginica'] X_train, X_test, y_train, y_test = train_test_split(\
X, y, test_size=0.3, random_state=42) random_seed = 13
X_train, y_train = shuffle(X_train, y_train, random_state=random_seed)
X_scaler = StandardScaler()
X_train = X_scaler.fit_transform(X_train)
X_test = X_scaler.transform(X_test) grid_search.fit(X_train,y_train)
y_pred = grid_search.predict(X_test) print 'mean_squared_error:'+str(metrics.mean_squared_error(y_test,y_pred)),\
'r2_score:'+str(metrics.r2_score(y_test,y_pred))

Neural Network:

# -*- coding: utf-8 -*-

import pandas as pd
from sklearn.grid_search import GridSearchCV
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.utils import shuffle
import numpy as np
from sklearn import metrics
from sklearn.neural_network import MLPRegressor
df = pd.read_csv('iris_training.csv', header=0) #neural networks for regresion
parameters = {'hidden_layer_sizes':[200,250,300,400,500,600], 'activation':['relu']}
grid_search = GridSearchCV(MLPRegressor(), parameters, cv=10, n_jobs=4, scoring='mean_squared_error') X = df[df.columns.drop('virginica')]
y = df['virginica'] X_train, X_test, y_train, y_test = train_test_split(\
X, y, test_size=0.3, random_state=42) random_seed = 13
X_train, y_train = shuffle(X_train, y_train, random_state=random_seed)
X_scaler = StandardScaler()
X_train = X_scaler.fit_transform(X_train)
X_test = X_scaler.transform(X_test) grid_search.fit(X_train,y_train)
y_pred = grid_search.predict(X_test) print 'mean_squared_error:'+str(metrics.mean_squared_error(y_test,y_pred)),\
'r2_score:'+str(metrics.r2_score(y_test,y_pred))

数据标准化+网格搜索+交叉验证+预测(Python)的更多相关文章

  1. scikit-learn一般实例之一:绘制交叉验证预测

    本实例展示怎样使用cross_val_predict来可视化预测错误: # coding:utf-8 from pylab import * from sklearn import datasets ...

  2. 机器学习之路:python 网格搜索 并行搜索 GridSearchCV 模型检验方法

    git:https://github.com/linyi0604/MachineLearning 如何确定一个模型应该使用哪种参数? k折交叉验证: 将样本分成k份 每次取其中一份做测试数据 其他做训 ...

  3. 十折交叉验证10-fold cross validation, 数据集划分 训练集 验证集 测试集

    机器学习 数据挖掘 数据集划分 训练集 验证集 测试集 Q:如何将数据集划分为测试数据集和训练数据集? A:three ways: 1.像sklearn一样,提供一个将数据集切分成训练集和测试集的函数 ...

  4. 机器学习--K折交叉验证和非负矩阵分解

    1.交叉验证 交叉验证(Cross validation),交叉验证用于防止模型过于复杂而引起的过拟合.有时亦称循环估计, 是一种统计学上将数据样本切割成较小子集的实用方法. 于是可以先在一个子集上做 ...

  5. 支持向量机(SVM)利用网格搜索和交叉验证进行参数选择

    上一回有个读者问我:回归模型与分类模型的区别在哪?有什么不同,我在这里给他回答一下 : : : : 回归问题通常是用来预测一个值,如预测房价.未来的天气情况等等,例如一个产品的实际价格为500元,通过 ...

  6. libsvm交叉验证与网格搜索(参数选择)

    首先说交叉验证.交叉验证(Cross validation)是一种评估统计分析.机器学习算法对独立于训练数据的数据集的泛化能力(generalize), 能够避免过拟合问题.交叉验证一般要尽量满足:1 ...

  7. Python之网格搜索与检查验证-5.2

    一.网格搜索,在我们不确定超参数的时候,需要通过不断验证超参数,来确定最优的参数值.这个过程就是在不断,搜索最优的参数值,这个过程也就称为网格搜索. 二.检查验证,将准备好的训练数据进行平均拆分,分为 ...

  8. 机器学习 - 案例 - 样本不均衡数据分析 - 信用卡诈骗 ( 标准化处理, 数据不均处理, 交叉验证, 评估, Recall值, 混淆矩阵, 阈值 )

    案例背景 银行评判用户的信用考量规避信用卡诈骗 ▒ 数据 数据共有 31 个特征, 为了安全起见数据已经向了模糊化处理无法读出真实信息目标 其中数据中的 class 特征标识为是否正常用户 (0 代表 ...

  9. Python机器学习笔记 Grid SearchCV(网格搜索)

    在机器学习模型中,需要人工选择的参数称为超参数.比如随机森林中决策树的个数,人工神经网络模型中隐藏层层数和每层的节点个数,正则项中常数大小等等,他们都需要事先指定.超参数选择不恰当,就会出现欠拟合或者 ...

随机推荐

  1. 解析Django路由层URLconf

    目录: 一  Django中路由的作用 二  路由的分组 三  路由分发 四  反向解析 五  名称空间 六  Django2.0版的path 一.Django中路由的作用 URL配置(URLconf ...

  2. PHP 内置函数fgets读取文件

    php fgets()函数从文件指针中读取一行 语法: fgets(file,length) 参数 描述 file  必需.规定尧要读取的文件 length 可选 .规定尧都区的字节数.默认是102字 ...

  3. 【Python】【有趣的模块】【Requests】session & cookie

    保存http请求的状态(请求的上下文) [区别&联系] 1. cookie保存在客户端的浏览器,比如标识是哪个请求者.购物车应用等 session保存在服务端,http连接时无则创建,有则用现 ...

  4. Unity--game

    打怪兽--头像状态 Git :https://github.com/vinieo/attck 打怪兽--背景音乐音量 Git :https://github.com/vinieo/ack_bgm 小球 ...

  5. _gift

    time 本次上线后在线时长,单位:秒 rewId 奖励模板ID,对应_rew表中rewId notice 弹窗内容,为空不弹窗

  6. Codeforces Round #267 (Div. 2) D. Fedor and Essay tarjan缩点

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Java Virtual Machine(Java虚拟机)

    JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的. Java语言 ...

  8. Linux下HBase和Maven的环境搭建

    Maven环境部署如下: maven下载并进行环变量配置 export MAVEN_HOME=/home/hadoop/app/apache-maven-3.3.9export PATH=$MAVEN ...

  9. linux基础02-bash特性

    Linux的行结束符是:[$] Windows的行结束符是:[$+回车] 目录管理:ls.cd.pwd.mkdir.rmdir.tree 文件管理:touch.stat.file.rm.cp.mv.n ...

  10. 最大的矩形面积 Maximal Rectangle

    2018-09-15 10:23:44 一.Largest Rectangle in Histogram 在求解最大的矩形面积之前,我们先讨论一条最大直方图面积的问题. 问题描述: 问题求解: 解法一 ...