fork download
  1. import numpy as np
  2. from sklearn.linear_model import LinearRegression
  3.  
  4. # Training data: hours studied vs marks scored
  5. X = np.array([[1], [2], [3], [4], [5]]) # hours
  6. y = np.array([35, 45, 55, 65, 75]) # marks
  7.  
  8. # Create and train the model
  9. model = LinearRegression()
  10. model.fit(X, y)
  11.  
  12. # Predict for 6 hours of study
  13. prediction = model.predict([[6]])
  14. print(f"Predicted marks for 6 hours: {prediction[0]:.2f}")
Success #stdin #stdout 2.79s 103388KB
stdin
Standard input is empty
stdout
Predicted marks for 6 hours: 85.00