# -*- 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的更多相关文章

  1. [LeetCode] Rank Scores 分数排行

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. LeetCode:Rank Scores

    做到这题时卡了不少时间,参考了别人的解法,觉得挺不错的,还挺巧妙. SELECT s2.Score,s1.Rank From ( SELECT S1.Score, COUNT(*) as Rank F ...

  6. (Problem 22)Names scores

    Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...

  7. Memory and Scores

    Memory and Scores 题目链接:http://codeforces.com/contest/712/problem/D dp 因为每轮Memory和Lexa能取的都在[-k,k],也就是 ...

  8. anacoda报错No module named 'sklearn.cross_validation'

    在目前的snacoda里集成的sklearn已经不存在cross_validation模块了 使用以下模块 from  sklearn.model_selection  import train_te ...

  9. [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 ...

随机推荐

  1. PrintWriter的使用

    java.io.PrintWriter 具有自动行刷新的缓冲字符输出流,特点是可以按行写出字符串,并且可以自动行刷新. java.io.BufferedWriter是缓冲字符输出流,内部有缓冲区可以进 ...

  2. ajax_基础

    ajax  请求过程 1.准备发送请求 2.填写请求地址和数据 3.请请求到服务器 4.等待服务器处理数据. 5.接受服务器返回信息 --------------------------------- ...

  3. wpf 界面平级之间设置上下顺序关系(ZIndex)

    只能用于平级之间设置上下顺序 this.grid1.SetValue(Grid.ZIndexProperty, 9999);                    Panel.SetZIndex(th ...

  4. 程序员怎样迈出从5K到1W的重要一步

    为什么一个相似的功能,大牛一会儿就搞定,然后悠闲地品着下午茶逛淘宝:而自己加班加点搞到天亮还做不完. 为什么用户提出需求变更后,大牛只需潇洒地敲敲键盘,改改配置:而自己将代码改了又改,删了又建,几乎晕 ...

  5. 机器学习(四)—逻辑回归LR

    逻辑回归常见问题:https://www.cnblogs.com/ModifyRong/p/7739955.html 推导在笔记上,现在摘取部分要点如下: (0) LR回归是在线性回归模型的基础上,使 ...

  6. hzau 1204 Escape from the Darkness

    1204: Escape from the Darkness Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 93  Solved: 3[Submit] ...

  7. eclipse配置lombok

    原文:http://wsj356428476.iteye.com/blog/1655032 1.下载Lombok.jar https://projectlombok.org/ 2.运行Lombok.j ...

  8. C#中的BackgroundWorker控件

    C#中的BackgroundWorker控件   Keywords: C# .NET BackgroundWorkerSource: http://txw1958.cnblogs.com/ Backg ...

  9. python的单例模式--解决多线程的单例模式失效

    单例模式 单例模式(Singleton Pattern) 是一种常用的软件设计模式,主要目的是确保某一个类只有一个实例存在.希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场 比如,某个 ...

  10. Leetcode 1014. Capacity To Ship Packages Within D Days

    二分搜索 class Solution(object): def shipWithinDays(self, weights, D): """ :type weights: ...