def StartTrain(self): train_files = glob.glob(self.lineEdit.text() + "\\*.csv") test_files = glob.glob(self.lineEdit_2.text() + "\\*.csv") train_li = [] for filename in train_files: df = pd.read_csv(filename, index_col=None, header=None,usecols=[2]) train_li.append(df) X_df = pd.concat(train_li, axis=1, ignore_index=True) X_df = X_df.T test_li = [] for filename in test_files: df = pd.read_csv(filename, index_col=None, header=None,usecols=[2]) test_li.append(df) X_df_ng = pd.concat(test_li, axis=1, ignore_index=True) X_df_ng = X_df_ng.T X_df = X_df.append(X_df_ng) X_df_tab = from_2d_array_to_nested(X_df) Y_df_ok = np.zeros(len(test_li), dtype="int32") Y_df_ng = np.ones(len(train_li), dtype="int32") Y_df = np.concatenate([Y_df_ok, Y_df_ng], 0) X_train, X_test, y_train, y_test = train_test_split(X_df_tab, Y_df, test_size= (100 - self.horizontalSlider.value()) / 100) self.tableWidget.setRowCount(0) selectedModel = self.comboBox.currentText() if(selectedModel == "RandomForestClassifier"): classifier = make_pipeline(Tabularizer(), RandomForestClassifier()) classifier.fit(X_train, y_train) self.lineEdit_5.setText(str(classifier.score(X_train, y_train))) self.lineEdit_6.setText(str(classifier.score(X_test, y_test))) for i in range(len(X_test)): row = self.tableWidget.rowCount() self.tableWidget.setRowCount(row) classifier_preds = classifier.predict(X_test.iloc[i].to_frame()) self.addTableRow(self.tableWidget, [str(i),str(y_test[i]), str(classifier_preds)]) elif(selectedModel == "RocketClassifier"): rocket = RocketClassifier() rocket.fit(X_train, y_train) self.lineEdit_5.setText(str(rocket.score(X_train, y_train))) self.lineEdit_6.setText(str(rocket.score(X_test, y_test))) for i in range(len(X_test)): row = self.tableWidget.rowCount() self.tableWidget.setRowCount(row) rocket_preds = rocket.predict(X_test.iloc[i].to_frame()) self.addTableRow(self.tableWidget, [str(i),str(y_test[i]), str(rocket_preds)]) elif(selectedModel == "TimeSeriesForestClassifier"): tsf = TimeSeriesForestClassifier(n_estimators=50, random_state=47) tsf.fit(X_train, y_train) self.lineEdit_5.setText(str(tsf.score(X_train, y_train))) self.lineEdit_6.setText(str(tsf.score(X_test, y_test))) for i in range(len(X_test)): row = self.tableWidget.rowCount() self.tableWidget.setRowCount(row) tsf_preds = tsf.predict(X_test.iloc[i].to_frame()) self.addTableRow(self.tableWidget, [str(i),str(y_test[i]), str(tsf_preds)]) elif(selectedModel == "RandomIntervalSpectralEnsemble"): rise = RandomIntervalSpectralEnsemble(n_estimators=50, random_state=47) rise.fit(X_train, y_train) self.lineEdit_5.setText(str(rise.score(X_train, y_train))) self.lineEdit_6.setText(str(rise.score(X_test, y_test))) for i in range(len(X_test)): row = self.tableWidget.rowCount() self.tableWidget.setRowCount(row) rise_preds = rise.predict(X_test.iloc[i].to_frame()) self.addTableRow(self.tableWidget, [str(i),str(y_test[i]), str(rise_preds)]) elif(selectedModel == "SupervisedTimeSeriesForest"): stsf = SupervisedTimeSeriesForest(n_estimators=50, random_state=47) stsf.fit(X_train, y_train) self.lineEdit_5.setText(str(stsf.score(X_train, y_train))) self.lineEdit_6.setText(str(stsf.score(X_test, y_test))) for i in range(len(X_test)): row = self.tableWidget.rowCount() self.tableWidget.setRowCount(row) stsf_preds = rise.predict(X_test.iloc[i].to_frame()) self.addTableRow(self.tableWidget, [str(i),str(y_test[i]), str(stsf_preds)]) else: print("None")
# time series forest classifier from sktime.classification.interval_based import TimeSeriesForestClassifier TimeSeriesForestClassifier(n_estimators=200, min_interval=3, n_jobs=1, random_state=None|0) # cannot handle multivariate series .fit(X, y, **kwargs) .predict(X, **kwargs) .predict_proba(X, **kwargs) # example: time_series = [1,2,3,4,5,6,7,8,9] x_train = [ [1,2,3], [2,3,4], [3,4,5], [4,5,6] ] y_train = [ 1, 1, 0, 0, ] model = TimeSeriesForestClassifier(n_estimators=5, min_interval=2) model.fit(np.array(x_train), np.array(y_train)) y_pred = model.predict(np.array(x_train)) print(y_pred) # [1,1,0,0] # examine input output structure: from sktime.datasets import load_unit_test X_train, y_train = load_unit_test(split='train', return_X_y=True) X_test, y_test = load_unit_test(split='test', return_X_y=True) x = [ [list(j) for j in i] for i in X_train.to_numpy()] y = list(y_train) # multivariate workaround (chain 3rd dim into flat 2nd) time_series = [ [1,9], [2,8], [3,7], [4,6], [5,5], [6,4], [7,3], [8,2], [9,1] ] x_train_2d = [ [1,9,2,8,3,7], [2,8,3,7,4,6], [3,7,4,6,5,5], [4,6,5,5,6,4] ] # instead of: x_train_3d = [ [[1,9],[2,8],[3,7]], [[2,8],[3,7],[4,6]], [[3,7],[4,6],[5,5]], ... ] #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@