【问题标题】:calculating prices in the load_boston dataset in python在 python 中计算 load_boston 数据集中的价格
【发布时间】:2020-07-30 05:26:51
【问题描述】:

我是机器学习的新手,需要为我的项目构建房价预测模型

我正在使用来自 https://www.ritchieng.com/machine-learning-project-boston-home-prices/ 的教程,但我得到的价格价值却截然不同

# Importing the libraries necessary for this project
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston

# Loading the datasets for prediction
boston = load_boston()
prices = boston.target

boston_frame= pd.DataFrame(boston.data, columns=boston.feature_names)
boston_frame['MEDV'] = prices
boston_frame.describe()

# Calculating the minimum, maximum, mean, median and standard deviation of 'MEDV'(i.e prices) in boston
minimum_price = prices.min()
maximum_price = np.max(prices)
mean_price = np.mean(prices)
median_price = np.median(prices)
std_price = np.std(prices)


# Show the calculated statistics
print("Statistics for Boston housing dataset:\n")
print(f"Minimum price: ${(minimum_price):.2f}")
print(f"Maximum price: ${(maximum_price):.2f}")
print(f"Mean price: ${(mean_price):.2f}")
print(f"Median price: ${(median_price):.2f}")
print(f"Standard Deviation of price: ${(std_price):.2f}")

以下是我的输出,它与教程中的内容相去甚远,并且没有任何意义,房子将是 5 美元

Statistics for Boston housing dataset:

Minimum price: $5.00
Maximum price: $50.00
Mean price: $22.53
Median price: $21.20
Standard Deviation of price: $9.19

【问题讨论】:

    标签: python pandas scikit-learn


    【解决方案1】:

    你得到了正确的结果,它是数千美元。

    通过添加以下代码来查看波士顿数据集的详细信息,以读取数据集中属性的描述。价格为1000美元。所以 5 美元的最低价格实际上是 5000 美元。

    print (boston['DESCR'])
    
    

    结果: :属性信息(按顺序): - 按城镇划分的 CRIM 人均犯罪率 - 超过 25,000 平方英尺的住宅用地的 ZN 比例。 - 每个城镇的非零售商业用地的INDUS比例 - CHAS Charles River 虚拟变量(= 1 如果区域边界河流;否则为 0) - NOX 一氧化氮浓度(百万分之一) - RM 每户平均房间数 - 1940 年之前建造的自住单位的 AGE 比例 - 到波士顿五个就业中心的 DIS 加权距离 - 径向高速公路可达性的 RAD 指数 - 每 10,000 美元的全额财产税税率 - PTRATIO 师生比例(按城镇) - B 1000(Bk - 0.63)^2 其中 Bk 是城镇中黑人的比例 - LSTAT % 人口地位较低 - MEDV 自住房屋的中位数价值 1000 美元

    【讨论】:

    • 非常感谢...请给我发邮件,以便您继续帮助我完成...另外,如果我在显示之前将其乘以 1000 可以吗print(f"Minimum price: ${(minimum_price*1000):.2f}")
    • 这取决于您如何呈现最终结果。为了进行回归和预测,如果直方图显示数据有偏差,您可能需要缩放数据。
    • 这对我来说听起来很先进,但我会继续阅读...@Praks 我可以有你的邮件,这样我们就可以直接沟通我的是 femii.femiii@gmail.com
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    相关资源
    最近更新 更多