关于:cross_validation.scores
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 10 08:10:35 2016 @author: Administrator
"""
'''
关于:cross_validation.scores
此处cross_validation.scores并不是cross_validation的scores,
而是分类函数(本文是clf,svm)的scores
分成K部分
K-1是训练
1次是测试
共K个scores
''' import time
import numpy as np
from sklearn import cross_validation
from sklearn import datasets
from sklearn import svm start = time.time()
iris = datasets.load_iris()
print iris.data.shape, iris.target.shape
#(150L, 4L) (150L,) X_train, X_test, y_train, y_test = cross_validation.train_test_split(iris.data, iris.target, test_size=0.4, random_state=0)
print X_train.shape, y_train.shape
print X_test.shape, y_test.shape
#(90L, 4L) (90L,)
#(60L, 4L) (60L,) clf = svm.SVC(kernel='linear', C=1).fit(X_train, y_train)
print clf.score(X_test, y_test)
#0.966666666667 #模块2
clf = svm.SVC(kernel='linear', C=1)
scores = cross_validation.cross_val_score(clf, iris.data, iris.target, cv=5)
print scores
#[ 0.96666667 1. 0.96666667 0.96666667 1. ]
print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))
#Accuracy: 0.98 (+/- 0.03) #模块3
from sklearn import metrics
scores = cross_validation.cross_val_score(clf, iris.data, iris.target,cv=5, scoring='f1_weighted')
print scores
#[ 0.96658312 1. 0.96658312 0.96658312 1. ] print("Took %.2f seconds for" % ((time.time() - start)))
关于:cross_validation.scores的更多相关文章
- [LeetCode] Rank Scores 分数排行
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- Codeforces Round #370 (Div. 2) D. Memory and Scores DP
D. Memory and Scores Memory and his friend Lexa are competing to get higher score in one popular c ...
- Faster RCNN 运行自己的数据,刚开始正常,后来就报错: Index exceeds matrix dimensions. Error in ori_demo (line 114) boxes_cell{i} = [boxes(:, (1+(i-1)*4):(i*4)), scores(:, i)];
function script_faster_rcnn_demo() close all; clc; clear mex; clear is_valid_handle; % to clear init ...
- LeetCode Database: Rank Scores
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- LeetCode:Rank Scores
做到这题时卡了不少时间,参考了别人的解法,觉得挺不错的,还挺巧妙. SELECT s2.Score,s1.Rank From ( SELECT S1.Score, COUNT(*) as Rank F ...
- (Problem 22)Names scores
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...
- Memory and Scores
Memory and Scores 题目链接:http://codeforces.com/contest/712/problem/D dp 因为每轮Memory和Lexa能取的都在[-k,k],也就是 ...
- anacoda报错No module named 'sklearn.cross_validation'
在目前的snacoda里集成的sklearn已经不存在cross_validation模块了 使用以下模块 from sklearn.model_selection import train_te ...
- [SQL]LeetCode178. 分数排名 | Rank Scores
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
随机推荐
- django学习笔记整理(2)django的路由系统
创建一个属于你的django框架.django-admin startproject 框架名 打开你的django框架,你会发现里面还有一个和框架名同名的文件夹,那个文件夹就称为一个app. 创建了d ...
- SpringMVC中使用ModelAndView遇到的问题
本文记录我在SpringMVC中使用ModelAndView,添加模型数据到ModelAndView中时遇到的问题: 1.jsp页面用EL表达式来获取值时直接显示EL表达式,JSP不解析EL表达式: ...
- ReverseInteger
public class ReverseInteger { public static int reverse(int x) { long ret = 0; //如果是个位数,直接返回. if(x/1 ...
- tp后台注册登录配置项
1.在application目录下Common/Conf/config.php中 2-17行,首先判断在data目录下有没有特意设置的db.php, config.php,route.php,如果有就 ...
- shitf+tab
在eclipse中,shitf+tab可以使代码向左移动.
- JS内存知识点汇总
废话片: 讲到内存可以联想到很多,内存分配管理,内存回收机制,内存泄露等等,今天我们就来答题的总结一下. 正文片: 1.内存分配管理 2.内存回收机制 3.内存泄露 一.内存分配管理 首先让我们看看内 ...
- LeetCode OJ:Contains DuplicateII(是否包含重复II)
Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...
- hdoj-1027-Ignatius and the Princess II(逆康拓展开)
题目链接 /* Name: Copyright: Author: Date: 2018/5/2 11:07:16 Description:输出第m小的序列 */ #include <iostre ...
- 2018.7.26 学会说NO,拒绝道德绑架。
一.领导交给你一项不属于你工作范围的工作,是否需要拒绝,你可以考虑以下问题: 1.这是与我核心能力相关的工作吗?是,接受:否,进入下一条: 2.它能帮助我拓展我核心能力的边界,或是我感兴趣的吗?是,接 ...
- BEC listen and translation exercise 11
When you are in any contest you should work as if there were — to the very last minute — a chance to ...