pandas Library
import pandas as pd
df = pd.read_excel(file_address)
print(df)
numpy
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr.mean())
matploilib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
seaborn
import seaborn as sns
import pandas as pd
data_sample = pd.DataFrame({'x':[1, 2, 3, 4], 'y':[1, 4, 9, 16]})
sns.barplot(data=data_sample, x='x', y='y')
scikit-learn
from sklearn.datasets import load_iris
from sklearn.linear_model import LinearRegression
# Iris 데이터셋 불러오기
iris = load_iris()
# Iris 데이터셋에서 특정 범위의 데이터 슬라이싱하기
X_train = iris.data[:,:-1] # 데이터 값들 추출
print("학습 데이터:", X_train)
y_train = iris.data[:,-1:] # 정답값 추출
print("학습 데이터:", y_train)
model = LinearRegression()
model.fit(X_train, y_train)
statsmodels
import statsmodels.api as sm
model = sm.OLS(y_train, X_train)
result = model.fit()
print(result.summary())
scipy
import numpy as np
from scipy.integrate import quad
# 적분할 함수 정의
def integrand(x):
return np.exp(-x ** 2)
# 정적분 구간
a = 0
b = np.inf
# 적분 계산
result, error = quad(integrand, a, b)
print("결과:", result)
print("오차:", error)
tensorflow
import tensorflow as tf
input_size = 3
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='relu', input_shape=(input_size,)),
tf.keras.layers.Dense(1)
])
model.compile(optimizer='adam', loss='mse')
pytorch
import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.fc1 = nn.Linear(input_size, hidden_size)
self.fc2 = nn.Linear(hidden_size, output_size)
def forward(self, x):
x = torch.relu(self.fc1(x))
x = self.fc2(x)
return x
'Python' 카테고리의 다른 글
[Python 101] Class, Decoration (0) | 2024.07.04 |
---|---|
[Python 101] List Comprehension, Lambda, glob, os (0) | 2024.07.04 |
[Python 101] 여러 확장자로 Data Frame 저장하기 (0) | 2024.07.04 |
[Python 101] 변수들과 데이터 관련 함수 (0) | 2024.07.04 |
[Python 과제 LV. 3] 단어 맞추기 게임 (0) | 2024.06.11 |