2023美赛C题编程部分
本文最后更新于 315 天前,其中的信息可能已经有所发展或是发生改变。

SIR模型:

import scipy.integrate
import numpy as np
import matplotlib.pyplot as plt


# model
def SIR_model(y, t, beta, gamma):
    S, I, R = y
    dS_dt = -beta * S * I
    dI_dt = beta * S * I - gamma * I
    dR_dt = gamma * I
    return ([dS_dt, dI_dt, dR_dt])


# initialization

S0 = 0.9 # ratio
I0 = 0.1 # ratio
R0 = 0.0 # ratio
beta = 0.35
gamma = 0.1

# time vector
t = np.linspace(0, 100, 10000)
# result
res = scipy.integrate.odeint(SIR_model, [S0, I0, R0], t, args=(beta, gamma))
res = np.array(res)
# plot
plt.figure(figsize=[6, 4])
plt.plot(t, res[:, 0], label='S(t)')
plt.plot(t, res[:, 1], label='I(t)')
plt.plot(t, res[:, 2], label='R(t)')
plt.legend()
plt.grid()
plt.xlabel('time')
plt.ylabel('proportions')
plt.title('SIR model simulation')
plt.show()

pytorch autograde

class SelfDeletingTempFile():
    def __init__(self):
        self.name = os.path.join(tmp_dir, str(uuid.uuid4()))

    def __del__(self):
        os.remove(self.name)

def pack_hook(tensor):
    temp_file = SelfDeletingTempFile()
    torch.save(tensor, temp_file.name)
    return temp_file

def unpack_hook(temp_file):
    return torch.load(temp_file.name)

K-Means

#Import Library
from sklearn.cluster import KMeans
 
#Assumed you have, X (attributes) for training data set and x_test(attributes) of test_dataset
# Create KNeighbors classifier object model 
model = KMeans(n_clusters=3, random_state=0)
 
# Train the model using the training sets and check score
model.fit(X)
 
#Predict Output
predicted= model.predict(x_test)

相关性分析:高亮高度相关的变量,Spearman,Pearson和Kendall矩阵

import pandas as pd

from dataprep.eda import create_report

df = pd.read_csv("parking_violations.csv")

create_report(df)

灵敏性分析的启发:

模型抽象成一个函数,输入数据,输出结果。可传入一个可选参数,表示扰动,此时输出的结果即为原始结果与扰动结果的比较,也即灵敏性分析:

def my_model(input, noise=0):
    pass

绘图相关:

https://www.heywhale.com/mw/project/5f4b3f146476cf0036f7e51e

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇