# Using Seaborn to create a scatter plot tips = sns.load_dataset('tips') sns.scatterplot(x='total_bill', y='tip', data=tips) plt.title('Scatter Plot using Seaborn') plt.show()
from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score from sklearn.preprocessing import StandardScaler
# Load iris dataset as an example iris = load_iris() X = iris.data y = iris.target
# Split the data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Standardize the features using StandardScaler scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test)
# Create and train a Logistic Regression model model = LogisticRegression(max_iter=1000) model.fit(X_train_scaled, y_train)
# Make predictions on the test set predictions = model.predict(X_test_scaled)
import lightgbm as lgb from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score
# Loading Iris dataset and splitting it iris = load_iris() X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2)
# Training a LightGBM classifier model = lgb.LGBMClassifier() model.fit(X_train, y_train)
# Making predictions and calculating accuracy predictions = model.predict(X_test) accuracy = accuracy_score(y_test, predictions)
print(f'Accuracy: {accuracy}')
19、Keras
Keras 是 Python 中的高級(jí)神經(jīng)網(wǎng)絡(luò) API,通過用戶友好的界面促進(jìn)深度學(xué)習(xí)模型的開發(fā)和實(shí)驗(yàn)。
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense
# Creating a simple Keras model model = Sequential() model.add(Dense(units=64, activation='relu', input_dim=10)) model.add(Dense(units=1, activation='sigmoid'))
# Displaying the model summary model.summary()
20、Arrow
Arrow 是一個(gè)用于處理日期、時(shí)間和時(shí)間戳的 Python 庫(kù),提供更直觀且人性化的 API 來(lái)處理時(shí)態(tài)數(shù)據(jù)。
import arrow
# Getting the current time in a specific timezone local_time = arrow.now() utc_time = arrow.utcnow()