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