看懂代码的前提需要理解样本空间分布,概率密度,香农熵,条件熵,信息增益等概念,

否则代码看不懂,不理解的可以看以前博客~

1.说明

1.1要实现的类

class CSamplesTool(object)

1.2输入的样本集

输入的样本集,样例由下面的方法提供:

def create_samples():'''提供训练样本集每个example由多个特征值+1个分类标签值组成比如第一个example=['youth', 'no', 'no', '1', 'refuse'],此样本的含义可以解读为:如果一个人的条件是:youth age,no working, no house, 信誉值credit为1那么此类人会被分类到refuse一类中,即在相亲中被拒绝每个example的特征值类型为:['age', 'working', 'house', 'credit']每个example的分类标签class_label取值范围为:'refuse'或者'agree''''data_list = [['youth', 'no',  'no',   '1', 'refuse'],['youth', 'no',  'no',   '2', 'refuse'],['youth', 'yes', 'no',   '2', 'agree'],['youth', 'yes', 'yes',  '1', 'agree'],['youth', 'no',  'no',   '1', 'refuse'],['mid',   'no',  'no',   '1', 'refuse'],['mid',   'no',  'no',   '2', 'refuse'],['mid',   'yes', 'yes',  '2', 'agree'],['mid',   'no',  'yes',  '3', 'agree'],['mid',   'no',  'yes',  '3', 'agree'],['elder', 'no',  'yes',  '3', 'agree'],['elder', 'no',  'yes',  '2', 'agree'],['elder', 'yes', 'no',   '2', 'agree'],['elder', 'yes', 'no',   '3', 'agree'],['elder', 'no',  'no',   '1', 'refuse']]feat_type_list = ['age', 'working', 'house', 'credit']return data_list, feat_type_list

1.3输出的样本集的特征分布、概率密度、香农熵、条件熵、信息增益组成的字典

对于样例的样本集,通过类的计算,输出如下目标字典,字典内部包含了样本集的香农熵、特征分布、特征概率密度、条件熵、信息增益等信息:

1.3.1运行结果截图

1.3.2运行结果log

feat_dict = {house :{condition_entropy :  0.5509775004326937cnt :  15info_gain :  0.4199730940219749yes : {'cnt': 6, 'refuse': 0, 'shannon_entropy': 0.0, 'p_agree': 1.0, 'p_refuse': 0.0, 'p_house': 0.4, 'agree': 6}no : {'cnt': 9, 'refuse': 6, 'shannon_entropy': 0.9182958340544896, 'p_agree': 0.3333333333333333, 'p_refuse': 0.6666666666666666, 'p_house': 0.6, 'agree': 3}}credit :{condition_entropy :  0.6079610319175832cnt :  153 : {'cnt': 4, 'refuse': 0, 'p_credit': 0.26666666666666666, 'shannon_entropy': 0.0, 'p_agree': 1.0, 'p_refuse': 0.0, 'agree': 4}1 : {'cnt': 5, 'refuse': 4, 'p_credit': 0.3333333333333333, 'shannon_entropy': 0.7219280948873623, 'p_agree': 0.2, 'p_refuse': 0.8, 'agree': 1}info_gain :  0.362989562537085362 : {'cnt': 6, 'refuse': 2, 'p_credit': 0.4, 'shannon_entropy': 0.9182958340544896, 'p_agree': 0.6666666666666666, 'p_refuse': 0.3333333333333333, 'agree': 4}}working :{condition_entropy :  0.6473003963031123cnt :  15info_gain :  0.32365019815155627yes : {'cnt': 5, 'refuse': 0, 'shannon_entropy': 0.0, 'p_working': 0.3333333333333333, 'p_agree': 1.0, 'p_refuse': 0.0, 'agree': 5}no : {'cnt': 10, 'refuse': 6, 'shannon_entropy': 0.9709505944546686, 'p_working': 0.6666666666666666, 'p_agree': 0.4, 'p_refuse': 0.6, 'agree': 4}}age :{condition_entropy :  0.8879430945988998cnt :  15info_gain :  0.08300749985576883elder : {'cnt': 5, 'refuse': 1, 'p_age': 0.3333333333333333, 'shannon_entropy': 0.7219280948873623, 'p_agree': 0.8, 'p_refuse': 0.2, 'agree': 4}youth : {'cnt': 5, 'refuse': 3, 'p_age': 0.3333333333333333, 'shannon_entropy': 0.9709505944546686, 'p_agree': 0.4, 'p_refuse': 0.6, 'agree': 2}mid : {'cnt': 5, 'refuse': 2, 'p_age': 0.3333333333333333, 'shannon_entropy': 0.9709505944546686, 'p_agree': 0.6, 'p_refuse': 0.4, 'agree': 3}}}

2.话不多说,直接上代码

# -*- coding: utf-8 -*-
"""
@author: 蔚蓝的天空Tom
Talk is cheap,show me the code
Aim:样本集中每种类型特征的变量分布、概率分布、香农熵、条件熵
Aim:每种类型特征都分别有多种特征值,请萃取出每个特征值的样本数据
Aim:求每种特征值被分类的概率分布
"""import numpy as np
import math'''Tool Function'''
varnamestr = lambda v,nms: [ vn for vn in nms if id(v)==id(nms[vn])][0]#============================================
class CUtileTool(object):'''提供有用的方法比如dump_list方法,可以打印给定的list的相关信息'''def dump_list(self, src_list, src_list_namestr):'''逐行打印list:param self:类实例自身:param src_list:被打印的源list:return 无'''print('\n============',src_list_namestr,'================')list_len = len(src_list)list_shape = np.shape(src_list)print('type(',src_list_namestr,'):',type(src_list))  #<class 'list'>print('np.shape(',src_list_namestr,'):',np.shape(src_list))if 1 == len(list_shape):print(src_list)elif 2 == len(list_shape):for i in range(list_len):if 0 == i:print('[',src_list[i])elif (list_len - 1) == i:print(src_list[i],']')else:print(src_list[i])else:print(src_list)print('======\n')returndef dump_array(self, src_a, src_dict_namestr):'''逐行打印array:param self:类实例自身:param src_a:被打印的源array:return 无'''print('\n===============',src_dict_namestr,'===================')a_len = len(src_a)a_shape = np.shape(src_a)print('type(',src_dict_namestr,'):',type(src_a))  #<class 'list'>print('np.shape(',src_dict_namestr,'):',np.shape(src_a))if 1 == len(a_shape):print(src_a)elif 2 == len(a_shape):for i in range(a_len):if 0 == i:print('[',src_a[i])elif (a_len - 1) == i:print(src_a[i],']')else:print(src_a[i])else:print(src_a)print('======\n')returndef print_dict(self, src_dict, level, src_dict_namestr=''):'''逐行打印dict:param self:类实例自身:param src_dict:被打印的dict:param level:递归level,初次调用为level=0:param src_dict_namestr:对象变量名称字符串'''if isinstance(src_dict, dict):tab_str = '\t'for i in range(level):tab_str += '\t'if 0 == level:print(src_dict_namestr,'= {')for key, value in src_dict.items():if isinstance(value, dict):has_dict = Falsefor k,v in value.items():if isinstance(v, dict):has_dict = Trueif has_dict:print(tab_str,key,":{")self.print_dict(value, level + 1)else:print(tab_str,key,':',value)else:print(tab_str,key,': ',value,)print(tab_str,'}')def dump_dict(self, src_dict, src_dict_namestr):'''逐行打印dict:param self:类实例自身:param src_dict:被打印的dict对象:return 无'''print('\n===============',src_dict_namestr,'===================')dict_len = len(src_dict)dict_shape = np.shape(src_dict)dict_type = type(src_dict)print('len(',src_dict_namestr,'):',dict_len)print('type(',src_dict_namestr,'):', dict_type)  #<class 'dict'>print('np.shape(',src_dict_namestr,'):', dict_shape)print('len(dict_shape):', len(dict_shape))self.print_dict(src_dict, 0, src_dict_namestr)print('======\n')returndef dump(self, src_thing, src_thing_namestr):'''逐行打印变量(list, array, matrix等):param self:类实例自身:param src_things:被打印者:return 无'''if isinstance(src_thing, list):return self.dump_list(src_thing, src_thing_namestr)elif isinstance(src_thing, np.ndarray):return self.dump_array(src_thing, src_thing_namestr)elif isinstance(src_thing, dict):return self.dump_dict(src_thing, src_thing_namestr)else:print(src_thing_namestr,':', src_thing)return
#===========================================def create_samples():'''提供训练样本集每个example由多个特征值+1个分类标签值组成比如第一个example=['youth', 'no', 'no', '1', 'refuse'],此样本的含义可以解读为:如果一个人的条件是:youth age,no working, no house, 信誉值credit为1那么此类人会被分类到refuse一类中,即在相亲中被拒绝每个example的特征值类型为:['age', 'working', 'house', 'credit']每个example的分类标签class_label取值范围为:'refuse'或者'agree''''data_list = [['youth', 'no',  'no',   '1', 'refuse'],['youth', 'no',  'no',   '2', 'refuse'],['youth', 'yes', 'no',   '2', 'agree'],['youth', 'yes', 'yes',  '1', 'agree'],['youth', 'no',  'no',   '1', 'refuse'],['mid',   'no',  'no',   '1', 'refuse'],['mid',   'no',  'no',   '2', 'refuse'],['mid',   'yes', 'yes',  '2', 'agree'],['mid',   'no',  'yes',  '3', 'agree'],['mid',   'no',  'yes',  '3', 'agree'],['elder', 'no',  'yes',  '3', 'agree'],['elder', 'no',  'yes',  '2', 'agree'],['elder', 'yes', 'no',   '2', 'agree'],['elder', 'yes', 'no',   '3', 'agree'],['elder', 'no',  'no',   '1', 'refuse']]feat_type_list = ['age', 'working', 'house', 'credit']return data_list, feat_type_listclass CSamplesTool(object):'提供样本集的摘取目标数据的方法'def __init__(self, data_list, feat_type_list):'''初始化函数:param data_list:数据集:param feat_type_list:数据的特征类型列表:return 无'''''' self.data_list 样例:[['youth', 'no',  'no',   '1', 'refuse'],['youth', 'no',  'no',   '2', 'refuse'],……]'''self.data_list = data_list'''self.feat_type_list 样例:['age', 'working', 'house', 'credit']'''self.feat_type_list = feat_type_list'''self.data_cnt 就是样本集中样本的总数'''self.data_cnt = len(data_list)'''self.feat_type_cnt 就是每个样本的特征值类型总数'''self.feat_type_cnt = len(feat_type_list)'''self.feat_value_list 每种类型特征的取值列表, 样例:[ ['youth', 'youth', 'youth', 'youth', 'youth', 'mid', 'mid', 'mid', 'mid', 'mid', 'elder', 'elder', 'elder', 'elder', 'elder']['no', 'no', 'yes', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'yes', 'yes', 'no']['no', 'no', 'no', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no']['1', '2', '2', '1', '1', '1', '2', '2', '3', '3', '3', '2', '2', '3', '1']]'''self.feat_value_list = []'''self.class_value_list 样本集的分类标签取值列表,长度为样本总数,样例:['refuse', 'refuse', 'agree', …… ,'agree', 'agree', 'refuse']'''self.class_value_list = []'''self.feat_dict 样本集的特征字典,样例:{house :{condition_entropy :  0.5509775004326937cnt :  15info_gain :  0.4199730940219749yes : {'cnt': 6, 'refuse': 0, 'shannon_entropy': 0.0, 'p_agree': 1.0, 'p_refuse': 0.0, 'p_house': 0.4, 'agree': 6}no : {'cnt': 9, 'refuse': 6, 'shannon_entropy': 0.9182958340544896, 'p_agree': 0.3333333333333333, 'p_refuse': 0.6666666666666666, 'p_house': 0.6, 'agree': 3}}credit :{condition_entropy :  0.6079610319175832cnt :  153 : {'cnt': 4, 'refuse': 0, 'p_credit': 0.26666666666666666, 'shannon_entropy': 0.0, 'p_agree': 1.0, 'p_refuse': 0.0, 'agree': 4}1 : {'cnt': 5, 'refuse': 4, 'p_credit': 0.3333333333333333, 'shannon_entropy': 0.7219280948873623, 'p_agree': 0.2, 'p_refuse': 0.8, 'agree': 1}info_gain :  0.362989562537085362 : {'cnt': 6, 'refuse': 2, 'p_credit': 0.4, 'shannon_entropy': 0.9182958340544896, 'p_agree': 0.6666666666666666, 'p_refuse': 0.3333333333333333, 'agree': 4}}working :{condition_entropy :  0.6473003963031123cnt :  15info_gain :  0.32365019815155627yes : {'cnt': 5, 'refuse': 0, 'shannon_entropy': 0.0, 'p_working': 0.3333333333333333, 'p_agree': 1.0, 'p_refuse': 0.0, 'agree': 5}no : {'cnt': 10, 'refuse': 6, 'shannon_entropy': 0.9709505944546686, 'p_working': 0.6666666666666666, 'p_agree': 0.4, 'p_refuse': 0.6, 'agree': 4}}age :{condition_entropy :  0.8879430945988998cnt :  15info_gain :  0.08300749985576883elder : {'cnt': 5, 'refuse': 1, 'p_age': 0.3333333333333333, 'shannon_entropy': 0.7219280948873623, 'p_agree': 0.8, 'p_refuse': 0.2, 'agree': 4}youth : {'cnt': 5, 'refuse': 3, 'p_age': 0.3333333333333333, 'shannon_entropy': 0.9709505944546686, 'p_agree': 0.4, 'p_refuse': 0.6, 'agree': 2}mid : {'cnt': 5, 'refuse': 2, 'p_age': 0.3333333333333333, 'shannon_entropy': 0.9709505944546686, 'p_agree': 0.6, 'p_refuse': 0.4, 'agree': 3}}}'''self.feat_dict = {}'''样本集的香农熵,H(Y={refuse, agree})'''self.samples_shanon_entropy = 1000#计算self.pickout_feat()self.pickout_class()self.pickout_samples_shannon_entropy()self.pickout_feat_dict()returndef shan_ent_ele(self, p):if 0 == p:return 0else:return -1 * p * math.log2(p)def shannon_entropy(self, P):func = np.frompyfunc(self.shan_ent_ele, 1, 1)ent_ele_list = func(P)entropy = ent_ele_list.sum()return entropydef get_data_cnt(self):'''样本总数'''return self.data_cntdef get_feat_type_cnt(self):'''特征类型总数'''return self.feat_type_cntdef get_feats(self):'''每种类型特征的特征值列表'''return self.feat_value_listdef get_classes(self):'''样本集的分类列表'''return self.class_value_listdef get_samples_shannon_entropy(self):'''样本集的香农熵,H(Y={refuse, agree})'''return self.samples_shanon_entropydef get_feat_dict(self):'''特征分布以及概率分布'''return self.feat_dictdef pickout_feat(self):'''摘取每种类型特征的特征值:return 无'''self.feat_value_list = []for dim in range(self.feat_type_cnt):curtype_feat = [example[dim] for example in self.data_list]''' 这一句等效下面三句curtype_feat = []for i in range(self.data_cnt):curtype_feat.append(self.data_list[i][dim])'''self.feat_value_list.append(curtype_feat)returndef pickout_class(self):'''摘取分类列表,大小一定是m×1'''self.class_value_list = []self.class_value_list = [example[-1] for example in self.data_list]'''这一句等效下面两句for i in range(self.data_cnt):self.class_value_list.append(self.data_list[i][-1])'''def pickout_samples_shannon_entropy(self):'''计算样本集的香农熵,H(Y={refuse, agree})'''#统计样本集的分类标签分布label_set = set(self.class_value_list)label_cnt_list = []for label in label_set:label_cnt_list.append(self.class_value_list.count(label))#统计样本集分类标签概率密度n_samples = len(self.class_value_list)label_prob_list = [label_cnt/n_samples for label_cnt in label_cnt_list]#计算样本集的香农熵self.samples_shanon_entropy = self.shannon_entropy(label_prob_list)return        def pickout_feat_dict(self):'''摘取特征分布以及特征概率分布'''self.feat_dict = {}class_label_set = set(self.class_value_list)print(class_label_set)for i in range(self.feat_type_cnt):#依次加入特征类型字典:age:{}, house:{}, working:{}, credit:{}feat_type = self.feat_type_list[i]self.feat_dict[feat_type] = {}#初始化feat_type时的条件熵, 即增加age:{'condition_entropy':0.0}self.feat_dict[feat_type]['condition_entropy'] = 0.0#初始化feat_type时的信息增益, 即增加age:{'inf_gain':0.0}self.feat_dict[feat_type]['info_gain'] = 0.0#填充feat_type的取值范围总数,如feat_type是age时,总数为3,可取值={youth, mid, elder}self.feat_dict[feat_type]['cnt'] = len(self.feat_value_list[i])#填充特征类型字典的key,例如age:{'youth':{}, 'mid:{}, 'elder':{}}#为具体特征值的字典填充内容#例如age:{elder:{填充此内容}} 填充为 age:{elder:{'cnt':5, 'p_age':5./15, 'refuse':4, 'agree':1, 'p_refuse':3./5, 'p_agree':2./5}}#填充具体特征值的总样本数cntfeat_value_set = set(self.feat_value_list[i])for feat_value in feat_value_set:#填充{'age':{'elder':{}}}其中的elder:{}self.feat_dict[feat_type][feat_value] = {}#填充'age':{'elder':{'cnt':5}}其中的'cnt':5self.feat_dict[feat_type][feat_value]['cnt'] = self.feat_value_list[i].count(feat_value)#填充'ag'e:{'elder':{'p_age':5./15}}其中的p_age:5./15value_prob_key = 'p_' + str(feat_type)self.feat_dict[feat_type][feat_value][value_prob_key] = self.feat_value_list[i].count(feat_value)*(1.0)/len(self.feat_value_list[i])#填充'age':{'elder':{'refuse':4, 'agree':1}}其中的'refuse':4, 'agree':1,for n in range(self.data_cnt):for class_label in class_label_set:if class_label not in self.feat_dict[feat_type][feat_value].keys():self.feat_dict[feat_type][feat_value][class_label] = 0if feat_value == self.feat_value_list[i][n] and class_label == self.class_value_list[n]:self.feat_dict[feat_type][feat_value][class_label] += 1#填充'age':{'elder':{'p_refuse':3./5, 'p_agree':2./5}}其中的'p_refuse':3./5, 'p_agree':2./5self.feat_dict[feat_type][feat_value]['shannon_entropy'] = 0.0for class_label in class_label_set:prob_key = 'p_'+str(class_label)class_label_cnt = self.feat_dict[feat_type][feat_value][class_label]value_cnt = self.feat_dict[feat_type][feat_value]['cnt']self.feat_dict[feat_type][feat_value][prob_key] = float(class_label_cnt) / value_cnt#填充'age':{'elder':{'shannon_entropy':2.3}}其中的'shannon_entropy':2.3prob = self.feat_dict[feat_type][feat_value][prob_key]if 0 != prob:self.feat_dict[feat_type][feat_value]['shannon_entropy'] += -1 * prob * math.log2(prob)#填充feat_type时的条件熵, 即增加age:{'condition_entropy':1.0}中的'condition_entropy':1.0feat_value_prob = self.feat_dict[feat_type][feat_value][value_prob_key]feat_value_sEnt = self.feat_dict[feat_type][feat_value]['shannon_entropy']self.feat_dict[feat_type]['condition_entropy'] += feat_value_prob * feat_value_sEnt#填充feat_type时的信息增益,即计算age:{'info_gain':0.345}中的'info_gain':0.345print('self.samples_shanon_entropy:',self.samples_shanon_entropy)self.feat_dict[feat_type]['info_gain'] = self.samples_shanon_entropy - self.feat_dict[feat_type]['condition_entropy']if __name__=='__main__':#创建样本集train_data_list, feat_type_list = create_samples()#创建样本集工具类实例samples = CSamplesTool(train_data_list, feat_type_list)#创建通用工具类实例tool = CUtileTool()tool.dump(samples.get_feats(), 'feat_value_list')tool.dump(samples.get_classes(), 'class_value_list')tool.dump(samples.get_feat_dict(), 'feat_dict')

3.如何使用类输出的字典?

不懂字典结构的,需要学习下python中dict的语法,很容易的,类似Json的数据结构~

3.1从输出样本集的字典,可以很容易汇总信息增益

根据类输出的样本集的字典,很容易得到,每个特征的信息增益,如下所示:

样本集的香农熵baseEntropy: 0.9709505944546686house:info_gain :  0.4199730940219749credit:info_gain :  0.36298956253708536working:info_gain :  0.32365019815155627age:info_gain :  0.08300749985576883

3.2使用信息增益来找决策树的根节点

如果以此样例样本集为训练集,其决策树的根节点应该是,信息增益最大的特征。

通过样本集的字典可以知道,条件样本空间为house时,信息增益H(Y|X=house)=0.4199730940219749是最大的。

所以选取特征house为训练集的决策树的根节点~,此时的决策树最简洁有效。

4.信息增益比

    def build_stat_dict(self):'''核心函数'''self.stat_dict= dict({})self.stat_dict['samples_ent'] = self.samples_shanon_entropyself.stat_dict['samples_cnt'] = len(self.data_list)class_vals, class_set = self.class_list, set(self.class_list)#class values, class value setfor i in range(self.n_feats):#for feat in [age, house, work, cedit]feat, vals, val_set = self.feat_list[i], self.feat_value_list[i], set(self.feat_value_list[i])feat_c_ent, val_pden = 0,[]#feat-conditional-enttropy, feat-value-probability-densityself.stat_dict[feat] = {}for val in val_set:#for val in {youth, mid, elder}val_p_self = vals.count(val)*1.0/len(vals)val_pden.append(val_p_self)val_ent, val_labels, label_dist, label_pden=0, [], [], []for label in class_set:#for label in {agree, refuse}val_labels.append(label)n_label = self.get_example_cnt(vals, val, class_vals, label)label_dist.append(n_label)label_pden.append(n_label * 1.0 / vals.count(val))val_ent = self.shan_ent(label_pden)feat_c_ent += val_p_self * val_ent#update feat cond-entropyself.stat_dict[feat][val]={}self.stat_dict[feat][val]['cnt']    = vals.count(val)self.stat_dict[feat][val]['p_self'] = val_p_selfself.stat_dict[feat][val]['ent']    = val_entfor i in range(len(class_set)):#填充value的分类样本分布和概率密度if val_labels[i] not in self.stat_dict[feat][val].keys():self.stat_dict[feat][val][val_labels[i]] = {}self.stat_dict[feat][val][val_labels[i]]['cnt']    = label_dist[i]self.stat_dict[feat][val][val_labels[i]]['p_self'] = label_pden[i]self.stat_dict[feat]['cond_ent']    = feat_c_entself.stat_dict[feat]['info_gain']   = self.samples_shanon_entropy - feat_c_entself.stat_dict[feat]['gain_ratio']  = self.feat_info_gain_ratio(self.stat_dict[feat]['info_gain'], val_pden)return self.stat_dict

note:如果这个代码搞定了,其实决策树的生成代码,差不多已经完成一半了。

enjoy it ~

(end)

【机器学习】【决策树】自己动手用Python实现一个类:in样本集,out特征分布、概率密度、熵、条件熵、信息增益、信息增益比相关推荐

  1. 机器学习-决策树之回归树python实战(预测泰坦尼克号幸存情况)(三)

    本文用通俗易懂的方式来讲解分类树中的回归树,并以"一维回归的图像绘制"和"泰坦尼克号幸存者预测"两个例子来说明该算法原理. 以下是本文大纲: 1 Decisio ...

  2. 这也行?动手用Python做一个酒精检测仪,数据还能直接上云

    来这里发现更多有趣案例 HaaS开发框架HaaS积木方案,赋能生态开发者,让您快速找到自己需要的解决方案,硬件主板与外设,以及各种应用组件.https://haas.iot.aliyun.com/so ...

  3. python创建一个类初始化两个变量name、age_Python小白入门:第八讲||类

    Python 是一种面向对象的编程语言.在面向对象编程中,你编写表示现实世界中的事务和情景的类,并基于这些类来创建对象. 编写类时,你定义的一大类对象都有的通用行为.基于类创建对象时,每个对象都自动具 ...

  4. python定义一个类和子类_Python面向对象class类属性及子类用法分析

    本文实例讲述了Python面向对象class类属性及子类用法.分享给大家供大家参考,具体如下: class类属性 class Foo(object): x=1.5 foo=Foo() print fo ...

  5. python定义一个类描述数字时钟_python自定义时钟类、定时任务类

    这是我使用python写的第一个类(也算是学习面向对象语言以来正式写的第一个解耦的类),记录下改进的过程. 分析需求 最初,因为使用time模块显示日期时,每次都要设置时间字符串的格式,挺麻烦,但还是 ...

  6. python写一个类_python3学习笔记--002--写一个类

    代码: [laolang@localhost classtest]$ cat test.py #!/usr/bin/env python class person: def __init__(self ...

  7. python定义一个类怎么弄_Python怎么创建一个类

    Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的. Python使用class语句来创建一个新类,class之后为类的名称并以冒号结尾:clas ...

  8. Python——定义一个类来进行北京污染物的可视化(pyecharts绘制折线图、饼图、北京地图)

    目录 作业基本要求 数据来源 其他要求 一.源代码 二.可视化展示 1.绘制随时间变化曲线图 2.绘制某一时点下污染物占比 3.绘制北京地图下的各个检测站污染情况 ​编辑 4.分析变量之间的相关性(污 ...

  9. 机器学习—决策树构造算法的python实现

    机器学习-决策树算法的python实现 想要实现的效果 先来看下结果 程序原理 数据 完整代码(附有具体解析) 想要实现的效果 对于这个不好玩的决策树,我想要得到的就是通过决策树训练我的数据然后生成这 ...

  10. 80行代码自己动手用python写一个表格拆分与合并小工具

    大家好,我是才哥. 可能是最近加班熬夜太多,这个周末身体不舒服,头痛.冷汗什么的.终于在连着睡了接近2天后,现在慢慢恢复了. 最近有新朋友看到之前<>,想问下有没有免费的小工具,可以进行表 ...

最新文章

  1. Log4Net组件的应用详解
  2. python【力扣LeetCode算法题库】876- 链表的中间结点
  3. LeetCode算法题-Minimum Depth of Binary Tree(Java实现)
  4. Git 系列(七):使用 Git 管理二进制大对象
  5. linux开机磁盘检查启动慢,Ubuntu 7.10开机启动慢的完美解决
  6. arcgis js 4.x 地图中加入图片
  7. TensorFlow报错:'dict' object has no attribute 'SerializeToString'
  8. oracle查询cpu占用率高,解决oracle进程CPU占用过高问题
  9. 弹出选择文件夹的对话框 BROWSEINFO 的用法【MFC】
  10. 山西计算机工程师职称英语,山西中级工程师职称在线查询
  11. Transfer: 99款高质量免费(X)HTML/CSS模板
  12. 深度学习必备的几款流行网络与数据集
  13. PHP中的ZIP压缩与解压
  14. 在Qtopia中添加国际化支持
  15. 关于西门子plc的CPU
  16. 悬崖帝国中文版下载|悬崖帝国中文破解版下载 v1.0绿色免安装版
  17. net3.5离线一键安装工具_一键获取抖音直播源地址(无水印高清下载),无需安装Fiddler抓包工具...
  18. ad转3d视图快捷键_AD详细快捷键按键
  19. Spring Cloud (五):路由网关(Zuul)
  20. nested exception is java.sql.SQLException: Data truncated for column 'PassWord' at row 72

热门文章

  1. npm install报错errno -4048
  2. MATLAB代码:面向削峰填谷的电动汽车多目标优化调度策略
  3. 2.5css ps切图、
  4. linux目录显示蓝色,centos系统创建文件夹目录显示颜色
  5. ECMAScript标准简介
  6. python 求和_python pandas行、列求和及累加求和
  7. centos 如何想windows样快速打五笔
  8. Linguistic Regularities in Continuous Space Word Representations
  9. (zotero+坚果云+pdf expert+欧陆词典)实现PC平板同步阅读管理科研文献(完美教程)
  10. PDF页码怎么设置?如何给PDF文件设置页码