0% found this document useful (0 votes)
0 views2 pages

DMS1

The document contains two programming tasks: the first is an R program that performs addition, multiplication, and division on two integer vectors of length 4; the second is a Python program that applies simple linear regression on a student dataset to calculate mean absolute error, mean squared error, and root mean squared error. The R program uses basic vector operations, while the Python program utilizes libraries such as pandas and scikit-learn for data manipulation and model evaluation.

Uploaded by

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

DMS1

The document contains two programming tasks: the first is an R program that performs addition, multiplication, and division on two integer vectors of length 4; the second is a Python program that applies simple linear regression on a student dataset to calculate mean absolute error, mean squared error, and root mean squared error. The R program uses basic vector operations, while the Python program utilizes libraries such as pandas and scikit-learn for data manipulation and model evaluation.

Uploaded by

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

Q1.Write a R program to add, multiply and divide two vectors of integer type.

(Vector
length should be minimum 4) [10 Marks]

vector1 <- c(4, 8, 12, 16)


vector2 <- c(2, 4, 6, 8)

add <- vector1 + vector2


cat("Addition Result:\n")
print(add)

mul <- vector1 * vector2


cat("Multiplication Result:\n")
print(mul)

div <- vector1 / vector2


cat("Division Result:\n")
print(div)

#Q2.Consider the student data set. It can be downloaded from:


https://drive.google.com/open?id=1oakZCv7g3mlmCSdv9J8kdSaqO 5_6dIOw .
Write a programme in python to apply simple linear regression and find out mean
absolute error, mean squared error and root mean squared error. [20 Marks]

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error, mean_squared_error

# Load the dataset


url = "https://drive.google.com/uc?id=1oakZCv7g3mlmCSdv9J8kdSaqO5_6dIOw" # Direct
link for CSV
data = pd.read_csv(url)

# Display the first few rows of the dataset (optional)


print(data.head())

# Assume 'X' is the independent variable and 'y' is the dependent variable
# Replace 'X_column' and 'y_column' with actual column names from your dataset
X = data[['X_column']] # Independent variable(s)
y = data['y_column'] # Dependent variable

# 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=42)

# Create a linear regression model


model = LinearRegression()

# Fit the model


model.fit(X_train, y_train)
# Make predictions
y_pred = model.predict(X_test)

# Calculate Mean Absolute Error, Mean Squared Error, and Root Mean Squared Error
mae = mean_absolute_error(y_test, y_pred)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)

# Print the errors


print("Mean Absolute Error (MAE):", mae)
print("Mean Squared Error (MSE):", mse)
print("Root Mean Squared Error (RMSE):", rmse)

You might also like