代码学习——MLDF

    科技2022-08-05  116

    文章目录

    sklearn.utils.shuffleastype强制转换数据类型format格式化函数

    sklearn.utils.shuffle

    打乱数据 def shuffle_index(num_samples): a = range(0, num_samples) a = shuffle(a) length = int((num_samples + 1) / 2) train_index = a[:length] test_index = a[length:] return [train_index, test_index]

    astype强制转换数据类型

    format格式化函数

    语法: str.format()用{}和:代替% format函数不设置参数: >>>"{} {}".format("hello", "world") # 不设置指定位置,按默认顺序 'hello world' >>> "{0} {1}".format("hello", "world") # 设置指定位置 'hello world' >>> "{1} {0} {1}".format("hello", "world") # 设置指定位置 'world hello world' 设置参数: print("用户名:{name}, 学号 {number}".format(name="universe", number="1207")) # 通过字典设置参数 site = {"name": "universe", "number": "1207"} print("用户名:{name}, 学号 {number}".format(**site)) # 通过列表索引设置参数 my_list = ['universe', '1207'] print("用户名:{0[0]}, 学号 {0[1]}".format(my_list)) # "0" 是必须的 输出都是:用户名:universe, 学号 1207
    Processed: 0.011, SQL: 8