from sklearn.linear_model import LogisticRegression import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from pyts.datasets import load_gunpoint from pyts.transformation import ShapeletTransform from datetime import time # Toy dataset data=pd.read_csv('dataset11.csv') pf=data.head(10) y=data[['Q0']] X=data[['TS']] X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=10) print(X_train) # as columns. dataframe = pd.DataFrame( pf,columns=['TS', 'Q0']) # Changing the datatype of Date, from # Object to datetime64 #dataframe["Sample2"] = Sample2.time.strptime("%T") # Setting the Date as index dataframe = dataframe.set_index("TS") dataframe # setting figure size to 12, 10 plt.figure(figsize=(12, 6)) # Labelling the axes and setting # a title plt.xlabel("Time") plt.ylabel("Values") plt.title("Vibration") # plotting the "A" column alone plt.plot(dataframe["Q0"]) plt.legend(loc='best', fontsize=8) plt.show() st = ShapeletTransform(window_sizes='auto', sort=True) X_new = st.fit_transform(X_train, y_train) print(X_new) # Visualize the four most discriminative shapelets plt.figure(figsize=(6, 4)) for i, index in enumerate(st.indices_[:4]): idx, start, end = index plt.plot(X_train[idx], color='C{}'.format(i), label='Sample {}'.format(idx)) plt.plot(np.arange(start, end), X_train[idx, start:end], lw=5, color='C{}'.format(i)) plt.xlabel('Time', fontsize=12) plt.title('The four most discriminative shapelets', fontsize=14) plt.legend(loc='best', fontsize=8) plt.show()