Prediction
This is part 2 of my data parsing and prediction example and assumes you successfully gathered data and saved it locally, as explained in Part 1. Once we have all the data from our solve.out files (Nodes, Elements, DOF and time), we can use that data set and some python AI/ML (Artificial Intelligence/Machine Learning) tools to create a method to predict the time based on our own inputs. This means once we have a tool built to do the prediction, we can use our analysis preliminary data to predict the time to solve. First we need to get a few packages for our python virtual environment installation.Step 0: Python venv activation
If you are restarting, you can just activate the virtual environment (bob) you created in Part 1.Step 1: Importing the data, cleaning and sorting
We will again use pandas to import the json data file we created in part 1. Note there is data in the file that did not appear to be needed in this iteration of the predictor tool, so we delete a few columns that are not needed. Memory and version were not used in this analysis.Step 2: Setup the data for using scikit-learn
The scikit ML tools are set up to take a set of data and divide it into two categories, testing and training data. The training data should be the majority, commonly 70% is used. The testing data is then used to test the accuracy of the predictions from the training data. For more information about scikit-learn and what it does, and you will need more information to understand it: scikit-learn. The standard procedure is to break out the data you are hoping to predict to a y parameter and remove it from the data set. Then train_test_split is used to build the predictive model (but not launch it).
Step 3: Baseline Regression model fitting (Prediction)
The prediction model has hyperparameters that allow the users to tune the fitting to the data. The extensive list of scikit hyperparameters can be found at: hyperparameters. Here I use some baseline values as suggested in another online training. Later we can refine them. ensemble.GradientBoostingRegressor is the command that will run the data fitting.Step 4: Refine the Regression model fitting (parameter optimization)
However, being short of time, I decided to use the GridSearchCV capabilities of the prediction tool to allow a best fit to be determine from ranges of the hyperparameters. Computers are there to do these tasks for us. To set up some ranges I just used 1/2 and 2 times the original values. Note, this will take time depending on how much data you have. Check the documentation for the ranges of the hyperparameters. Using more CPUs will speed up the process. The parameter search is run only on the training data. Here a timer is inserted to see how long it takes. Note: once you launch this you might want to go get a coffee. It takes a bit of time.Step 5: Important! as in, what is?
Not all inputs or features have the same importance. We can use scikit to determine the importance of the different features. The higher the value, the more relevant that value is to the prediction, here, time. We could actually remove low value features with very little loss of prediction accuracy.Step 6: Predict using your best values
Let’s use the best values from our grid search, that we saved, by reimporting the pkl.
