DS3
Q. 1) Write a PHP script to accept username and password. If in the first three chances, username and
password entered is correct then display second form with “Welcome message” otherwise display error
message. [Use Session] [Marks 15]
Q. 2)Create ‘User’ Data set having 5 columns namely: User ID, Gender, Age, Estimated Salary and
Purchased. Build a logistic regression model that can predict whether on the given parameter a person
will buy a car or not.
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, classification_report
Create the 'User' dataset
data = {'User ID': [1, 2, 3, 4, 5],
'Gender': ['Male', 'Female', 'Male', 'Female', 'Male'],
'Age': [25, 30, 35, 40, 45],
'Estimated Salary': [30000, 40000, 50000, 60000, 70000],
'Purchased': [0, 1, 0, 1, 0]} # 0: Not purchased, 1: Purchased
Convert the dataset into a DataFrame
df = pd.DataFrame(data)
Identify independent variables (Gender, Age, Estimated Salary) and target variable (Purchased)
X = df[['Gender', 'Age', 'Estimated Salary']]
y = df['Purchased']
Convert categorical variable (Gender) into dummy/indicator variables
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=0)
Feature scaling
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
Build a logistic regression model
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train, y_train)
Predictions
y_pred = classifier.predict(X_test)
Evaluate the model
print("Confusion Matrix:")
print(confusion_matrix(y_test, y_pred))
print("\nClassification Report:")
print(classification_report(y_test, y_pred))