You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.3 KiB
128 lines
4.3 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Giá Bí Ngô\n",
|
|
"\n",
|
|
"Tải các thư viện và tập dữ liệu cần thiết. Chuyển đổi dữ liệu thành một dataframe chứa một phần dữ liệu:\n",
|
|
"\n",
|
|
"- Chỉ lấy những quả bí ngô được định giá theo giạ\n",
|
|
"- Chuyển đổi ngày thành tháng\n",
|
|
"- Tính giá trung bình giữa giá cao và giá thấp\n",
|
|
"- Chuyển đổi giá để phản ánh mức giá theo số lượng giạ\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import numpy as np\n",
|
|
"from datetime import datetime\n",
|
|
"\n",
|
|
"pumpkins = pd.read_csv('../data/US-pumpkins.csv')\n",
|
|
"\n",
|
|
"pumpkins.head()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"pumpkins = pumpkins[pumpkins['Package'].str.contains('bushel', case=True, regex=True)]\n",
|
|
"\n",
|
|
"columns_to_select = ['Package', 'Variety', 'City Name', 'Low Price', 'High Price', 'Date']\n",
|
|
"pumpkins = pumpkins.loc[:, columns_to_select]\n",
|
|
"\n",
|
|
"price = (pumpkins['Low Price'] + pumpkins['High Price']) / 2\n",
|
|
"\n",
|
|
"month = pd.DatetimeIndex(pumpkins['Date']).month\n",
|
|
"day_of_year = pd.to_datetime(pumpkins['Date']).apply(lambda dt: (dt-datetime(dt.year,1,1)).days)\n",
|
|
"\n",
|
|
"new_pumpkins = pd.DataFrame(\n",
|
|
" {'Month': month, \n",
|
|
" 'DayOfYear' : day_of_year, \n",
|
|
" 'Variety': pumpkins['Variety'], \n",
|
|
" 'City': pumpkins['City Name'], \n",
|
|
" 'Package': pumpkins['Package'], \n",
|
|
" 'Low Price': pumpkins['Low Price'],\n",
|
|
" 'High Price': pumpkins['High Price'], \n",
|
|
" 'Price': price})\n",
|
|
"\n",
|
|
"new_pumpkins.loc[new_pumpkins['Package'].str.contains('1 1/9'), 'Price'] = price/1.1\n",
|
|
"new_pumpkins.loc[new_pumpkins['Package'].str.contains('1/2'), 'Price'] = price*2\n",
|
|
"\n",
|
|
"new_pumpkins.head()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Một biểu đồ phân tán cơ bản nhắc nhở chúng ta rằng chúng ta chỉ có dữ liệu tháng từ tháng Tám đến tháng Mười Hai. Chúng ta có lẽ cần thêm dữ liệu để có thể đưa ra kết luận theo cách tuyến tính.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt\n",
|
|
"plt.scatter('Month','Price',data=new_pumpkins)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"plt.scatter('DayOfYear','Price',data=new_pumpkins)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"\n---\n\n**Tuyên bố miễn trừ trách nhiệm**: \nTài liệu này đã được dịch bằng dịch vụ dịch thuật AI [Co-op Translator](https://github.com/Azure/co-op-translator). Mặc dù chúng tôi cố gắng đảm bảo độ chính xác, xin lưu ý rằng các bản dịch tự động có thể chứa lỗi hoặc sự không chính xác. Tài liệu gốc bằng ngôn ngữ bản địa nên được coi là nguồn tham khảo chính thức. Đối với các thông tin quan trọng, nên sử dụng dịch vụ dịch thuật chuyên nghiệp từ con người. Chúng tôi không chịu trách nhiệm cho bất kỳ sự hiểu lầm hoặc diễn giải sai nào phát sinh từ việc sử dụng bản dịch này.\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.3-final"
|
|
},
|
|
"orig_nbformat": 2,
|
|
"coopTranslator": {
|
|
"original_hash": "b032d371c75279373507f003439a577e",
|
|
"translation_date": "2025-09-06T13:09:20+00:00",
|
|
"source_file": "2-Regression/3-Linear/notebook.ipynb",
|
|
"language_code": "vi"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
} |