import numpy as np import matplotlib.pyplot as plt
deflogistic(r, x): return r * x * (1 - x)
x = np.linspace(0, 1) fig, ax = plt.subplots(1, 1, figsize=(6, 10), dpi=80) for r in np.linspace(0.5, 4.0, 400): X = np.empty(1000) X[0] = 0.1 for i inrange(999): X[i+1] = logistic(r, X[i]) ax.plot([r]*1000, X, ',k', alpha=0.2)
import numpy as np import matplotlib.pyplot as plt
numpyは数値計算をサポートするPythonライブラリで、配列操作や数値計算を高速に行います。
matplotlib.pyplotはグラフ描画ライブラリです。
ロジスティック写像の関数
1 2
deflogistic(r, x): return r * x * (1 - x)
logistic関数はロジスティック写像の式を表しています。
分岐図の作成
1 2 3 4 5 6 7 8
x = np.linspace(0, 1) fig, ax = plt.subplots(1, 1, figsize=(6, 10), dpi=80) for r in np.linspace(0.5, 4.0, 400): X = np.empty(1000) X[0] = 0.1 for i inrange(999): X[i+1] = logistic(r, X[i]) ax.plot([r]*1000, X, ',k', alpha=0.2)
plt.figure(figsize=(8, 4)) for i inrange(2): plt.subplot(1, 2, i+1) plt.bar(range(len(colors[i])), colors[i], color=['r', 'g', 'b'], alpha=0.6) plt.xticks(range(len(colors[i])), ['R', 'G', 'B']) plt.title(labels[i])
plt.tight_layout() plt.show()
print(f"The given color is: {given_color}") print(f"The complementary color is: {complementary_color}") print(f"The distance between these colors is: {distance_value}")
print(f"The given color is: {given_color}") print(f"The complementary color is: {complementary_color}") print(f"The distance between these colors is: {distance_value}")
The given color is: [0.4, 0.2, 0.9]
The complementary color is: [0.6, 0.8, 0.09999999999999998]
The distance between these colors is: 1.019803902718557
from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score import matplotlib.pyplot as plt import seaborn as sns
次に、心臓疾患のデータセットをロードします。
scikit-learnのdatasetsモジュールには、心臓疾患のデータセットが含まれています。
1 2 3
heart = datasets.load_breast_cancer() X = heart.data y = heart.target
次に、データセットを訓練データとテストデータに分割します。
1
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
defpredator_prey_equations(xy, t, alpha, beta, delta, gamma): x, y = xy dxdt = alpha * x - beta * x * y dydt = delta * x * y - gamma * y return [dxdt, dydt]
plt.hist(degrees, bins='auto', alpha=0.7, color='skyblue', edgecolor='black') plt.xlabel('Degree') plt.ylabel('Frequency') plt.title('Degree Distribution of a Watts-Strogatz Graph') plt.show()