each

使用 sklearn 构建决策树并使用 Graphviz 绘制树结构

让人想犯罪 __ 提交于 2019-11-28 11:32:13
1. 概述 之前两篇日志,我们系统性的介绍了决策树的构建算法、构建流程、展示与决策: 决策树的构建算法 – ID3 与 C4.5 算法 决策树的构建、展示与决策 本文,我们来介绍如何使用 sklearn 构建决策树。 2. sklearn 之前我们已经介绍和使用过 python 的 sklearn 包: k 近邻算法 sklearn 也提供了决策树明星,用于解决分类和回归问题。 http://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html。 3. sklearn.tree.DecisionTreeClassifier 构造参数 sklearn.tree.DecisionTreeClassifier 类就是我们需要的决策树类,它具有如下构造参数: ####sklearn.tree.DecisionTreeClassifier 类构造参数 参数名 类型 可选参数 默认值 说明 criterion string ‘gini’、‘entropy’ ‘gini’ 构建决策树算法,基尼不纯度准则(CART 算法)或信息熵准则(C4.5算法) splitter string ‘best’、‘random’ ‘random’ 决策树分支选取原则,全局最优或选取随机局部最优点 max

Python常用小技巧(五)——批量读取json文件

不想你离开。 提交于 2019-11-28 10:58:13
Python常用小技巧(五)——批量读取json文件 前言: 其实Python能够批量读取很多文件,这里,本人以json文件为例(json是标注图片时生成的文件,记录有标注的坐标和标签,友情推荐标注图片的工具:labelme),读取想要的数据。大家也可以稍做修改,去读取其他类型的文件。 一、材料准备 - Python - os - json 二、代码编写 首先我们来观察一下我们需要处理的json文件 打开json文件,我们可以看到一下内容 我们需要获取的信息是 label 后面标注的种类,还有坐标信息 期望输出的格式是: 结构: n.json x1,y1,x2,y2,lable1 x1,y1,x2,y2,label2 样例: 21.json 203,1,511,116,shoes 248,2,350,44,welt 所以,知道标准后,我们的代码如下: # -*- coding:utf8 -*- import json from os import listdir import os path = '/home/ljt/Documents/labelme' filelist = listdir(path) #for i in filelist: #print(filelist[0].split(".")[0]) # i.split() fileIndex =[]

MongoDB aggregate, how to addToSet each element of array in group pipeline

怎甘沉沦 提交于 2019-11-28 09:56:05
问题 I have documents that contains a tags fields. It's a simple array with tag names inside, no object nor _id inside. Just plain tags like this ["Protocol", "Access", "Leverage", "Capability"] . And in my group pipeline I tried something like 'selectedTags': { $addToSet: '$tags' } but then I end up with an array containing arrays of tags. And I get the same with $push . I tried to use $each or $pushAll but they are not supported as grouping operator as my shell tell me. Can someone help me on

How to append multiple file inputs to a FormData object using $.each?

余生颓废 提交于 2019-11-28 09:13:09
I have a multiple (and dynamic) number of inputs of type=file . I want to create a FormData object out of them. I need to manually append them to the object as I need access to their filenames for inserting into a database and therefore need to specify a filename is this format: myFormData.append(name,file,filename); HTML <form id="my_form" enctype="multipart/form-data"> <input type="file" name="undefined" id="file_1" data-filename="image.jpg"> <input type="file" name="undefined" id="file_2" data-filename="image2.jpg"> <button>click</button> </form> jQuery var myFormData = new FormData(); $

jQuery.each implementation differs from native Array.forEach

社会主义新天地 提交于 2019-11-28 09:02:26
Does anyone why is the otherwise excellent jQuery.each function is designed differently from the (now) native Array.forEach ? F.ex: var arr = ['abc','def']; arr.forEach(function(entry, index) { console.log(entry); // abc / def }); This makes absolute sense. But jQuery chose to put the index as first argument: $.each(arr, function(index, entry) { console.log(entry); }); Does anyone know the reasoning behind this design decision? I have always used $.each extensively, but it always bugged me that the index was the first argument as it is rarely used. I know jQuery implemented a direct reference

jQuery each method does not return value

送分小仙女□ 提交于 2019-11-28 08:45:18
问题 $(document).ready(function() { $('#commentForm').submit(function(){ return $('input[type=text], textarea').each(function(index){ if($(this).attr('value') == ""){ alert(msgHash[$(this).attr('id')]); return false; }else{ if(!$(this).attr('value').match(validateHash[$(this).attr('id')])){ //Do nothing alert(msgOnError[$(this).attr('id')]); return false; } } }); return true; }); }); Here msgOnError, msgHash and msgHash are map that I use to get messages for each text box with particular ID

POJ -1144 Network(Tarjan,割点)

拟墨画扇 提交于 2019-11-28 08:35:03
Network Time Limit: 1000MS Memory Limit: 10000K Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power

PAT A1011 World Cup Betting

空扰寡人 提交于 2019-11-28 07:47:38
PAT A1011 World Cup Betting 题目描述:   With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets. Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for

about ruby range?

一笑奈何 提交于 2019-11-28 07:03:14
问题 like this range = (0..10) how can I get number like this: 0 5 10 plus five every time but less than 10 if range = (0..20) then i should get this: 0 5 10 15 20 回答1: Try using .step() to go through at a given step. (0..20).step(5) do |n| print n,' ' end gives... 0 5 10 15 20 As mentioned by dominikh, you can add .to_a on the end to get a storable form of the list of numbers: (0..20).step(5).to_a 回答2: Like Dav said, but add to_a: (0..20).step(5).to_a # [0, 5, 10, 15, 20] 回答3: The step method

poj1144 割点割边问题 dfs暴力

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 05:03:06
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does