def train_script_2(): dbreader = DbReader(PATH, split_size=ONE_PERSON_SPLIT) training_commands = getting_commands_from_signals( dbreader.training_signals[:2], dbreader.training_text[:2]) valid_commands = getting_commands_from_signals( dbreader.training_signals[2:], dbreader.training_text[2:]) training_mfcc_data = simple_mfcc(training_commands) valid_mfcc_data = simple_mfcc(valid_commands) y_train = training_mfcc_data['command'] X_train = training_mfcc_data.drop(columns=['command']) y_valid = valid_mfcc_data['command'] X_valid = valid_mfcc_data.drop(columns=['command']) rf_model = RandomForestModel() model_to_fit = rf_model.gridsearchCV() model_to_fit.fit(X_train, y_train) rf_model.set_internal_model(model_to_fit.best_estimator_) print(model_to_fit.best_estimator_) rf_model.save_model() joblib.dump(dbreader, "dbreader.mdl") predictions = rf_model.predict(X_valid) plot_confusion_matrix(y_valid, predictions)
from Model import RandomForestModel ## Test 1 model = RandomForestModel(X_train=[[1, 2, 3], [11, 12, 13]], y_train = [0, 1], X_test=[[3, 4, 1],[14, 11, 17]], n_estimators=1) model.fit() out = list(model.predict()) desired_out = [0, 1] print("Desired out:" + "\t" + str(desired_out)) print("Actual out:" + "\t" + str(out)) for index in range(0, len(out)): if out[index]!=desired_out[index]: print("Test 1 failed") exit(0) print("Test 1 passed")