Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
73 строки
3.0 KiB
Python
73 строки
3.0 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
import seaborn as sb
|
|
import pingouin as pg
|
|
from scipy import stats
|
|
|
|
# Датасет "Рост-Вес-Возраст-Позиция"
|
|
columns = ['Position', 'Height(inches)', 'Weight(pounds)', 'Age']
|
|
|
|
df = pd.read_csv('SOCR_Data_MLB_HeightsWeights.txt', sep='\t', nrows = 115, usecols = columns)
|
|
|
|
#replace_dict = {'Catcher':1, 'First_Baseman':2, 'Second_Baseman':3, 'Shortstop':4, 'Third_Baseman':5,
|
|
# 'Outfielder':6, 'Designated_Hitter':7, 'Starting_Pitcher':8, 'Relief_Pitcher':9}
|
|
|
|
#pd.set_option('future.no_silent_downcasting', True)
|
|
#df['Position'] = df['Position'].replace(replace_dict)
|
|
#Index(['Name', 'Team', 'Position', 'Height(inches)', 'Weight(pounds)', 'Age'], dtype='object')
|
|
|
|
|
|
|
|
# Построение диаграммы Тьюки
|
|
fig1, axes = plt.subplots(2, 2, zfigsize=(10, 10))
|
|
fig1.suptitle('Диаграммы Тюки по признакам')
|
|
|
|
axes[0,0].boxplot(df['Position'], tick_labels = ['Position'])
|
|
axes[0,1].boxplot(df['Height(inches)'], tick_labels = ['Height(inches)'])
|
|
axes[1,0].boxplot(df['Weight(pounds)'], tick_labels = ['Weight(pounds)'])
|
|
axes[1,1].boxplot(df['Age'], tick_labels = ['Age'])
|
|
|
|
fig2, axes = plt.subplots(1, 2, figsize=(12, 5))
|
|
fig2.suptitle('Тепловые карты')
|
|
|
|
# Построение тепловой карты парных коэффициентов корреляции
|
|
corrMatrix = df.corr()
|
|
axes[0].set_title('Тепловая карта парных коэфф. корреляции')
|
|
sb.heatmap(corrMatrix, annot=True, linewidths=0.5, xticklabels = False, yticklabels = False, ax = axes[0])
|
|
|
|
|
|
# Построение тепловой карты частных коэффициентов корреляции
|
|
pCorrMatrix = df.pcorr()
|
|
axes[1].set_title('Тепловая карта частных коэфф. корреляции')
|
|
sb.heatmap(pCorrMatrix, annot=True, linewidths=0.5, xticklabels = False, yticklabels = False, ax = axes[1])
|
|
|
|
|
|
|
|
print('Тест Колмогорова-Смирнова. Уровень значимости a = 0.05')
|
|
|
|
for col in columns:
|
|
x = df[col]
|
|
x_mean, std = np.mean(x), np.std(x, ddof = 1)
|
|
x_std = (x - x_mean)/std
|
|
pvalue = stats.kstest(x_std, "norm", alternative='less').pvalue
|
|
if pvalue > 0.05: result = 'H0 не должна быть отвергнута'
|
|
else: result = 'H0 должна быть отвергнута'
|
|
print('Для {}: p-value: {}, так что {}'.format(col, pvalue, result))
|
|
|
|
# Построение гистограмм по выборкам
|
|
fig2, axes = plt.subplots(2, 2, figsize=(10, 7))
|
|
|
|
axes[0,0].hist(df['Position'])
|
|
axes[0,0].set_title('Гисотграмма по значениям Position')
|
|
|
|
axes[0,1].hist(df['Height(inches)'])
|
|
axes[0,1].set_title('Гисотграмма по значениям Height(inches)')
|
|
|
|
axes[1,0].hist(df['Weight(pounds)'])
|
|
axes[1,0].set_title('Гисотграмма по значениям Weight(pounds)')
|
|
|
|
axes[1,1].hist(df['Age'])
|
|
axes[1,1].set_title('Гисотграмма по значениям Age')
|
|
|
|
plt.show() |