this method of using polyfit to find model for data works when the relationship can be described by an equation of the form baseax+ if used on data that cannot be described this wayit will yield erroneous results to see thislet' try replacing the body of the function byreturn *( **( * ) it now printsf( predicted ( when theory is missing in this we have emphasized the interplay between theoreticalexperimentaland computational science sometimeshoweverwe find ourselves with lots of interesting databut little or no theory in such caseswe often resort to using computational techniques to develop theory by building model that seems to fit the data in an ideal worldwe would run controlled experiment ( hang weights from spring)study the resultsand retrospectively formulate model consistent with those results we would then run different prospective experiment ( hang different weights from the same springand compare the results of that experiment to what the model predicted unfortunatelyin many cases it is impossible to run even one controlled experiment imaginefor examplebuilding model designed to shed light on how interest rates affect stock prices very few of us are in position to set interest rates and see what happens on the other hand there is no shortage of relevant historical data in such situationsone can simulate set of experiments by dividing the existing data into training set and holdout set without looking at the holdout setwe build model that seems to explain the training set for examplewe find curve that has reasonable for the training set we then test that model on the holdout set most of the time the model will fit the training set more closely than it fits the holdout set but if the model is good oneit should fit the holdout set reasonably well if it doesn'tthe model should probably be discarded how does one choose the training setwe want it to be representative of the data set as whole one way to do this is to randomly choose the samples for the training set if the data set is sufficiently large this often works pretty well related but slightly different way to check model is to train on many randomly selected subsets of the original dataand see how similar the models are to one another if they are quite similarthan we can feel pretty good this approach is known as cross validation