Train/Test Split and Linear Regression
Using the notes' own hours-studied-vs-exam-scores dataset, split it with traintestsplit, train a LinearRegression model, and predict the score for a given number of study hours.
Approach: use the exact dataset, testsize, and randomstate from the notes so the split is reproducible, fit a LinearRegression, then predict for the given hours value.
Input: One line: the number of hours studied to predict a score for.
Output: One line: the predicted exam score, to 2 decimal places.
7.5
85.88
- 0 <= hours <= 24
Hint 1
model.fit(X_train, y_train) trains the model on the training split only.
Hint 2
model.predict([[hours]]) expects a 2D list — one row, one feature — matching the shape of hours_studied.
Hint 3
random_state=42 makes the train/test split reproducible, so the same input always gives the same trained model and prediction.
Using the exact same dataset, testsize, and randomstate as the notes guarantees the train/test split — and therefore the fitted model — is identical every run. model.fit(Xtrain, ytrain) trains on just the training portion, and model.predict([[hours]]) then applies the learned line to the requested input.