Predict the Future with Regression Analysis

Using Scikit-Learn and a little bit of Python

Solve if you are a genius, or just know how to use scikit-learn

Wish life was just as simple as a linear function

You may have noticed that we used LinerRegression here. What is linear? As you have seen in the formula used, Y depended on X1 and X2, but not on something like X1², X2², X1*X2 or even X power something greater than 2, or the square root of X or such. These kind of formulae, we call them non-linear ones.

Linear and Exponential Data compared

Ain’t there other models, other that LinearRegression?

Of course, Scikit-Learn provides more complex models. Back in the early 2000’s, SVM (Support Vector Machines) was the new cool, something like Deep Learning of today. SVM can deal with non-linear data too, by using some trick called kernels. In this code, we are going to use SVM with a Polynomial kernel (i.e. non-linear) to do our regression task. We are going to use the same data as above.

Life is even more complex than we thought

In real life, data are more noisy than you think

How to tell the model we are using is a good fit or not?

Now back to your earlier question, “How to tell the model we are using is a good fit four our data or not?” Previously, we used all our data as training data. In practice, we normally split our data into two chunks. One chunk we use as our training data. I.e. we use it to train a model. The other chunk we call testing data. Once we have our model trained, we use it to predict the Y values of the testing data. Since we already know the true values of Y for the testing data anyway, we can then compare the true values to the predicted values, and decide whether our model is sound or not.

https://www.amazon.com/gp/product/B08BTFY8YW/

Hope you found this introduction to Scikit-Learn, Data Mining and Regression useful. If you find it useful, please check my new book, Hands-On Machine Learning with scikit-learn and Scientific Python Toolkits.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tarek Amr

I write about what machines can learn from data, what humans can learn from machines, and what businesses can learn from all three.