DS4


Q. 1) Write a PHP script to accept Employee details (Eno, Ename, Address) on first page. On second
page accept earning (Basic, DA, HRA). On third page print Employee information (Eno, Ename, Address,
Basic, DA, HRA, Total) [ Use Session] [Marks 15]

<?php session_start(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $_SESSION["employee"] = [ "Eno" => $_POST["Eno"], "Ename" => $_POST["Ename"], "Address" => $_POST["Address"] ]; header("Location: earning_details.php"); exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Employee Details</title> </head> <body> <h2>Employee Details</h2> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <label for="Eno">Employee Number:</label> <input type="text" id="Eno" name="Eno"><br><br> <label for="Ename">Employee Name:</label> <input type="text" id="Ename" name="Ename"><br><br> <label for="Address">Address:</label> <input type="text" id="Address" name="Address"><br><br> <input type="submit" value="Next"> </form> </body> </html> <?php session_start();

if (_SERVER["REQUEST_METHOD"] == "POST") { _SESSION["earnings"] = [
"Basic" => POST["Basic"],"DA"=>_POST["Basic"], "DA" => _POST["DA"],
"HRA" => $_POST["HRA"]
];
header("Location: print_employee_info.php");
exit;
}
?>

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Earning Details</title> </head> <body> <h2>Earning Details</h2> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <label for="Basic">Basic:</label> <input type="text" id="Basic" name="Basic"><br><br> <label for="DA">DA:</label> <input type="text" id="DA" name="DA"><br><br> <label for="HRA">HRA:</label> <input type="text" id="HRA" name="HRA"><br><br> <input type="submit" value="Next"> </form> </body> </html> <?php session_start();

if (!isset(SESSION["employee"])!isset(_SESSION["employee"]) || !isset(_SESSION["earnings"])) {
header("Location: employee_details.php");
exit;
}

employee=employee = _SESSION["employee"];
earnings=earnings = _SESSION["earnings"];
total=total = earnings["Basic"] + earnings["DA"]+earnings["DA"] + earnings["HRA"];
?>

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Print Employee Information</title> </head> <body> <h2>Employee Information</h2> <p>Employee Number: <?php echo $employee["Eno"]; ?></p> <p>Employee Name: <?php echo $employee["Ename"]; ?></p> <p>Address: <?php echo $employee["Address"]; ?></p> <p>Basic: <?php echo $earnings["Basic"]; ?></p> <p>DA: <?php echo $earnings["DA"]; ?></p> <p>HRA: <?php echo $earnings["HRA"]; ?></p> <p>Total: <?php echo $total; ?></p> </body> </html>

Q. 2)Build a simple linear regression model for Fish Species Weight Prediction.
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score

Load the dataset

fish_data = pd.read_csv("fish_dataset.csv")

Select features (independent variables) and target variable (dependent variable)

X = fish_data[['Species', 'Length', 'Width']] # Features
y = fish_data['Weight'] # Target variable

Encode categorical variable (Species) using one-hot encoding

X = pd.get_dummies(X, drop_first=True)

Split the dataset into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Build a linear regression model

model = LinearRegression()

Train the model

model.fit(X_train, y_train)

Make predictions

y_pred = model.predict(X_test)

Evaluate the model

mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)

print("Mean Squared Error:", mse)
print("R-squared:", r2)