OneCompiler

DS2

156

Q. 1Write a PHP script to change the preferences of your web page like font style, font size, font color,
background color using cookie. Display selected setting on next web page and actual implementation
(with new settings) on third page (Use Cookies). [Marks 15]

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Preferences</title> </head> <body> <h2>Page Preferences</h2> <form action="set_preferences.php" method="post"> <label for="fontStyle">Font Style:</label> <select name="fontStyle" id="fontStyle"> <option value="Arial">Arial</option> <option value="Verdana">Verdana</option> <option value="Times New Roman">Times New Roman</option> </select><br><br> <label for="fontSize">Font Size:</label> <select name="fontSize" id="fontSize"> <option value="small">Small</option> <option value="medium">Medium</option> <option value="large">Large</option> </select><br><br> <label for="fontColor">Font Color:</label> <input type="color" name="fontColor" id="fontColor"><br><br> <label for="bgColor">Background Color:</label> <input type="color" name="bgColor" id="bgColor"><br><br> <input type="submit" value="Save Preferences"> </form> </body> </html>

Q. 2)Create ‘Salary’ Data set . Build a linear regression model by identifying independent and target
variable. Split the variables into tr
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression

Create the salary dataset

data = {'YearsExperience': [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5],
'Salary': [30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000]}

Convert the dataset into a DataFrame

df = pd.DataFrame(data)

Identify independent and target variables

X = df[['YearsExperience']] # Independent variable (Years of Experience)
y = df['Salary'] # Target variable (Salary)

Split the variables into training and testing sets

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

Print the training and testing sets

print("Training set:")
print(X_train)
print(y_train)
print("\nTesting set:")
print(X_test)
print(y_test)

Build a simple linear regression model

model = LinearRegression()
model.fit(X_train, y_train)