Hướng dẫn python data science tutorial - hướng dẫn khoa học dữ liệu trăn

GIỚI THIỆU

Hướng dẫn python data science tutorial - hướng dẫn khoa học dữ liệu trăn

Cám ơn bạn đã ghé thăm blog của Thịnh. Đây là góc chia sẻ kiến thức và kinh nghiệm của tôi về Digital Marketing, Data cũng như hành trình học hỏi của tôi trong 7+ năm qua.

CASE STUDY: Luxstay cá nhân hoá nội dung để tăng 60% tương tác

Hướng dẫn python data science tutorial - hướng dẫn khoa học dữ liệu trăn

#GROWTH MasterClass – MoEngage

Hướng dẫn python data science tutorial - hướng dẫn khoa học dữ liệu trăn

#career_talk with Trinh Thai

Hướng dẫn python data science tutorial - hướng dẫn khoa học dữ liệu trăn

Thịnh Vũ

#digital_marketing #growth #data_driven

Danh mục

  • APIs Collection (3)
  • Data Science (8)
  • Productivity (5)
  • Python Course (1)
  • Thoughts (3)
  • Tutorial (6)

Điều kiện tiên quyết

Phần hai của hướng dẫn này giả định rằng bạn đã hoàn thành phần một và các điều kiện tiên quyết của nó.

Khám phá và chuẩn bị dữ liệu

Prerequisites

  • Bài viết
  • 06/15/2022
  • 3 phút để đọc

Trong bài viết này

Applies to: SQL Server 2017 (14.x) and later Azure SQL Managed Instance SQL Server 2017 (14.x) and later Azure SQL Managed Instance

In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with SQL Server Machine Learning Services or on SQL Server 2019 Big Data Clusters.

In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with SQL Server Machine Learning Services.In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with Azure SQL Managed Instance Machine Learning Services.
In this article, you'll learn how to:Load the data from the database into a pandas data frame
Prepare the data in Python by removing some columnsIn part one, you learned how to restore the sample database.
In part three, you'll learn how to train a linear regression machine learning model in Python.In part four, you'll learn how to store the model in a database, and then create stored procedures from the Python scripts you developed in parts two and three. The stored procedures will run on the server to make predictions based on new data.rxLinMod from the revoscalepy library.
PrerequisitesPart two of this tutorial assumes you have completed part one and its prerequisites.

In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with SQL Server Machine Learning Services.In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with Azure SQL Managed Instance Machine Learning Services.
In this article, you'll learn how to:Load the data from the database into a pandas data frame
Prepare the data in Python by removing some columnsIn part one, you learned how to restore the sample database.

In part three, you'll learn how to train a linear regression machine learning model in Python.

In part four, you'll learn how to store the model in a database, and then create stored procedures from the Python scripts you developed in parts two and three. The stored procedures will run on the server to make predictions based on new data.

QuickstartDescription
Run simple Python scripts Learn the basics of how to call Python in T-SQL using sp_execute_external_script.
Data structures and objects using Python Shows how SQL uses the Python pandas package to handle data structures.
Create and score a predictive model in Python Explains how to create, train, and use a Python model to make predictions from new data.

Next steps

  • Python extension in SQL Server

Phản hồi

Gửi và xem ý kiến phản hồi dành cho

Chuyển đến nội dung chính

Trình duyệt này không còn được hỗ trợ nữa.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Python Tutorial: Prepare data to train a linear regression model with SQL machine learning

  • Bài viết
  • 06/15/2022
  • 3 phút để đọc

Trong bài viết này

Applies to: SQL Server 2017 (14.x) and later Azure SQL Managed Instance SQL Server 2017 (14.x) and later Azure SQL Managed Instance

In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with SQL Server Machine Learning Services or on SQL Server 2019 Big Data Clusters.

In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with SQL Server Machine Learning Services.

In part two of this four-part tutorial series, you'll prepare data from a database using Python. Later in this series, you'll use this data to train and deploy a linear regression model in Python with Azure SQL Managed Instance Machine Learning Services.

In this article, you'll learn how to:

  • Load the data from the database into a pandas data framepandas data frame
  • Prepare the data in Python by removing some columns

In part one, you learned how to restore the sample database.

In part three, you'll learn how to train a linear regression machine learning model in Python.

In part four, you'll learn how to store the model in a database, and then create stored procedures from the Python scripts you developed in parts two and three. The stored procedures will run on the server to make predictions based on new data.

Điều kiện tiên quyết

  • Phần hai của hướng dẫn này giả định rằng bạn đã hoàn thành phần một và các điều kiện tiên quyết của nó.

Khám phá và chuẩn bị dữ liệu

Để sử dụng dữ liệu trong Python, bạn sẽ tải dữ liệu từ cơ sở dữ liệu vào khung dữ liệu Pandas.

Tạo một máy tính xách tay Python mới trong Azure Data Studio và chạy tập lệnh bên dưới.

Tập lệnh Python bên dưới nhập dữ liệu từ bảng dbo.rental_data trong cơ sở dữ liệu của bạn vào khung dữ liệu Pandas DF.df.

Trong chuỗi kết nối, thay thế chi tiết kết nối khi cần thiết. Để sử dụng xác thực Windows với chuỗi kết nối ODBC, chỉ định Trusted_Connection=Yes; thay vì tham số UIDPWD.

import pyodbc
import pandas
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Connection string to your SQL Server instance
conn_str = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server}; SERVER=; DATABASE=TutorialDB;UID=;PWD=')

query_str = 'SELECT Year, Month, Day, Rentalcount, Weekday, Holiday, Snow FROM dbo.rental_data'

df = pandas.read_sql(sql=query_str, con=conn_str)
print("Data frame:", df)

Bạn sẽ thấy kết quả tương tự như sau.

Data frame:      Year  Month  Day  Rentalcount  WeekDay  Holiday  Snow
0    2014      1   20          445        2        1     0
1    2014      2   13           40        5        0     0
2    2013      3   10          456        1        0     0
3    2014      3   31           38        2        0     0
4    2014      4   24           23        5        0     0
..    ...    ...  ...          ...      ...      ...   ...
448  2013      2   19           57        3        0     1
449  2015      3   18           26        4        0     0
450  2015      3   24           29        3        0     1
451  2014      3   26           50        4        0     1
452  2015     12    6          377        1        0     1

[453 rows x 7 columns]

Lọc các cột từ DataFrame để loại bỏ các cột mà chúng tôi không muốn sử dụng trong khóa đào tạo. Rentalcount không nên được bao gồm vì nó là mục tiêu của các dự đoán.

columns = df.columns.tolist()
columns = [c for c in columns if c not in ["Year", "Rentalcount"]]

print("Training set:", test[columns])

Lưu ý dữ liệu tập huấn luyện sẽ có quyền truy cập:

Training set:      Month  Day  Weekday  Holiday  Snow
1        2   13        5        0     0
3        3   31        2        0     0
7        3    8        7        0     0
15       3    4        2        0     1
22       1   18        1        0     0
..     ...  ...      ...      ...   ...
416      4   13        1        0     1
421      1   21        3        0     1
438      2   19        4        0     1
441      2    3        3        0     1
447      1    4        6        0     1

[91 rows x 5 columns]

Bước tiếp theo

Trong phần hai của loạt hướng dẫn này, bạn đã hoàn thành các bước sau:

  • Tải dữ liệu từ cơ sở dữ liệu vào khung dữ liệu gấu trúcpandas data frame
  • Chuẩn bị dữ liệu trong Python bằng cách xóa một số cột

Để đào tạo mô hình học máy sử dụng dữ liệu từ cơ sở dữ liệu TutorialDB, hãy làm theo Phần ba của chuỗi hướng dẫn này:

Phản HồI

Gửi và xem ý kiến ​​ph