0% found this document useful (0 votes)
11 views1 page

2021BCS0103 ML

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

2021BCS0103 ML

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Start coding or generate with AI.

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 accuracy_score, classification_report

df=pd.read_csv('/content/Social_Network_Ads.csv')

df.head()

output Age EstimatedSalary Purchased

0 19 19000 0

1 35 20000 0

2 26 43000 0

3 27 57000 0

4 19 76000 0

Next steps: Generate code with df


toggle_off View recommended plots

df.shape

(400, 3)

X = df.drop("Purchased", axis=1)
y = df["Purchased"]

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

scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

model = LogisticRegression()
model.fit(X_train_scaled, y_train)

predictions = model.predict(X_test_scaled)

accuracy = accuracy_score(y_test, predictions)


print("Accuracy:", accuracy)

print("Classification Report:")
print(classification_report(y_test, predictions))

Accuracy: 0.8625
Classification Report:
precision recall f1-score support

0 0.85 0.96 0.90 52


1 0.90 0.68 0.78 28

accuracy 0.86 80
macro avg 0.88 0.82 0.84 80
weighted avg 0.87 0.86 0.86 80

Start coding or generate with AI.

You might also like