Linear Regression in scikit-learn
Linear Regression in scikit-learn: Your First scikit-learn Model: fit and predict, Splitting Data with train_test_split, More Than One Feature.
Updated
- Your First scikit-learn Model: fit and predict (Journeyman): Every scikit-learn model follows the same three steps, make it, fit(X, y) to learn from examples, and predict(X) to guess for new ones, with the features X as a table even when there's only one, and a linear regression's learned slope and intercept kept in coef_ and intercept_.
- Splitting Data with train_test_split (Journeyman): train_test_split shuffles the examples and holds a share back as test data (test_size=0.2 holds back a fifth, and 25% when no size is given), random_state fixes the shuffle so every run splits the same way, and the split comes before anything learns, so the test homes stay unseen.
- More Than One Feature (Journeyman): A linear regression with several features learns one coefficient for each, read as the change in the guess for one more unit of that feature with the others held the same; a coefficient's size isn't its importance when the units differ, and features that move together, such as bedrooms and size, share the credit.