0% found this document useful (0 votes)
2 views3 pages

Data Analysis and Model Evaluation Steps

The document outlines a series of tasks for data processing and machine learning using Python. It includes loading a dataset, handling missing values, encoding categorical data, splitting the dataset, and applying various algorithms like Linear Regression, Decision Trees, Support Vector Machines, and K-Nearest Neighbors to evaluate their performance. Each task is accompanied by code snippets demonstrating the implementation and evaluation metrics.

Uploaded by

arshadimam111
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)
2 views3 pages

Data Analysis and Model Evaluation Steps

The document outlines a series of tasks for data processing and machine learning using Python. It includes loading a dataset, handling missing values, encoding categorical data, splitting the dataset, and applying various algorithms like Linear Regression, Decision Trees, Support Vector Machines, and K-Nearest Neighbors to evaluate their performance. Each task is accompanied by code snippets demonstrating the implementation and evaluation metrics.

Uploaded by

arshadimam111
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

Q.1 Load the dataset and display the first 5 rows and basic statistics.

import pandas as pd
data = pd.read_csv('[Link]')
print([Link]())
print([Link]())

Q.2 Check for missing values and fill them using the mean.
print([Link]().sum())
[Link]([Link](), inplace=True)
print([Link]().sum())

Q.3 Encode the "Gender" column using Label Encoding.


from [Link] import LabelEncoder
le = LabelEncoder()
data['Gender'] = le.fit_transform(data['Gender'])
print([Link]())

Q.4 Split the dataset into training (80%) and testing (20%).
from sklearn.model_selection import train_test_split
X = [Link]('Target', axis=1)
y = data['Target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)
print(X_train.shape, X_test.shape)
Q.5 Apply Linear Regression and calculate the Mean Squared Error .
from sklearn.linear_model import LinearRegression
from [Link] import mean_squared_error
lr = LinearRegression()
[Link](X_train, y_train)
y_pred = [Link](X_test)
mse = mean_squared_error(y_test, y_pred)
print(f"Mean Squared Error: {mse}")

Q.6 Apply Decision Tree on the Iris dataset and find accuracy.
from [Link] import load_iris
from [Link] import DecisionTreeClassifier
from [Link] import accuracy_score
iris = load_iris()
X, y = [Link], [Link]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=1)
dt = DecisionTreeClassifier()
[Link](X_train, y_train)
y_pred = [Link](X_test)
acc = accuracy_score(y_test, y_pred)
print(f"Accuracy: {acc}")
Q.7 Apply Support Vector Machine (SVM) and check accuracy.
from [Link] import SVC
svm = SVC()
[Link](X_train, y_train)
y_pred = [Link](X_test)
acc = accuracy_score(y_test, y_pred)
print(f"SVM Accuracy: {acc}")

Q.8 Apply K-Nearest Neighbors (KNN) and check accuracy.


from [Link] import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=5)
[Link](X_train, y_train)
y_pred = [Link](X_test)
acc = accuracy_score(y_test, y_pred)
print(f"KNN Accuracy: {acc}")

You might also like