Machine Learning for Time Series Data in Python

本文介绍了如何在Python中利用时间序列数据进行机器学习。首先,通过重塑、日期转换和特征工程,处理时间序列数据。然后,计算音频数据的导数特征,如tempogram,以提取节奏和节拍信息。接着,利用谱特征增强数据,包括计算谱带宽和谱中心。最后,将多种特征结合,训练分类器以提高区分不同类型音频的能力。
摘要由CSDN通过智能技术生成

Time Series and Machine Learning Primer


# Plot the time series in each dataset
fig, axs = plt.subplots(2, 1, figsize=(5, 10))
data.iloc[:1000].plot(x="time", y="data_values", ax=axs[0])
data2.iloc[:1000].plot(x="time", y="data_values", ax=axs[1])
plt.show()

 


from sklearn.svm import LinearSVC
data.head()
# Construct data for the model
X = data[['petal length (cm)', 'petal width (cm)']]
y = data[['target']]

# Fit the model
model = LinearSVC()
model.fit(X, y)

注意(cm)前面的空格


from sklearn import linear_model

# Prepare input and output DataFrames
X = boston["AGE"].reshape(-1,1)
y = boston["RM"].reshape(-1,1)

# Fit the model
model = linear_model.LinearRegression()
model.fit(X,y)

reshape(-1,1)


import librosa as lr
from glob import glob

# List all the wav files in the folder
audio_files = glob(data_dir + '/*.wav')
# audio_files

# Read in the first audio file, create the time array
audio, sfreq = lr.load(audio_files[0])
time = np.arange(0, len(audio)) / sfreq

# Plot audio over time
fig, ax = plt.subplots()
ax.plot(time, audio)
ax.set(xlabel='Time (s)', ylabel='Sound Amplitude')
plt.show()

 


# Read in the data
data = pd.read_csv('prices.csv', index_col=0)

# Convert the index of the DataFrame to datetime
data.index = pd.to_datetime(data.index)
print(data.head())

# Loop through each column, plot its values over time
fig, ax = plt.subplots()
for column in data:
    data[column].plot(ax=ax, label=column)
ax.legend()
plt.show()

pd.to_datatime



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值