导入波士顿房价数据集,计算房价的最小值,最大值,均值,中位数,方差,标准差,协方差。 import sklearn.datasets as datasets import pandas as pd import numpy as np boston=datasets.load_boston()#导入数据集
时间: 2023-06-20 10:10:40 浏览: 507
import sklearn.datasets as datasets
import pandas as pd
import numpy as np
boston = datasets.load_boston() # 导入波士顿房价数据集
# 将数据集转化为DataFrame格式
boston_df = pd.DataFrame(boston.data,columns=boston.feature_names)
# 添加目标值MEDV
boston_df['MEDV'] = boston.target
# 计算房价的最小值,最大值,均值,中位数,方差,标准差,协方差
min_price = np.min(boston.target)
max_price = np.max(boston.target)
mean_price = np.mean(boston.target)
median_price = np.median(boston.target)
variance_price = np.var(boston.target)
std_dev_price = np.std(boston.target)
covariance_matrix = np.cov(boston.data.T)
print("房价的最小值是:", min_price)
print("房价的最大值是:", max_price)
print("房价的均值是:", mean_price)
print("房价的中位数是:", median_price)
print("房价的方差是:", variance_price)
print("房价的标准差是:", std_dev_price)
print("房价的协方差矩阵是:\n", covariance_matrix)
阅读全文