当前位置:   article > 正文

【学习笔记】Python大数据处理与分析——数据预处理_在数据清洗阶段,处理确实值的函数是什么其中的参数axis,可以取0和1,分别代表

在数据清洗阶段,处理确实值的函数是什么其中的参数axis,可以取0和1,分别代表

一、数据清洗

1、唯一值与重复值

        获取唯一值的方法是采用unique()函数,用于Series对象:

  1. s1 = pd.Series([2, 3, 4, 1, 2, 5, 3, 6, 4, 9, 5, 3, 4, 2, 1, 2])
  2. print(s1.unique())
  3. →[2 3 4 1 5 6 9]

        但unique()函数不能用于DataFrame对象,而drop_duplicates()函数可以:

  1. df1 = pd.DataFrame({'a': [1, 1, 3, 2],
  2. 'b': [1, 1, 6, 4],
  3. 'c': [1, 1, 3, 9]})
  4. print(df1.drop_duplicates())
  5. → a b c
  6. 0 1 1 1
  7. 2 3 6 3
  8. 3 2 4 9

2、缺失值

        数据缺失分两种情况:行记录缺失(数据记录丢失)和列记录缺失。

  1. df2 = pd.DataFrame(np.arange(12).reshape(4, 3), index=[0, 1, 2, 3], columns=['a', 'b', 'c'])
  2. df2.iloc[1, [1]] = np.nan
  3. df2.iloc[2, [1, 2]] = np.nan
  4. print(df2)
  5. → a b c
  6. 0 0 1.0 2.0
  7. 1 3 NaN 5.0
  8. 2 6 NaN NaN
  9. 3 9 10.0 11.0

(1)数据删除

        删除数据意味着减少数据特征,通常用于样本数据量很大且缺失值较少的情况。dropna()函数的原型为dropna(axis, how, thresh, subset, inplace),参数分别为:

axis:默认为0,当等于0时代表的是删除空值所在的行,当等于1时删除空值所在的列。

how:默认为‘any’,表示的是删除空值所在的行或者是列,这个主要看前面的axis参数你设定是0还是1;当参数等于‘all’,表示的是删除一阵行或者是一整列都为空值的行或者列,如果你的某一行或某一列,不全为空值的话,则不会删除,即不起作用。

thresh:一个整数x,意思是保留非空值的数量不小于x的每一行或者是每一列。

subset:指定删除特定行或列的空值所在的列或行,如果axis=0,表示如果指定行x中有空值,则删除所在的列;如果axis=1,表示如果指定列x有空值,则删除空值所在的行。

inplace:默认为False,它的意思是在处理空值时,是在原数据上处理还是在先把原数据复制一份,然后在副本上处理,在副本上处理的时候,原数据不受任何影响;如果inplace设置为True,那代表你在原数据上进行处理,原数据直接受影响。

  1. print(df2.dropna())
  2. → a b c
  3. 0 0 1.0 2.0
  4. 3 9 10.0 11.0
  5. print(df2.dropna(axis=1))
  6. → a
  7. 0 0
  8. 1 3
  9. 2 6
  10. 3 9
  11. print(df2.dropna(axis=1, how='all'))
  12. → a b c
  13. 0 0 1.0 2.0
  14. 1 3 NaN 5.0
  15. 2 6 NaN NaN
  16. 3 9 10.0 11.0
  17. print(df2.dropna(axis=1, how='any'))
  18. → a
  19. 0 0
  20. 1 3
  21. 2 6
  22. 3 9
  23. print(df2.dropna(axis=1, thresh=3))
  24. → a c
  25. 0 0 2.0
  26. 1 3 5.0
  27. 2 6 NaN
  28. 3 9 11.0
  29. print(df2.dropna(subset=['c']))
  30. → a b c
  31. 0 0 1.0 2.0
  32. 1 3 NaN 5.0
  33. 3 9 10.0 11.0
  34. df2.dropna(subset=['c'], inplace=True)
  35. print(df2)
  36. → a b c
  37. 0 0 1.0 2.0
  38. 1 3 NaN 5.0
  39. 3 9 10.0 11.0

(2)数据填补

        大致分为替换缺失值(对于数值型数据,使用平均数(mean)或中位数(median)等方法不足;对于分类型数据,使用众数(mode)等方法补足)和拟合缺失值(利用其他变量做模型输入进行缺失变量预测,对于数值型数据,使用回归模型补足;对于分类型数量,使用分类模型补足)。

  1. df2['b'].fillna(df2['b'].mean(), inplace=True)
  2. print(df2)
  3. → a b c
  4. 0 0 1.0 2.0
  5. 1 3 5.5 5.0
  6. 2 6 5.5 NaN
  7. 3 9 10.0 11.0
  8. df2['c'].fillna(df2['c'].median(), inplace=True)
  9. print(df2)
  10. → a b c
  11. 0 0 1.0 2.0
  12. 1 3 5.5 5.0
  13. 2 6 5.5 5.0
  14. 3 9 10.0 11.0

(3)不处理

        很多模型对于缺失值有较高的容忍度或更灵活的处理方法,并且补齐处理只是用主观估计值来填补未知值,不一定完全符合客观事实,有时会改变原始的系统信息或引入新的噪声数据。常见能自动处理缺失值的模型有K-Nearest Neighbor、决策树模型、随机森林模型、神经网络、朴素贝叶斯、DBSCAN等,它们将缺失值忽略,不参与运算,或将缺失作为分布的状态参与建模过程。

3、异常值

        指数据整体呈现某种统计概率分布,但有部分偏离总体,在总体规律中有不合理表现的数据。对异常值的检测原则是:确保结合具体场景下数据有意义的情况下,查找不合逻辑的数值。通常有箱线图法、正态分布图法、模型法来检测。

        对异常值的处理一般有以下几种方法:

(1)不处理

(2)填充

(3)删除

(4)编码(将异常值单独作为一组值或类别)

(5)盖帽法(将某连续变量均值上下3倍标准差范围外的记录替换为上下3倍标准差值)

二、正则表达式

        对于正则表达式的语法详解此处不作说明,仅说明正则表达式的元字符如下所示:

1、字符串方法

(1)使用 % 格式化

%d 以整型输出
%ld 以长整型输出
%o 以八进制数形式输出整数
%x 以十六进制数形式输出整数
%u 以十进制数输出unsigned型数据(无符号数)
%c 用来输出一个字符
%s 用来输出一个字符串
%f 用来输出实数,以小数形式输出
%e 以指数形式输出实数
%g 根据大小自动选f格式或e格式,且不输出无意义的零

  1. num = 13579
  2. print("%o" % num)
  3. 32413
  4. print("%x" % num)
  5. →350b
  6. print("%u" % num)
  7. 13579
  8. print("%s" % num)
  9. 13579
  10. print("%f" % num)
  11. 13579.000000
  12. print("%e" % num)
  13. 1.357900e+04
  14. print("%g" % num)
  15. 13579
  16. print("%.2f" % num)
  17. 13579.00

 (2)使用format()函数格式化

  1. print("{}{}".format('A', 'B')) # 不带编号,必须一一对应
  2. →AB
  3. print("{1}{0}{1}".format('A', 'B')) # 带编号打乱顺序
  4. →BAB
  5. print("{a}{b}{a}".format(a='A', b='B')) # 带关键字
  6. →ABA
① 取位数
  1. print("{:10}".format('hello')) # 取10位默认左对齐
  2. →hello
  3. print("{0} to {1:.2f}".format(np.pi, np.pi)) # 取两位小数
  4. 3.141592653589793 to 3.14
  5. print("{0:5.2} to {0:5.2f}".format(np.pi, np.pi)) # 保留两位有效数字与取两位小数对比
  6. 3.1 to 3.14
② 进制转化
  1. print("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(16))
  2. int: 16; hex: 10; oct: 20; bin: 10000
  3. print("{0} in hex is: {0:#x}\n{1} in oct is: {0:#o}".format(18, 10))
  4. 18 in hex is: 0x12
  5. 10 in oct is: 0o22
③ 字符串对齐与位数补全
  1. print("{:<20}".format("hello world!"))
  2. →hello world!
  3. print("{:^20}".format("hello world!"))
  4. → hello world!
  5. print("{:>20}".format("hello world!"))
  6. → hello world!
  7. print("{:*<20}".format("hello world!"))
  8. →hello world!********
  9. print("{:-^20}".format("hello world!"))
  10. →----hello world!----
  11. print("{:#>20}".format("hello world!"))
  12. ########hello world!
  13. print("{:0=10}".format(12345))
  14. →0000012345
  15. print("{:%}".format(0.125))
  16. 12.500000%
  17. print("my name is {name}, my age is {age}, and my QQ is {qq}.".format(name="67x", age=21, qq="409867818"))
  18. →my name is 67x, my age is 21, and my QQ is 409867818.
  19. position = (1, 2, 3)
  20. print("X: {0[0]}; Y: {0[1]}; Z: {0[2]}".format(position))
  21. →X: 1; Y: 2; Z: 3

(3)使用f-string方法格式化

  1. name = "67x"
  2. age = 21
  3. print(f"my name is {name}, my age is {age}")
  4. →my name is 67x, my age is 21
  5. width = 10
  6. precision = 4
  7. value = 11 / 3
  8. print(f"result: {value:{width}.{precision}}")
  9. →result: 3.667
  10. a = 10
  11. b = 5
  12. c = 3
  13. pi = np.pi
  14. print(f"{pi:{a}.{b}}")
  15. 3.1416
  16. print(f"{pi:{a}.{c}f}")
  17. 3.142
  18. print(f"{a * 2}")
  19. 20
  20. print(f"{name * 3}")
  21. →67x67x67x

2、re模块

(1)re.match()

        函数原型为re.match(pattern, string, flags=0),参数分别为:

pattern:匹配的正则表达式

string:要匹配的字符串

flags:标志位,控制正则表达式的匹配方式(如是否区分大小写、多行匹配等)

  1. print(re.match("www", "www.baidu.com").span())
  2. →(0, 3)
  3. print(re.match("com", "www.baidu.com"))
  4. None
  5. str1 = "Cats are smarter than dogs"
  6. matchObj1 = re.match(r"(.*) are (.*?) (.*)", str1, re.M | re.I)
  7. print(matchObj1.group())
  8. →Cats are smarter than dogs
  9. print(matchObj1.group(1))
  10. →Cats
  11. print(matchObj1.group(2))
  12. →smarter
  13. print(matchObj1.group(3))
  14. →than dogs
  15. matchObj2 = re.match(r"(.*) are (.*?) .*", str1, re.M | re.I)
  16. print(matchObj2.group())
  17. →Cats are smarter than dogs
  18. print(matchObj2.group(1))
  19. →Cats
  20. print(matchObj2.group(2))
  21. →smarter
  22. matchObj3 = re.match(r"(.*) are (.*) .*", str1, re.M | re.I)
  23. print(matchObj3.group())
  24. →Cats are smarter than dogs
  25. print(matchObj3.group(1))
  26. →Cats
  27. print(matchObj3.group(2))
  28. →smarter than
  29. matchObj4 = re.match(r"(.*) are (.*)", str1, re.M | re.I)
  30. print(matchObj4.group())
  31. →Cats are smarter than dogs
  32. print(matchObj4.group(1))
  33. →Cats
  34. print(matchObj4.group(2))
  35. →smarter than dogs

        re.match(r"(.*) are (.*) .*", str1, re.M | re.I) 的具体匹配过程如下:

re.match() 函数从头开始匹配字符串 str1,尝试将其分成若干个子串,使每个子串能够匹配正则表达式模式;

匹配过程从左到右进行。模式中的 (.*) 匹配任意数量的任意字符,并将匹配的结果保存在分组 1 中。因为这是一个贪婪模式,它会尽可能多地匹配字符,直到遇到匹配模式中的下一个字符或结束位置。在这个例子中,(.*) 匹配了 "Cats";

模式中的 " are " 匹配了字符串中的 " are ";

模式中的 (.*?) 匹配任意数量的任意字符,并将匹配的结果保存在分组 2 中。因为这是一个非贪婪模式。它会尽可能少地匹配字符,直到遇到匹配模式中的下一个字符或结束位置。在这个例子中,(.*?) 匹配了 "smarter";

模式中的 " " 匹配了字符串中的空格;

.* 匹配任意数量的任意字符,并将其忽略。在这个例子中,它匹配了 "than dogs"。

(2)re.search()

        函数原型为re.search(pattern, string, flags=0),参数分别为:

pattern:匹配的正则表达式

string:要匹配的字符串

flags:标志位,控制正则表达式的匹配方式(如是否区分大小写、多行匹配等)

  1. print(re.search("www", "www.baidu.com").span())
  2. →(0, 3)
  3. print(re.search("baidu", "www.baidu.com").span())
  4. →(4, 9)
  5. print(re.search("com", "www.baidu.com").span())
  6. →(10, 13)
  7. print(re.search("\.", "www.baidu.com"))
  8. →<re.Match object; span=(3, 4), match='.'>
  9. print(re.search("67x", "www.baidu.com"))
  10. None

(3)re.sub()

        函数原型为re.sub(pattern, repl, string, count=0),参数分别为:

pattern:正则表达式中的模式字符串

repl:替换的字符串,也可为一个函数

string:要被查找替换的字符串

count:模式匹配后替换的最大次数,默认为0,表示替换所有匹配

  1. phone = "2020-221-342#67x"
  2. print(re.sub(r"#.*$", "", phone)) # 删除#后字符
  3. 2020-221-342
  4. print(re.sub(r"-", "*", phone)) # 删除-符号
  5. 2020*221*342#67x

(4)re.compile()

        函数原型为re.compile(pattern[, flags]),参数分别为:

pattern:一个字符串形式的正则表达式

flags:匹配模式,可选:

        re.I:忽略大小写;

        re.L:表示特殊字符\w、\W、\b、\B、\s、\S;

        re.M:多行模式;

        re.S:即.,并且包含换行符在内的任意字符(.不包括换行符)

        re.U:表示特殊字符集\w、\W、\b、\B、\d、\D、\s、\S;

        re.X:为增加可读性,忽略空格和#后注释

  1. pattern1 = re.compile(r"\d+") # 匹配至少1个数字
  2. str2 = "LiuXin67X"
  3. print(pattern1.match(str2)) # 查找头部没有匹配
  4. None
  5. matchObj5 = pattern1.match(str2, 6, len(str2))
  6. print(matchObj5) # 返回一个Match对象
  7. →<re.Match object; span=(6, 8), match='67'>
  8. print(matchObj5.group())
  9. 67
  10. print(matchObj5.start())
  11. 6
  12. print(matchObj5.end())
  13. 8
  14. print(matchObj5.span())
  15. →(6, 8)
  16. pattern2 = re.compile(r"([a-z]+) ([a-z]+)", re.I)
  17. str3 = "Hello World Wide Web"
  18. matchObj6 = pattern2.match(str3)
  19. print(matchObj6)
  20. →<re.Match object; span=(0, 11), match='Hello World'>
  21. print(matchObj6.group()) # 返回匹配成功的整个子串
  22. →Hello World
  23. print(matchObj6.span()) # 返回匹配成功的整个子串的索引
  24. →(0, 11)
  25. print(matchObj6.group(1)) # 返回第一个分组匹配成功的子串
  26. →Hello
  27. print(matchObj6.span(1)) # 返回第一个分组匹配成功的子串的索引
  28. →(0, 5)
  29. print(matchObj6.group(2)) # 返回第二个分组匹配成功的子串
  30. →World
  31. print(matchObj6.span(2)) # 返回第二个分组匹配成功的子串的索引
  32. →(6, 11)
  33. print(matchObj6.groups()) # 等价于(matchObj6.groups(1), matchObj6.groups(2), ...)
  34. →('Hello', 'World')

 (5)findall()

        函数原型为findall(string[, pos[, endpos]]),参数分别为:

string:待匹配的字符串

pos:指定字符串的起始位置,默认为0

endpos:指定字符串的结束位置,默认为字符串长度

  1. str4 = "baidu 123 google 456."
  2. print(pattern1.findall(str4))
  3. →['123', '456']
  4. print(pattern1.findall(str4, 7, 19))
  5. →['23', '45']

 (6)finditer()

        函数原型为finditer(string[, pos[, endpos]]),参数分别为:

string:待匹配的字符串

pos:指定字符串的起始位置,默认为0

endpos:指定字符串的结束位置,默认为字符串长度

        功能是在字符串中找到正则表达式所匹配的所有子串,并把它们作为一个迭代器返回。

  1. it = re.finditer(pattern1, str4)
  2. for i in it:
  3. print(i.group())
  4. 123
  5. 456

(7)split()

        函数原型为re.split(pattern, string[, maxsplit=0, flag=0]),参数分别为:

pattern:匹配的正则表达式

string:要匹配的字符串

maxsplit:分割次数,默认为0,表示不限制次数

flags:标志位,控制正则表达式的匹配方式(如是否区分大小写、多行匹配等)

  1. str5 = " baidu 123 google 456."
  2. print(re.split("x", str4))
  3. →['baidu 123 google 456.']
  4. print(re.split("\W+", str4))
  5. →['baidu', '123', 'google', '456', '']
  6. print(re.split("\W+", str4, 1))
  7. →['baidu', '123 google 456.']
  8. print(re.split("\W+", str4, 2))
  9. →['baidu', '123', 'google 456.']
  10. print(re.split("(\W+)", str4))
  11. →['baidu', ' ', '123', ' ', 'google', ' ', '456', '.', '']
  12. print(re.split("\W+", str5))
  13. →['', 'baidu', '123', 'google', '456', '']
  14. print(re.split("(\W+)", str5))
  15. →['', ' ', 'baidu', ' ', '123', ' ', 'google', ' ', '456', '.', '']

三、数据规整

1、聚合、分组及数据透视

(1)分组与聚合

        数据分组的核心思想是“拆分-组织-合并”,聚合通常使用聚合函数(如count()、sum()、mean()等)。

  1. df3 = pd.DataFrame({"A": ['a', 'b', 'c', 'a', 'b', 'a'], "B": [10, 15, 5, 2, 8, 4]})
  2. df4 = pd.DataFrame({"A": ['a', 'b', 'c', 'b', 'a'], "B1": [3, 5, 6, 8, 9], "B2": [2, 5, 9, 6, 8]})
  3. combine1 = df3["B"].groupby(df3["A"])
  4. combine2 = df3.groupby(df3.dtypes, axis=1)
  5. combine3 = df4.groupby("A")
  6. print(combine1.mean())
  7. →A
  8. a 5.333333
  9. b 11.500000
  10. c 5.000000
  11. Name: B, dtype: float64
  12. print(combine1.size())
  13. →A
  14. a 3
  15. b 2
  16. c 1
  17. Name: B, dtype: int64
  18. print(dict(list(combine2)))
  19. →{dtype('int64'): B
  20. 0 10
  21. 1 15
  22. 2 5
  23. 3 2
  24. 4 8
  25. 5 4, dtype('O'): A
  26. 0 a
  27. 1 b
  28. 2 c
  29. 3 a
  30. 4 b
  31. 5 a}
  32. print(combine1.agg("mean"))
  33. →A
  34. a 5.333333
  35. b 11.500000
  36. c 5.000000
  37. Name: B, dtype: float64
  38. print(combine1.agg(["mean", "sum", "std"]))
  39. → mean sum std
  40. A
  41. a 5.333333 16 4.163332
  42. b 11.500000 23 4.949747
  43. c 5.000000 5 NaN
  44. print(combine3.agg({"B1": "mean", "B2": "sum"}))
  45. → B1 B2
  46. A
  47. a 6.0 10
  48. b 6.5 11
  49. c 6.0 9

(2)数据透视表

  1. df5 = pd.DataFrame({"level": ['a', 'b', 'c', 'b', 'a'],
  2. "key": ["one", "two", "one", "two", "one"],
  3. "num1": [3, 5, 6, 8, 9],
  4. "num2": [2, 5, 9, 6, 8]})
  5. print(df5.pivot_table(index="key", columns="level"))
  6. → num1 num2
  7. level a b c a b c
  8. key
  9. one 6.0 NaN 6.0 5.0 NaN 9.0
  10. two NaN 6.5 NaN NaN 5.5 NaN
  11. print(pd.crosstab(df5.key, df5.level, margins=True)) # 计算分组频率
  12. →level a b c All
  13. key
  14. one 2 0 1 3
  15. two 0 2 0 2
  16. All 2 2 1 5

2、数据变换与数据规约

(1)规范化

        主要分为标准化和归一化,都属于线性变换,主要区别为:归一化只与最大值和最小值有关,容易受到极值点影响,输出范围为0~1;标准化是依据样本总体的变换,每个样本点都有贡献,输出范围为实数范围。这里使用iris数据集演示:

  1. transfer1 = MinMaxScaler(feature_range=(0, 1))
  2. transfer2 = StandardScaler()
  3. iris = load_iris()
  4. df6 = transfer1.fit_transform(iris.data)
  5. df7 = transfer2.fit_transform(iris.data)
  6. print(iris.data)
  7. →[[5.1 3.5 1.4 0.2]
  8. [4.9 3. 1.4 0.2]
  9. [4.7 3.2 1.3 0.2]
  10. [4.6 3.1 1.5 0.2]
  11. [5. 3.6 1.4 0.2]
  12. [5.4 3.9 1.7 0.4]
  13. [4.6 3.4 1.4 0.3]
  14. [5. 3.4 1.5 0.2]
  15. [4.4 2.9 1.4 0.2]
  16. [4.9 3.1 1.5 0.1]
  17. [5.4 3.7 1.5 0.2]
  18. [4.8 3.4 1.6 0.2]
  19. [4.8 3. 1.4 0.1]
  20. [4.3 3. 1.1 0.1]
  21. [5.8 4. 1.2 0.2]
  22. [5.7 4.4 1.5 0.4]
  23. [5.4 3.9 1.3 0.4]
  24. [5.1 3.5 1.4 0.3]
  25. [5.7 3.8 1.7 0.3]
  26. [5.1 3.8 1.5 0.3]
  27. [5.4 3.4 1.7 0.2]
  28. [5.1 3.7 1.5 0.4]
  29. [4.6 3.6 1. 0.2]
  30. [5.1 3.3 1.7 0.5]
  31. [4.8 3.4 1.9 0.2]
  32. [5. 3. 1.6 0.2]
  33. [5. 3.4 1.6 0.4]
  34. [5.2 3.5 1.5 0.2]
  35. [5.2 3.4 1.4 0.2]
  36. [4.7 3.2 1.6 0.2]
  37. [4.8 3.1 1.6 0.2]
  38. [5.4 3.4 1.5 0.4]
  39. [5.2 4.1 1.5 0.1]
  40. [5.5 4.2 1.4 0.2]
  41. [4.9 3.1 1.5 0.2]
  42. [5. 3.2 1.2 0.2]
  43. [5.5 3.5 1.3 0.2]
  44. [4.9 3.6 1.4 0.1]
  45. [4.4 3. 1.3 0.2]
  46. [5.1 3.4 1.5 0.2]
  47. [5. 3.5 1.3 0.3]
  48. [4.5 2.3 1.3 0.3]
  49. [4.4 3.2 1.3 0.2]
  50. [5. 3.5 1.6 0.6]
  51. [5.1 3.8 1.9 0.4]
  52. [4.8 3. 1.4 0.3]
  53. [5.1 3.8 1.6 0.2]
  54. [4.6 3.2 1.4 0.2]
  55. [5.3 3.7 1.5 0.2]
  56. [5. 3.3 1.4 0.2]
  57. [7. 3.2 4.7 1.4]
  58. [6.4 3.2 4.5 1.5]
  59. [6.9 3.1 4.9 1.5]
  60. [5.5 2.3 4. 1.3]
  61. [6.5 2.8 4.6 1.5]
  62. [5.7 2.8 4.5 1.3]
  63. [6.3 3.3 4.7 1.6]
  64. [4.9 2.4 3.3 1. ]
  65. [6.6 2.9 4.6 1.3]
  66. [5.2 2.7 3.9 1.4]
  67. [5. 2. 3.5 1. ]
  68. [5.9 3. 4.2 1.5]
  69. [6. 2.2 4. 1. ]
  70. [6.1 2.9 4.7 1.4]
  71. [5.6 2.9 3.6 1.3]
  72. [6.7 3.1 4.4 1.4]
  73. [5.6 3. 4.5 1.5]
  74. [5.8 2.7 4.1 1. ]
  75. [6.2 2.2 4.5 1.5]
  76. [5.6 2.5 3.9 1.1]
  77. [5.9 3.2 4.8 1.8]
  78. [6.1 2.8 4. 1.3]
  79. [6.3 2.5 4.9 1.5]
  80. [6.1 2.8 4.7 1.2]
  81. [6.4 2.9 4.3 1.3]
  82. [6.6 3. 4.4 1.4]
  83. [6.8 2.8 4.8 1.4]
  84. [6.7 3. 5. 1.7]
  85. [6. 2.9 4.5 1.5]
  86. [5.7 2.6 3.5 1. ]
  87. [5.5 2.4 3.8 1.1]
  88. [5.5 2.4 3.7 1. ]
  89. [5.8 2.7 3.9 1.2]
  90. [6. 2.7 5.1 1.6]
  91. [5.4 3. 4.5 1.5]
  92. [6. 3.4 4.5 1.6]
  93. [6.7 3.1 4.7 1.5]
  94. [6.3 2.3 4.4 1.3]
  95. [5.6 3. 4.1 1.3]
  96. [5.5 2.5 4. 1.3]
  97. [5.5 2.6 4.4 1.2]
  98. [6.1 3. 4.6 1.4]
  99. [5.8 2.6 4. 1.2]
  100. [5. 2.3 3.3 1. ]
  101. [5.6 2.7 4.2 1.3]
  102. [5.7 3. 4.2 1.2]
  103. [5.7 2.9 4.2 1.3]
  104. [6.2 2.9 4.3 1.3]
  105. [5.1 2.5 3. 1.1]
  106. [5.7 2.8 4.1 1.3]
  107. [6.3 3.3 6. 2.5]
  108. [5.8 2.7 5.1 1.9]
  109. [7.1 3. 5.9 2.1]
  110. [6.3 2.9 5.6 1.8]
  111. [6.5 3. 5.8 2.2]
  112. [7.6 3. 6.6 2.1]
  113. [4.9 2.5 4.5 1.7]
  114. [7.3 2.9 6.3 1.8]
  115. [6.7 2.5 5.8 1.8]
  116. [7.2 3.6 6.1 2.5]
  117. [6.5 3.2 5.1 2. ]
  118. [6.4 2.7 5.3 1.9]
  119. [6.8 3. 5.5 2.1]
  120. [5.7 2.5 5. 2. ]
  121. [5.8 2.8 5.1 2.4]
  122. [6.4 3.2 5.3 2.3]
  123. [6.5 3. 5.5 1.8]
  124. [7.7 3.8 6.7 2.2]
  125. [7.7 2.6 6.9 2.3]
  126. [6. 2.2 5. 1.5]
  127. [6.9 3.2 5.7 2.3]
  128. [5.6 2.8 4.9 2. ]
  129. [7.7 2.8 6.7 2. ]
  130. [6.3 2.7 4.9 1.8]
  131. [6.7 3.3 5.7 2.1]
  132. [7.2 3.2 6. 1.8]
  133. [6.2 2.8 4.8 1.8]
  134. [6.1 3. 4.9 1.8]
  135. [6.4 2.8 5.6 2.1]
  136. [7.2 3. 5.8 1.6]
  137. [7.4 2.8 6.1 1.9]
  138. [7.9 3.8 6.4 2. ]
  139. [6.4 2.8 5.6 2.2]
  140. [6.3 2.8 5.1 1.5]
  141. [6.1 2.6 5.6 1.4]
  142. [7.7 3. 6.1 2.3]
  143. [6.3 3.4 5.6 2.4]
  144. [6.4 3.1 5.5 1.8]
  145. [6. 3. 4.8 1.8]
  146. [6.9 3.1 5.4 2.1]
  147. [6.7 3.1 5.6 2.4]
  148. [6.9 3.1 5.1 2.3]
  149. [5.8 2.7 5.1 1.9]
  150. [6.8 3.2 5.9 2.3]
  151. [6.7 3.3 5.7 2.5]
  152. [6.7 3. 5.2 2.3]
  153. [6.3 2.5 5. 1.9]
  154. [6.5 3. 5.2 2. ]
  155. [6.2 3.4 5.4 2.3]
  156. [5.9 3. 5.1 1.8]]
  157. print(df6)
  158. →[[0.22222222 0.625 0.06779661 0.04166667]
  159. [0.16666667 0.41666667 0.06779661 0.04166667]
  160. [0.11111111 0.5 0.05084746 0.04166667]
  161. [0.08333333 0.45833333 0.08474576 0.04166667]
  162. [0.19444444 0.66666667 0.06779661 0.04166667]
  163. [0.30555556 0.79166667 0.11864407 0.125 ]
  164. [0.08333333 0.58333333 0.06779661 0.08333333]
  165. [0.19444444 0.58333333 0.08474576 0.04166667]
  166. [0.02777778 0.375 0.06779661 0.04166667]
  167. [0.16666667 0.45833333 0.08474576 0. ]
  168. [0.30555556 0.70833333 0.08474576 0.04166667]
  169. [0.13888889 0.58333333 0.10169492 0.04166667]
  170. [0.13888889 0.41666667 0.06779661 0. ]
  171. [0. 0.41666667 0.01694915 0. ]
  172. [0.41666667 0.83333333 0.03389831 0.04166667]
  173. [0.38888889 1. 0.08474576 0.125 ]
  174. [0.30555556 0.79166667 0.05084746 0.125 ]
  175. [0.22222222 0.625 0.06779661 0.08333333]
  176. [0.38888889 0.75 0.11864407 0.08333333]
  177. [0.22222222 0.75 0.08474576 0.08333333]
  178. [0.30555556 0.58333333 0.11864407 0.04166667]
  179. [0.22222222 0.70833333 0.08474576 0.125 ]
  180. [0.08333333 0.66666667 0. 0.04166667]
  181. [0.22222222 0.54166667 0.11864407 0.16666667]
  182. [0.13888889 0.58333333 0.15254237 0.04166667]
  183. [0.19444444 0.41666667 0.10169492 0.04166667]
  184. [0.19444444 0.58333333 0.10169492 0.125 ]
  185. [0.25 0.625 0.08474576 0.04166667]
  186. [0.25 0.58333333 0.06779661 0.04166667]
  187. [0.11111111 0.5 0.10169492 0.04166667]
  188. [0.13888889 0.45833333 0.10169492 0.04166667]
  189. [0.30555556 0.58333333 0.08474576 0.125 ]
  190. [0.25 0.875 0.08474576 0. ]
  191. [0.33333333 0.91666667 0.06779661 0.04166667]
  192. [0.16666667 0.45833333 0.08474576 0.04166667]
  193. [0.19444444 0.5 0.03389831 0.04166667]
  194. [0.33333333 0.625 0.05084746 0.04166667]
  195. [0.16666667 0.66666667 0.06779661 0. ]
  196. [0.02777778 0.41666667 0.05084746 0.04166667]
  197. [0.22222222 0.58333333 0.08474576 0.04166667]
  198. [0.19444444 0.625 0.05084746 0.08333333]
  199. [0.05555556 0.125 0.05084746 0.08333333]
  200. [0.02777778 0.5 0.05084746 0.04166667]
  201. [0.19444444 0.625 0.10169492 0.20833333]
  202. [0.22222222 0.75 0.15254237 0.125 ]
  203. [0.13888889 0.41666667 0.06779661 0.08333333]
  204. [0.22222222 0.75 0.10169492 0.04166667]
  205. [0.08333333 0.5 0.06779661 0.04166667]
  206. [0.27777778 0.70833333 0.08474576 0.04166667]
  207. [0.19444444 0.54166667 0.06779661 0.04166667]
  208. [0.75 0.5 0.62711864 0.54166667]
  209. [0.58333333 0.5 0.59322034 0.58333333]
  210. [0.72222222 0.45833333 0.66101695 0.58333333]
  211. [0.33333333 0.125 0.50847458 0.5 ]
  212. [0.61111111 0.33333333 0.61016949 0.58333333]
  213. [0.38888889 0.33333333 0.59322034 0.5 ]
  214. [0.55555556 0.54166667 0.62711864 0.625 ]
  215. [0.16666667 0.16666667 0.38983051 0.375 ]
  216. [0.63888889 0.375 0.61016949 0.5 ]
  217. [0.25 0.29166667 0.49152542 0.54166667]
  218. [0.19444444 0. 0.42372881 0.375 ]
  219. [0.44444444 0.41666667 0.54237288 0.58333333]
  220. [0.47222222 0.08333333 0.50847458 0.375 ]
  221. [0.5 0.375 0.62711864 0.54166667]
  222. [0.36111111 0.375 0.44067797 0.5 ]
  223. [0.66666667 0.45833333 0.57627119 0.54166667]
  224. [0.36111111 0.41666667 0.59322034 0.58333333]
  225. [0.41666667 0.29166667 0.52542373 0.375 ]
  226. [0.52777778 0.08333333 0.59322034 0.58333333]
  227. [0.36111111 0.20833333 0.49152542 0.41666667]
  228. [0.44444444 0.5 0.6440678 0.70833333]
  229. [0.5 0.33333333 0.50847458 0.5 ]
  230. [0.55555556 0.20833333 0.66101695 0.58333333]
  231. [0.5 0.33333333 0.62711864 0.45833333]
  232. [0.58333333 0.375 0.55932203 0.5 ]
  233. [0.63888889 0.41666667 0.57627119 0.54166667]
  234. [0.69444444 0.33333333 0.6440678 0.54166667]
  235. [0.66666667 0.41666667 0.6779661 0.66666667]
  236. [0.47222222 0.375 0.59322034 0.58333333]
  237. [0.38888889 0.25 0.42372881 0.375 ]
  238. [0.33333333 0.16666667 0.47457627 0.41666667]
  239. [0.33333333 0.16666667 0.45762712 0.375 ]
  240. [0.41666667 0.29166667 0.49152542 0.45833333]
  241. [0.47222222 0.29166667 0.69491525 0.625 ]
  242. [0.30555556 0.41666667 0.59322034 0.58333333]
  243. [0.47222222 0.58333333 0.59322034 0.625 ]
  244. [0.66666667 0.45833333 0.62711864 0.58333333]
  245. [0.55555556 0.125 0.57627119 0.5 ]
  246. [0.36111111 0.41666667 0.52542373 0.5 ]
  247. [0.33333333 0.20833333 0.50847458 0.5 ]
  248. [0.33333333 0.25 0.57627119 0.45833333]
  249. [0.5 0.41666667 0.61016949 0.54166667]
  250. [0.41666667 0.25 0.50847458 0.45833333]
  251. [0.19444444 0.125 0.38983051 0.375 ]
  252. [0.36111111 0.29166667 0.54237288 0.5 ]
  253. [0.38888889 0.41666667 0.54237288 0.45833333]
  254. [0.38888889 0.375 0.54237288 0.5 ]
  255. [0.52777778 0.375 0.55932203 0.5 ]
  256. [0.22222222 0.20833333 0.33898305 0.41666667]
  257. [0.38888889 0.33333333 0.52542373 0.5 ]
  258. [0.55555556 0.54166667 0.84745763 1. ]
  259. [0.41666667 0.29166667 0.69491525 0.75 ]
  260. [0.77777778 0.41666667 0.83050847 0.83333333]
  261. [0.55555556 0.375 0.77966102 0.70833333]
  262. [0.61111111 0.41666667 0.81355932 0.875 ]
  263. [0.91666667 0.41666667 0.94915254 0.83333333]
  264. [0.16666667 0.20833333 0.59322034 0.66666667]
  265. [0.83333333 0.375 0.89830508 0.70833333]
  266. [0.66666667 0.20833333 0.81355932 0.70833333]
  267. [0.80555556 0.66666667 0.86440678 1. ]
  268. [0.61111111 0.5 0.69491525 0.79166667]
  269. [0.58333333 0.29166667 0.72881356 0.75 ]
  270. [0.69444444 0.41666667 0.76271186 0.83333333]
  271. [0.38888889 0.20833333 0.6779661 0.79166667]
  272. [0.41666667 0.33333333 0.69491525 0.95833333]
  273. [0.58333333 0.5 0.72881356 0.91666667]
  274. [0.61111111 0.41666667 0.76271186 0.70833333]
  275. [0.94444444 0.75 0.96610169 0.875 ]
  276. [0.94444444 0.25 1. 0.91666667]
  277. [0.47222222 0.08333333 0.6779661 0.58333333]
  278. [0.72222222 0.5 0.79661017 0.91666667]
  279. [0.36111111 0.33333333 0.66101695 0.79166667]
  280. [0.94444444 0.33333333 0.96610169 0.79166667]
  281. [0.55555556 0.29166667 0.66101695 0.70833333]
  282. [0.66666667 0.54166667 0.79661017 0.83333333]
  283. [0.80555556 0.5 0.84745763 0.70833333]
  284. [0.52777778 0.33333333 0.6440678 0.70833333]
  285. [0.5 0.41666667 0.66101695 0.70833333]
  286. [0.58333333 0.33333333 0.77966102 0.83333333]
  287. [0.80555556 0.41666667 0.81355932 0.625 ]
  288. [0.86111111 0.33333333 0.86440678 0.75 ]
  289. [1. 0.75 0.91525424 0.79166667]
  290. [0.58333333 0.33333333 0.77966102 0.875 ]
  291. [0.55555556 0.33333333 0.69491525 0.58333333]
  292. [0.5 0.25 0.77966102 0.54166667]
  293. [0.94444444 0.41666667 0.86440678 0.91666667]
  294. [0.55555556 0.58333333 0.77966102 0.95833333]
  295. [0.58333333 0.45833333 0.76271186 0.70833333]
  296. [0.47222222 0.41666667 0.6440678 0.70833333]
  297. [0.72222222 0.45833333 0.74576271 0.83333333]
  298. [0.66666667 0.45833333 0.77966102 0.95833333]
  299. [0.72222222 0.45833333 0.69491525 0.91666667]
  300. [0.41666667 0.29166667 0.69491525 0.75 ]
  301. [0.69444444 0.5 0.83050847 0.91666667]
  302. [0.66666667 0.54166667 0.79661017 1. ]
  303. [0.66666667 0.41666667 0.71186441 0.91666667]
  304. [0.55555556 0.20833333 0.6779661 0.75 ]
  305. [0.61111111 0.41666667 0.71186441 0.79166667]
  306. [0.52777778 0.58333333 0.74576271 0.91666667]
  307. [0.44444444 0.41666667 0.69491525 0.70833333]]
  308. print(df7)
  309. →[[-9.00681170e-01 1.01900435e+00 -1.34022653e+00 -1.31544430e+00]
  310. [-1.14301691e+00 -1.31979479e-01 -1.34022653e+00 -1.31544430e+00]
  311. [-1.38535265e+00 3.28414053e-01 -1.39706395e+00 -1.31544430e+00]
  312. [-1.50652052e+00 9.82172869e-02 -1.28338910e+00 -1.31544430e+00]
  313. [-1.02184904e+00 1.24920112e+00 -1.34022653e+00 -1.31544430e+00]
  314. [-5.37177559e-01 1.93979142e+00 -1.16971425e+00 -1.05217993e+00]
  315. [-1.50652052e+00 7.88807586e-01 -1.34022653e+00 -1.18381211e+00]
  316. [-1.02184904e+00 7.88807586e-01 -1.28338910e+00 -1.31544430e+00]
  317. [-1.74885626e+00 -3.62176246e-01 -1.34022653e+00 -1.31544430e+00]
  318. [-1.14301691e+00 9.82172869e-02 -1.28338910e+00 -1.44707648e+00]
  319. [-5.37177559e-01 1.47939788e+00 -1.28338910e+00 -1.31544430e+00]
  320. [-1.26418478e+00 7.88807586e-01 -1.22655167e+00 -1.31544430e+00]
  321. [-1.26418478e+00 -1.31979479e-01 -1.34022653e+00 -1.44707648e+00]
  322. [-1.87002413e+00 -1.31979479e-01 -1.51073881e+00 -1.44707648e+00]
  323. [-5.25060772e-02 2.16998818e+00 -1.45390138e+00 -1.31544430e+00]
  324. [-1.73673948e-01 3.09077525e+00 -1.28338910e+00 -1.05217993e+00]
  325. [-5.37177559e-01 1.93979142e+00 -1.39706395e+00 -1.05217993e+00]
  326. [-9.00681170e-01 1.01900435e+00 -1.34022653e+00 -1.18381211e+00]
  327. [-1.73673948e-01 1.70959465e+00 -1.16971425e+00 -1.18381211e+00]
  328. [-9.00681170e-01 1.70959465e+00 -1.28338910e+00 -1.18381211e+00]
  329. [-5.37177559e-01 7.88807586e-01 -1.16971425e+00 -1.31544430e+00]
  330. [-9.00681170e-01 1.47939788e+00 -1.28338910e+00 -1.05217993e+00]
  331. [-1.50652052e+00 1.24920112e+00 -1.56757623e+00 -1.31544430e+00]
  332. [-9.00681170e-01 5.58610819e-01 -1.16971425e+00 -9.20547742e-01]
  333. [-1.26418478e+00 7.88807586e-01 -1.05603939e+00 -1.31544430e+00]
  334. [-1.02184904e+00 -1.31979479e-01 -1.22655167e+00 -1.31544430e+00]
  335. [-1.02184904e+00 7.88807586e-01 -1.22655167e+00 -1.05217993e+00]
  336. [-7.79513300e-01 1.01900435e+00 -1.28338910e+00 -1.31544430e+00]
  337. [-7.79513300e-01 7.88807586e-01 -1.34022653e+00 -1.31544430e+00]
  338. [-1.38535265e+00 3.28414053e-01 -1.22655167e+00 -1.31544430e+00]
  339. [-1.26418478e+00 9.82172869e-02 -1.22655167e+00 -1.31544430e+00]
  340. [-5.37177559e-01 7.88807586e-01 -1.28338910e+00 -1.05217993e+00]
  341. [-7.79513300e-01 2.40018495e+00 -1.28338910e+00 -1.44707648e+00]
  342. [-4.16009689e-01 2.63038172e+00 -1.34022653e+00 -1.31544430e+00]
  343. [-1.14301691e+00 9.82172869e-02 -1.28338910e+00 -1.31544430e+00]
  344. [-1.02184904e+00 3.28414053e-01 -1.45390138e+00 -1.31544430e+00]
  345. [-4.16009689e-01 1.01900435e+00 -1.39706395e+00 -1.31544430e+00]
  346. [-1.14301691e+00 1.24920112e+00 -1.34022653e+00 -1.44707648e+00]
  347. [-1.74885626e+00 -1.31979479e-01 -1.39706395e+00 -1.31544430e+00]
  348. [-9.00681170e-01 7.88807586e-01 -1.28338910e+00 -1.31544430e+00]
  349. [-1.02184904e+00 1.01900435e+00 -1.39706395e+00 -1.18381211e+00]
  350. [-1.62768839e+00 -1.74335684e+00 -1.39706395e+00 -1.18381211e+00]
  351. [-1.74885626e+00 3.28414053e-01 -1.39706395e+00 -1.31544430e+00]
  352. [-1.02184904e+00 1.01900435e+00 -1.22655167e+00 -7.88915558e-01]
  353. [-9.00681170e-01 1.70959465e+00 -1.05603939e+00 -1.05217993e+00]
  354. [-1.26418478e+00 -1.31979479e-01 -1.34022653e+00 -1.18381211e+00]
  355. [-9.00681170e-01 1.70959465e+00 -1.22655167e+00 -1.31544430e+00]
  356. [-1.50652052e+00 3.28414053e-01 -1.34022653e+00 -1.31544430e+00]
  357. [-6.58345429e-01 1.47939788e+00 -1.28338910e+00 -1.31544430e+00]
  358. [-1.02184904e+00 5.58610819e-01 -1.34022653e+00 -1.31544430e+00]
  359. [ 1.40150837e+00 3.28414053e-01 5.35408562e-01 2.64141916e-01]
  360. [ 6.74501145e-01 3.28414053e-01 4.21733708e-01 3.95774101e-01]
  361. [ 1.28034050e+00 9.82172869e-02 6.49083415e-01 3.95774101e-01]
  362. [-4.16009689e-01 -1.74335684e+00 1.37546573e-01 1.32509732e-01]
  363. [ 7.95669016e-01 -5.92373012e-01 4.78571135e-01 3.95774101e-01]
  364. [-1.73673948e-01 -5.92373012e-01 4.21733708e-01 1.32509732e-01]
  365. [ 5.53333275e-01 5.58610819e-01 5.35408562e-01 5.27406285e-01]
  366. [-1.14301691e+00 -1.51316008e+00 -2.60315415e-01 -2.62386821e-01]
  367. [ 9.16836886e-01 -3.62176246e-01 4.78571135e-01 1.32509732e-01]
  368. [-7.79513300e-01 -8.22569778e-01 8.07091462e-02 2.64141916e-01]
  369. [-1.02184904e+00 -2.43394714e+00 -1.46640561e-01 -2.62386821e-01]
  370. [ 6.86617933e-02 -1.31979479e-01 2.51221427e-01 3.95774101e-01]
  371. [ 1.89829664e-01 -1.97355361e+00 1.37546573e-01 -2.62386821e-01]
  372. [ 3.10997534e-01 -3.62176246e-01 5.35408562e-01 2.64141916e-01]
  373. [-2.94841818e-01 -3.62176246e-01 -8.98031345e-02 1.32509732e-01]
  374. [ 1.03800476e+00 9.82172869e-02 3.64896281e-01 2.64141916e-01]
  375. [-2.94841818e-01 -1.31979479e-01 4.21733708e-01 3.95774101e-01]
  376. [-5.25060772e-02 -8.22569778e-01 1.94384000e-01 -2.62386821e-01]
  377. [ 4.32165405e-01 -1.97355361e+00 4.21733708e-01 3.95774101e-01]
  378. [-2.94841818e-01 -1.28296331e+00 8.07091462e-02 -1.30754636e-01]
  379. [ 6.86617933e-02 3.28414053e-01 5.92245988e-01 7.90670654e-01]
  380. [ 3.10997534e-01 -5.92373012e-01 1.37546573e-01 1.32509732e-01]
  381. [ 5.53333275e-01 -1.28296331e+00 6.49083415e-01 3.95774101e-01]
  382. [ 3.10997534e-01 -5.92373012e-01 5.35408562e-01 8.77547895e-04]
  383. [ 6.74501145e-01 -3.62176246e-01 3.08058854e-01 1.32509732e-01]
  384. [ 9.16836886e-01 -1.31979479e-01 3.64896281e-01 2.64141916e-01]
  385. [ 1.15917263e+00 -5.92373012e-01 5.92245988e-01 2.64141916e-01]
  386. [ 1.03800476e+00 -1.31979479e-01 7.05920842e-01 6.59038469e-01]
  387. [ 1.89829664e-01 -3.62176246e-01 4.21733708e-01 3.95774101e-01]
  388. [-1.73673948e-01 -1.05276654e+00 -1.46640561e-01 -2.62386821e-01]
  389. [-4.16009689e-01 -1.51316008e+00 2.38717193e-02 -1.30754636e-01]
  390. [-4.16009689e-01 -1.51316008e+00 -3.29657076e-02 -2.62386821e-01]
  391. [-5.25060772e-02 -8.22569778e-01 8.07091462e-02 8.77547895e-04]
  392. [ 1.89829664e-01 -8.22569778e-01 7.62758269e-01 5.27406285e-01]
  393. [-5.37177559e-01 -1.31979479e-01 4.21733708e-01 3.95774101e-01]
  394. [ 1.89829664e-01 7.88807586e-01 4.21733708e-01 5.27406285e-01]
  395. [ 1.03800476e+00 9.82172869e-02 5.35408562e-01 3.95774101e-01]
  396. [ 5.53333275e-01 -1.74335684e+00 3.64896281e-01 1.32509732e-01]
  397. [-2.94841818e-01 -1.31979479e-01 1.94384000e-01 1.32509732e-01]
  398. [-4.16009689e-01 -1.28296331e+00 1.37546573e-01 1.32509732e-01]
  399. [-4.16009689e-01 -1.05276654e+00 3.64896281e-01 8.77547895e-04]
  400. [ 3.10997534e-01 -1.31979479e-01 4.78571135e-01 2.64141916e-01]
  401. [-5.25060772e-02 -1.05276654e+00 1.37546573e-01 8.77547895e-04]
  402. [-1.02184904e+00 -1.74335684e+00 -2.60315415e-01 -2.62386821e-01]
  403. [-2.94841818e-01 -8.22569778e-01 2.51221427e-01 1.32509732e-01]
  404. [-1.73673948e-01 -1.31979479e-01 2.51221427e-01 8.77547895e-04]
  405. [-1.73673948e-01 -3.62176246e-01 2.51221427e-01 1.32509732e-01]
  406. [ 4.32165405e-01 -3.62176246e-01 3.08058854e-01 1.32509732e-01]
  407. [-9.00681170e-01 -1.28296331e+00 -4.30827696e-01 -1.30754636e-01]
  408. [-1.73673948e-01 -5.92373012e-01 1.94384000e-01 1.32509732e-01]
  409. [ 5.53333275e-01 5.58610819e-01 1.27429511e+00 1.71209594e+00]
  410. [-5.25060772e-02 -8.22569778e-01 7.62758269e-01 9.22302838e-01]
  411. [ 1.52267624e+00 -1.31979479e-01 1.21745768e+00 1.18556721e+00]
  412. [ 5.53333275e-01 -3.62176246e-01 1.04694540e+00 7.90670654e-01]
  413. [ 7.95669016e-01 -1.31979479e-01 1.16062026e+00 1.31719939e+00]
  414. [ 2.12851559e+00 -1.31979479e-01 1.61531967e+00 1.18556721e+00]
  415. [-1.14301691e+00 -1.28296331e+00 4.21733708e-01 6.59038469e-01]
  416. [ 1.76501198e+00 -3.62176246e-01 1.44480739e+00 7.90670654e-01]
  417. [ 1.03800476e+00 -1.28296331e+00 1.16062026e+00 7.90670654e-01]
  418. [ 1.64384411e+00 1.24920112e+00 1.33113254e+00 1.71209594e+00]
  419. [ 7.95669016e-01 3.28414053e-01 7.62758269e-01 1.05393502e+00]
  420. [ 6.74501145e-01 -8.22569778e-01 8.76433123e-01 9.22302838e-01]
  421. [ 1.15917263e+00 -1.31979479e-01 9.90107977e-01 1.18556721e+00]
  422. [-1.73673948e-01 -1.28296331e+00 7.05920842e-01 1.05393502e+00]
  423. [-5.25060772e-02 -5.92373012e-01 7.62758269e-01 1.58046376e+00]
  424. [ 6.74501145e-01 3.28414053e-01 8.76433123e-01 1.44883158e+00]
  425. [ 7.95669016e-01 -1.31979479e-01 9.90107977e-01 7.90670654e-01]
  426. [ 2.24968346e+00 1.70959465e+00 1.67215710e+00 1.31719939e+00]
  427. [ 2.24968346e+00 -1.05276654e+00 1.78583195e+00 1.44883158e+00]
  428. [ 1.89829664e-01 -1.97355361e+00 7.05920842e-01 3.95774101e-01]
  429. [ 1.28034050e+00 3.28414053e-01 1.10378283e+00 1.44883158e+00]
  430. [-2.94841818e-01 -5.92373012e-01 6.49083415e-01 1.05393502e+00]
  431. [ 2.24968346e+00 -5.92373012e-01 1.67215710e+00 1.05393502e+00]
  432. [ 5.53333275e-01 -8.22569778e-01 6.49083415e-01 7.90670654e-01]
  433. [ 1.03800476e+00 5.58610819e-01 1.10378283e+00 1.18556721e+00]
  434. [ 1.64384411e+00 3.28414053e-01 1.27429511e+00 7.90670654e-01]
  435. [ 4.32165405e-01 -5.92373012e-01 5.92245988e-01 7.90670654e-01]
  436. [ 3.10997534e-01 -1.31979479e-01 6.49083415e-01 7.90670654e-01]
  437. [ 6.74501145e-01 -5.92373012e-01 1.04694540e+00 1.18556721e+00]
  438. [ 1.64384411e+00 -1.31979479e-01 1.16062026e+00 5.27406285e-01]
  439. [ 1.88617985e+00 -5.92373012e-01 1.33113254e+00 9.22302838e-01]
  440. [ 2.49201920e+00 1.70959465e+00 1.50164482e+00 1.05393502e+00]
  441. [ 6.74501145e-01 -5.92373012e-01 1.04694540e+00 1.31719939e+00]
  442. [ 5.53333275e-01 -5.92373012e-01 7.62758269e-01 3.95774101e-01]
  443. [ 3.10997534e-01 -1.05276654e+00 1.04694540e+00 2.64141916e-01]
  444. [ 2.24968346e+00 -1.31979479e-01 1.33113254e+00 1.44883158e+00]
  445. [ 5.53333275e-01 7.88807586e-01 1.04694540e+00 1.58046376e+00]
  446. [ 6.74501145e-01 9.82172869e-02 9.90107977e-01 7.90670654e-01]
  447. [ 1.89829664e-01 -1.31979479e-01 5.92245988e-01 7.90670654e-01]
  448. [ 1.28034050e+00 9.82172869e-02 9.33270550e-01 1.18556721e+00]
  449. [ 1.03800476e+00 9.82172869e-02 1.04694540e+00 1.58046376e+00]
  450. [ 1.28034050e+00 9.82172869e-02 7.62758269e-01 1.44883158e+00]
  451. [-5.25060772e-02 -8.22569778e-01 7.62758269e-01 9.22302838e-01]
  452. [ 1.15917263e+00 3.28414053e-01 1.21745768e+00 1.44883158e+00]
  453. [ 1.03800476e+00 5.58610819e-01 1.10378283e+00 1.71209594e+00]
  454. [ 1.03800476e+00 -1.31979479e-01 8.19595696e-01 1.44883158e+00]
  455. [ 5.53333275e-01 -1.28296331e+00 7.05920842e-01 9.22302838e-01]
  456. [ 7.95669016e-01 -1.31979479e-01 8.19595696e-01 1.05393502e+00]
  457. [ 4.32165405e-01 7.88807586e-01 9.33270550e-01 1.44883158e+00]
  458. [ 6.86617933e-02 -1.31979479e-01 7.62758269e-01 7.90670654e-01]]

(2)离散化

        指把连续型变量转化为离散型变量的过程,可理解为连续值的一种映射。

  1. ages = [31, 27, 11, 38, 15, 74, 44, 32, 54, 63, 41, 23]
  2. bins = [15, 25, 45, 65, 100]
  3. group_names = ["A", "B", "C", "D"]
'
运行
① 等宽法

        按照变量的取值范围进行区间等长度划分,从而获得切分点和切分区间。

  1. print(list(pd.cut(ages, bins, labels=group_names)))
  2. →['B', 'B', nan, 'B', nan, 'D', 'B', 'B', 'C', 'C', 'B', 'A']
② 等频法

        按照分位数的概念对区间进行切分,已达到每个区间频数近似相等的效果。

  1. print(list(pd.qcut(ages, 4)))
  2. →[Interval(26.0, 35.0, closed='right'), Interval(26.0, 35.0, closed='right'),
  3. Interval(10.999, 26.0, closed='right'), Interval(35.0, 46.5, closed='right'),
  4. Interval(10.999, 26.0, closed='right'), Interval(46.5, 74.0, closed='right'),
  5. Interval(35.0, 46.5, closed='right'), Interval(26.0, 35.0, closed='right'),
  6. Interval(46.5, 74.0, closed='right'), Interval(46.5, 74.0, closed='right'),
  7. Interval(35.0, 46.5, closed='right'), Interval(10.999, 26.0, closed='right')]

(3)编码

        序号编码实际上是特征的映射,并且序号编码是对有先后顺序的变量值或者变量类别进行的编码。

  1. df8 = pd.DataFrame({"gender": ["male", "female", "male", "male", "female"]})
  2. print(df8["gender"].replace(["male", "female"], [1.0, 0.0]))
  3. 0 1.0
  4. 1 0.0
  5. 2 1.0
  6. 3 1.0
  7. 4 0.0
  8. Name: gender, dtype: float64
  9. print(df8["gender"].map({"male": 1.0, "female": 0.0}))
  10. 0 1.0
  11. 1 0.0
  12. 2 1.0
  13. 3 1.0
  14. 4 0.0
  15. Name: gender, dtype: float64

(4)数据规约

        数据规约产生更小且保持完整性的新数据集,在规约后的数据集上进行分析和挖掘将提高效率。

① 属性规约

        属性规约通过属性合并创建新属性维数,或者通过直接删除不相关的属性来减少数据维数,从而提高数据挖掘的效率,降低计算成本。

属性规约常用方法
属性规约方法方法描述
合并属性将一些旧属性合并为新属性
逐步向前选择从一个空属性集开始,每次从原来属性集合中选择一个当前最优的属性添加到当前属性子集中,直到无法选出最优属性或满足一定阈值约束为止
逐步向后删除从全属性集开始,每次从当前属性子集中选择一个当前最差属性并将其从当前属性子集中消去
决策树归纳利用决策树的归纳方法对初始数据进行分类归纳学习,获得一个初始决策树,所有没有出现在决策树上的属性均可认为是无关属性,因此可以将这些属性删除
主成分分析用较少的变量去解释原数据中的大部分变量,将许多相关性很高的变量转化成彼此相互独立或不相关变量
② 数值规约

        用替代的、较小的数据表示形式换原始数据。这些技术可以是参数或者非参数的。

对于参数方法而言,使用模型估计数据,使得一般只需要存放模型参数而不是实际数据(离群点需存放),如回归和对数-线性模型。

存放数值规约表示的非参数方法包括: 直方图、聚类、抽样和数据立方体聚类。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/798146
推荐阅读
相关标签
  

闽ICP备14008679号