Sổ tay khoa học dữ liệu Python

Mar 31 2023
.
  1. IPython: Ngoài Python bình thường
  2. Giới thiệu về NumPy
  3. Thao tác dữ liệu với Pandas
  4. Trực quan hóa với Matplotlib
  1. Bắt đầu với Học máy
  2. Học từ dữ liệu
  3. hồi quy tuyến tính
  4. Naive Bayes
  5. k-Hàng xóm gần nhất
  6. Giới thiệu về Machine Learning với Scikit-Learn
  7. Học máy trong thực tế
  8. Đánh đổi sai lệch-phương sai
  9. Ước tính mật độ hạt nhân
  10. Phân tích thành phần chính
  11. học đa dạng
  12. phân cụm
  13. Cây quyết định và rừng ngẫu nhiên
  14. Tối ưu hóa dựa trên Gradient
  15. Phân cụm K-Means
  16. Chuyên sâu: Phân loại Naive Bayes
  17. Chuyên sâu: Hồi quy tuyến tính
  18. Chuyên sâu: Máy Vector hỗ trợ
  19. Chuyên sâu: Cây quyết định và rừng ngẫu nhiên
  20. Chuyên sâu: Phân tích thành phần chính
  21. Chuyên sâu: Học đa dạng
  22. Chuyên sâu: Phân cụm k-Means
  1. Chuyến đi vòng xoáy của Python
  2. Cơ bản về ngôn ngữ Python
  3. IPython: Ngoài Python bình thường
  4. NumPy
  5. Thông tin thêm về IPython System Shell
  6. Matplotlib
  7. khoa học viễn tưởng
  8. Scikit-Tìm hiểu
  9. Học máy với Scikit-Learn
  10. Tài nguyên học máy khác
  11. Học máy thực tế: Một ví dụ đơn giản
  12. Thư mục

import numpy as np

# create a 1D array
a = np.array([0, 1, 2, 3, 4])
print(a)

import pandas as pd

# create a Pandas DataFrame
data = {'name': ['Alice', 'Bob', 'Charlie', 'David'],
        'age': [25, 32, 18, 47],
        'gender': ['F', 'M', 'M', 'M']}
df = pd.DataFrame(data)
print(df)

# filter rows based on a condition
df_filtered = df[df['age'] > 30]
print(df_filtered)

# group data by a column and compute statistics
grouped_data = df.groupby('gender')['age'].mean()
print(grouped_data)

import matplotlib.pyplot as plt
import numpy as np

# create some data to plot
x = np.linspace(0, 10, 100)
y = np.sin(x)

# create a line plot
plt.plot(x, y)
plt.title('Sine Wave')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

# create a scatter plot
x = np.random.randn(100)
y = np.random.randn(100)
plt.scatter(x, y)
plt.title('Random Data')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# load the iris dataset
iris = load_iris()

# split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(iris['data'], iris['target'], random_state=0)

# create a K-Nearest Neighbors classifier
knn = KNeighborsClassifier(n_neighbors=1)

# fit the classifier to the training data
knn.fit(X_train, y_train)

# predict the classes of the test data
y_pred = knn.predict(X_test)

# compute the accuracy of the classifier
accuracy = knn.score(X_test, y_test)
print('Accuracy:', accuracy)