DS1


Q. 1) Write a PHP script to keep track of number of times the web page has been accessed (Use Session
Tracking).
[Marks 15]

<?php session_start(); // Check if the session variable for page views exists if (!isset($_SESSION['page_views'])) { $_SESSION['page_views'] = 1; // If not, initialize it to 1 } else { $_SESSION['page_views']++; // If exists, increment it by 1 } echo "You have visited this page " . $_SESSION['page_views'] . " times."; ?>

Q. 2)Create ‘Position_Salaries’ Data set. Build a linear regression model by identifying independent and
target variable. Split the variables into training and testing sets. then divide the training and testing sets
into a 7:3 ratio, respectively and print them. Build a simple linear regression model.
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression

Create the dataset

data = {'Position': ['Business Analyst', 'Junior Consultant', 'Senior Consultant', 'Manager', 'Country Manager', 'Region Manager', 'Partner', 'Senior Partner', 'C-level', 'CEO'],
'Level': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'Salary': [45000, 50000, 60000, 80000, 110000, 150000, 200000, 300000, 500000, 1000000]}

Convert the dataset into a DataFrame

df = pd.DataFrame(data)

Identify independent and target variables

X = df[['Level']] # Independent variable (Level)
y = df['Salary'] # Target variable (Salary)

Split the variables into training and testing sets in a 7:3 ratio

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)