0
0

まえがき

データ分析において、数学的な基礎を理解することは非常に重要です。この記事では、微分と積分、線形代数の基本概念とその実生活や実務での応用について学びます。

微分と積分

定義と実生活への応用

  • 微分:変化の速度を測る手法。例えば、車の速度は距離の微分です。
  • 積分:累積量を求める手法。例えば、車の走行距離は速度の積分です。

具体例
例えば、車が走行しているときの速度(m/s)が次のようなデータがあったとします。

時間 (s) 速度 (m/s)
0 0
1 2
2 4
3 6
4 8
5 10

このデータを用いて速度の変化(微分)と累積走行距離(積分)を計算します。

コード例

import numpy as np
import matplotlib.pyplot as plt

# サンプルデータの作成
time = np.array([0, 1, 2, 3, 4, 5])
speed = np.array([0, 2, 4, 6, 8, 10])

# 微分
acceleration = np.gradient(speed, time)

# 積分
distance = np.cumsum(speed) * (time[1] - time[0])

# プロット
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(time, speed, label='Speed (m/s)')
plt.plot(time, acceleration, label='Acceleration (m/s^2)')
plt.xlabel('Time (s)')
plt.ylabel('Speed and Acceleration')
plt.legend()

plt.subplot(1, 2, 2)
plt.plot(time, distance, label='Distance (m)')
plt.xlabel('Time (s)')
plt.ylabel('Distance')
plt.legend()

plt.show()

アウトプット
スクリーンショット 2024-08-07 10.13.12.png

線形代数

ベクトルと行列

  • ベクトル:方向と大きさを持つ量。例:力のベクトル。
  • 行列:ベクトルの集合で、複数のデータを一度に操作可能。

実務での応用例

例えば、2つのベクトル間の内積を計算する例を示します。

コード例

import numpy as np

# ベクトルの作成
v1 = np.array([1, 2])
v2 = np.array([3, 4])

# 内積
dot_product = np.dot(v1, v2)
print(f"Dot Product: {dot_product}")

# 行列の作成
matrix = np.array([[1, 2], [3, 4]])

# 行列の逆行列
inverse_matrix = np.linalg.inv(matrix)
print(f"Inverse Matrix:\n{inverse_matrix}")

アウトプット

Dot Product: 11
Inverse Matrix:
[[-2.   1. ]
 [ 1.5 -0.5]]

あとがき

微分と積分、線形代数の基本を理解することで、データ分析の基礎を固めることができます。これらの数学的手法は、実務でも広く応用されており、データの理解と解析に欠かせません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0