SEP- AIA

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 . . .

 
  
 1. Write a program to demonstrate Simple Linear Regression to predict a value (e.g., Study Hours vs.
Marks) using a hardcoded dataset.

 
  

### Program

```python
# Simple Linear Regression
# Study Hours vs Marks

from sklearn.linear_model import LinearRegression
import numpy as np

# Hardcoded dataset
study_hours = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)
marks = np.array([35, 40, 50, 55, 65, 70])

# Create and train the model
model = LinearRegression()
model.fit(study_hours, marks)

# Get study hours from user
hours = float(input("Enter study hours: "))

# Predict marks
predicted_marks = model.predict([[hours]])

print("Predicted Marks:", round(predicted_marks[0], 2))
```

### Sample Output

```text
Enter study hours: 7
Predicted Marks: 78.57
```

### Explanation

* `study_hours` contains the input values.
* `marks` contains the corresponding output values.
* `LinearRegression()` creates the regression model.
* `model.fit()` trains the model using the hardcoded dataset.
* `model.predict()` predicts the marks for the given number of study hours.

The program demonstrates the basic relationship:

**Study Hours → Linear Regression Model → Predicted Marks**