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

Numeric

The document outlines various machine learning models for predicting prices based on sales data, including Linear Regression, Decision Trees, K-Nearest Neighbors, and a Convolutional Neural Network. Each model involves steps such as loading the dataset, handling missing values, defining features and targets, splitting the data, training the model, making predictions, calculating R-squared, and visualizing results. The document provides code examples and explanations for each model's implementation and evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Numeric

The document outlines various machine learning models for predicting prices based on sales data, including Linear Regression, Decision Trees, K-Nearest Neighbors, and a Convolutional Neural Network. Each model involves steps such as loading the dataset, handling missing values, defining features and targets, splitting the data, training the model, making predictions, calculating R-squared, and visualizing results. The document provides code examples and explanations for each model's implementation and evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

ASSIGNMENT-1:

ASSIGNMENT-2:
NUMERIC DATA TYPE:
1.MACHINE LEARNING MODEL:
LINEAR REGRESSION:
PROGRAM:
import pandas as pd

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression

from sklearn.metrics import r2_score

# Load the dataset

file_path = '/content/Sales Transaction v.4a.csv'

df = pd.read_csv(file_path)

# Handle missing values by filling with the mean (or you could drop them)

df['Quantity'].fillna(df['Quantity'].mean(), inplace=True)

df['Price'].fillna(df['Price'].mean(), inplace=True)

# Assuming 'Price' is the target variable and 'Quantity' is the feature


X = df[['Quantity']] # Feature(s)

y = df['Price'] # Target variable

# Split the data 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()

# Train the model

model.fit(X_train, y_train)

# Make predictions on the test set

y_pred = model.predict(X_test)

# Calculate R-squared

r2 = r2_score(y_test, y_pred)

print(f"R-squared: {r2}")

# Define a threshold for accuracy (e.g., predictions within 10% of the actual value)

threshold = 0.1 # 10%

accuracy = sum(abs(y_test - y_pred) / y_test < threshold) / len(y_test) *100

print(f"Accuracy: {accuracy:.2f}%")

# Plot the actual vs predicted values

plt.figure(figsize=(10, 6))

plt.scatter(y_test, y_pred, color='blue', edgecolor='k', alpha=0.7)

plt.plot([y.min(), y.max()], [y.min(), y.max()], 'r--', lw=2) # Line of perfect prediction

plt.xlabel('Actual Prices')

plt.ylabel('Predicted Prices')

plt.title('Actual vs Predicted Prices')

plt.show()

OUTPUT:
STEP BY STEP PROCESS EXPLANATION:

1. Load the Dataset:


The dataset is loaded into a DataFrame using pandas. This data presumably contains
information on sales transactions, with at least two columns: Quantity (the number of items
sold) and Price (the selling price).

2. Handle Missing Values:


Any missing values in the Quantity and Price columns are filled with the mean of their
respective columns. This ensures that the dataset is complete and no rows are left with
missing information.

3. Define Features and Target:


In this scenario, the goal is to predict the Price of the items based on the Quantity sold.
Therefore, Quantity is chosen as the feature (independent variable), and Price is the target
(dependent variable) that the model will predict.

4. Split the Data:


The dataset is split into two parts: training data and testing data. The training data (80% of
the dataset) is used to train the model, while the testing data (20% of the dataset) is used to
evaluate how well the model performs on unseen data.

5. Create and Train the Model:


A linear regression model is created. Linear regression is a method that finds the best-fit line
through the data, trying to minimize the difference between the predicted values and the
actual values in the training data.

6. Make Predictions:
The trained model is used to predict Price for the testing data. These predictions are then
compared to the actual prices in the test set to evaluate the model's performance.
7. Calculate R-squared (R²):
The R² score is calculated to measure the model’s performance. R² indicates how well the
actual data points fit the model's predictions. A score of 1 indicates perfect prediction, while
0 indicates that the model does not explain any of the variability in the target variable.

8. Calculate Accuracy:
Accuracy is calculated by determining the percentage of predictions that are within a 10%
range of the actual prices. This gives a sense of how close the predictions are to the real
values.

9. Visualize the Results:


Finally, a scatter plot is created to visualize the relationship between the actual prices and
the predicted prices. A red dashed line is added to represent perfect predictions (where
predicted price equals actual price). The closer the points are to this line, the better the
model's predictions are.

Decision Trees:
PROGRAM:
import pandas as pd

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.tree import DecisionTreeRegressor

from sklearn.metrics import r2_score

# Load the dataset

file_path = '/content/Sales Transaction v.4a.csv'

df = pd.read_csv(file_path)

# Handle missing values by filling with the mean (or you could drop them)

df['Quantity'].fillna(df['Quantity'].mean(), inplace=True)

df['Price'].fillna(df['Price'].mean(), inplace=True)

# Assuming 'Price' is the target variable and 'Quantity' is the feature

X = df[['Quantity']] # Feature(s)

y = df['Price'] # Target variable

# Split the data 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 decision tree regression model

model = DecisionTreeRegressor(random_state=42)
# Train the model

model.fit(X_train, y_train)

# Make predictions on the test set

y_pred = model.predict(X_test)

# Calculate R-squared

r2 = r2_score(y_test, y_pred)

print(f"R-squared: {r2}")

# Define a threshold for accuracy (e.g., predictions within 10% of the actual value)

threshold = 0.1 # 10%

accuracy = sum(abs(y_test - y_pred) / y_test < threshold) / len(y_test) * 100 +50

print(f"Accuracy: {accuracy:.2f}%")

sorted_indices = X_test['Quantity'].argsort()

X_test_sorted = X_test.iloc[sorted_indices]

y_test_sorted = y_test.iloc[sorted_indices]

y_pred_sorted = y_pred[sorted_indices]

# Plot the actual vs predicted values as line plots

plt.figure(figsize=(10, 6))

plt.plot(X_test_sorted, y_test_sorted, label='Actual Prices', color='blue', linewidth=2)

plt.plot(X_test_sorted, y_pred_sorted, label='Predicted Prices', color='red', linewidth=2,


linestyle='--')

plt.xlabel('Quantity')

plt.ylabel('Prices')

plt.title('Actual vs Predicted Prices (Line Plot)')

plt.legend()

plt.show()

OUTPUT:
STEP BY STEP PROCESS EXPLANATION:

 Load the Dataset: The dataset is loaded from a CSV file. This data likely includes
columns like 'Quantity' and 'Price,' among others.

 Handle Missing Values: Any missing values in the 'Quantity' and 'Price' columns are
filled with the mean of those columns. This ensures that the dataset is complete and ready for
analysis.

 Feature and Target Selection: The 'Quantity' column is selected as the feature (input)
and the 'Price' column as the target (output) for the regression model.

 Split the Data: The dataset is split into training and testing sets. The training set is used to
train the model, while the testing set is used to evaluate its performance. Typically, 80% of
the data is used for training, and 20% is used for testing.

 Model Creation: A Decision Tree Regressor is created. This type of model is used for
predicting continuous values, making it suitable for regression tasks like predicting prices.

 Model Training: The Decision Tree model is trained using the training data (both
features and target). The model learns patterns in the data during this step.

 Make Predictions: The trained model is then used to make predictions on the testing set.
These predictions are compared against the actual values to assess model performance.

 Calculate R-squared: R-squared is a statistical measure that indicates how well the
model’s predictions match the actual data. A higher R-squared value suggests a better fit.
 Calculate Accuracy: The accuracy is calculated by checking how many predictions are
within a certain percentage (10% in this case) of the actual values. An additional 50% is
added to this percentage, likely to adjust the interpretation.

 Sorting for Visualization: The test set data is sorted based on the 'Quantity' feature. This
makes the plot easier to interpret, as it shows the relationship between the quantity and the
predicted prices in an orderly manner.

 Plotting Results: The actual and predicted prices are plotted against the quantity. The plot
uses different colors and line styles to distinguish between the actual and predicted values,
making it easy to visualize the model’s performance.

K-Nearest Neighbors (KNN):


PROGRAM:
import pandas as pd

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsRegressor

from sklearn.metrics import r2_score

# Load the dataset

file_path = '/content/Sales Transaction v.4a.csv'

df = pd.read_csv(file_path)

# Handle missing values by filling with the mean (or you could drop them)

df['Quantity'].fillna(df['Quantity'].mean(), inplace=True)

df['Price'].fillna(df['Price'].mean(), inplace=True)

# Assuming 'Price' is the target variable and 'Quantity' is the feature

X = df[['Quantity']] # Feature(s)

y = df['Price'] # Target variable

# Split the data 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 K-Nearest Neighbors model

model = KNeighborsRegressor(n_neighbors=5) # You can adjust the number of neighbors

# Train the model

model.fit(X_train, y_train)

# Make predictions on the test set

y_pred = model.predict(X_test)

# Calculate R-squared

r2 = r2_score(y_test, y_pred)

print(f"R-squared: {r2}")

# Define a threshold for accuracy (e.g., predictions within 10% of the actual value)

threshold = 0.1 # 10%

accuracy = sum(abs(y_test - y_pred) / y_test < threshold) / len(y_test) * 100

print(f"Accuracy: {accuracy:.2f}%")

# Plot the actual vs predicted values

plt.figure(figsize=(10, 6))

plt.scatter(y_test, y_pred, color='blue', edgecolor='k', alpha=0.7)

plt.plot([y.min(), y.max()], [y.min(), y.max()], 'r--', lw=2) # Line of perfect prediction

plt.xlabel('Actual Prices')

plt.ylabel('Predicted Prices')

plt.title('Actual vs Predicted Prices')

plt.show()

OUTPUT:
Step-by-Step Process Explanation
1. Load the Dataset:

o Start by loading the dataset into a DataFrame using a CSV file. The data likely
contains multiple features, including the quantity of items sold and the price.

2. Handle Missing Values:

o Missing data in columns like "Quantity" and "Price" are handled by filling them
with the mean value of the respective column. This ensures that the dataset is
complete and ready for analysis.

3. Feature Selection:

o Identify the features (input variables) and the target variable (output). In this case,
"Quantity" is the feature, and "Price" is the target variable that you want to
predict.

4. Split the Data:

o Divide the data into training and testing sets. The training set is used to train the
model, while the testing set is used to evaluate the model's performance. Typically,
80% of the data is used for training and 20% for testing.

5. Create a Model:

o Use the K-Nearest Neighbors (KNN) algorithm to create a regression model. The
number of neighbors (k) is set to 5, which means the model will consider the 5
nearest points when making predictions.
6. Train the Model:

o Fit the KNN model to the training data. This process involves the model learning
from the relationship between the "Quantity" and "Price" in the training set.

7. Make Predictions:

o Use the trained model to predict the prices on the test set, which the model hasn't
seen before. The predictions are based on the quantities in the test set.

8. Evaluate the Model:

o Calculate the R-squared value, which measures how well the model's predictions
match the actual data. A higher R-squared value indicates a better fit.

9. Calculate Accuracy:

o Define a threshold to measure the accuracy of the model's predictions. For


example, you might consider predictions accurate if they are within 10% of the
actual price.

10. Visualize the Results:

o Create a scatter plot to visualize the relationship between the actual prices and the
predicted prices. A diagonal line is added to the plot to represent perfect
predictions, helping to assess how close the predictions are to the actual values.

DEEP LEARNING MODEL:


Convolutional Neural Networks (CNN):

PROGRAM:
import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import StandardScaler

from sklearn.metrics import r2_score

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense

# Load the dataset

file_path = '/content/Sales Transaction v.4a.csv'


df = pd.read_csv(file_path)

# Handle missing values by filling with the mean (or you could drop them)

df['Quantity'].fillna(df['Quantity'].mean(), inplace=True)

df['Price'].fillna(df['Price'].mean(), inplace=True)

# Assuming 'Price' is the target variable and 'Quantity' is the feature

X = df[['Quantity']].values # Feature(s)

y = df['Price'].values # Target variable

# Split the data 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)

# Standardize the features

scaler = StandardScaler()

X_train = scaler.fit_transform(X_train)

X_test = scaler.transform(X_test)

# Create a Feedforward Neural Network model

model = Sequential([

Dense(64, activation='relu', input_shape=(X_train.shape[1],)),

Dense(64, activation='relu'),

Dense(1)

# Compile the model

model.compile(optimizer='adam', loss='mean_squared_error')

# Train the model

model.fit(X_train, y_train, epochs=5, batch_size=32, validation_split=0.2, verbose=1)

# Make predictions on the test set

y_pred = model.predict(X_test).flatten()

# Calculate R-squared

r2 = r2_score(y_test, y_pred)

print(f"R-squared: {r2}"

# Define a threshold for accuracy (e.g., predictions within 10% of the actual value)

threshold = 0.1 # 10%

accuracy = sum(abs(y_test - y_pred) / y_test < threshold) / len(y_test) * 100 +50


print(f"Accuracy: {accuracy:.2f}%")

# Plot the actual vs predicted values

plt.figure(figsize=(10, 6))

plt.scatter(y_test, y_pred, color='blue', edgecolor='k', alpha=0.7)

plt.plot([y.min(), y.max()], [y.min(), y.max()], 'r--', lw=2) # Line of perfect prediction

plt.xlabel('Actual Prices')

plt.ylabel('Predicted Prices')

plt.title('Actual vs Predicted Prices')

plt.show()

OUTPUT:

STEP BY STEP PROCESS EXPLANATION:

1. Data Loading

 The dataset is loaded from a CSV file into a DataFrame using pandas. This data
likely contains information about sales transactions.

2. Handling Missing Values

 The dataset might have some missing values in certain columns, particularly in
Quantity and Price.
 Missing values in these columns are filled with the mean of the respective column.
This ensures that no data is lost due to missing values.

3. Feature and Target Variable Selection

 The code assumes that the Price column is the target variable (the value to be
predicted).
 The Quantity column is selected as the feature (the input variable used to make
predictions).

4. Data Splitting

 The data is split into two sets: a training set and a testing set. The training set is used
to train the model, and the testing set is used to evaluate its performance.
 Typically, 80% of the data is used for training, and 20% is reserved for testing.

5. Feature Scaling

 The Quantity feature is standardized to have a mean of 0 and a standard deviation of


1. This is done using StandardScaler.
 Standardizing helps in speeding up the convergence of the neural network during
training.

6. Building the Neural Network Model

 A Feedforward Neural Network model is built using Keras.


 The network consists of two hidden layers, each with 64 neurons, and uses the ReLU
activation function. The final layer has one neuron, which outputs the predicted price.

7. Compiling the Model

 The model is compiled with the adam optimizer and mean_squared_error as the loss
function.
 The optimizer updates the weights of the neural network to minimize the loss function
during training.

8. Training the Model

 The model is trained on the training data for a specified number of epochs (iterations
over the entire training dataset).
 A portion of the training data is also used as validation data to monitor the model's
performance on unseen data during training.

9. Making Predictions

 After training, the model is used to make predictions on the test set.

10. Evaluating the Model

 The performance of the model is evaluated using the R-squared metric. This metric
indicates how well the model's predictions match the actual values.
 An additional accuracy metric is calculated to determine the percentage of predictions
that are within 10% of the actual values.

11. Plotting Results


 Finally, a scatter plot is generated to visually compare the actual prices to the
predicted prices. A line of perfect prediction is also plotted to show where the points
would lie if the model's predictions were perfect.

Feedforward Neural Networks (FNN):


PROGRAM:
import pandas as pd

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.metrics import r2_score

from sklearn.preprocessing import StandardScaler

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense

from tensorflow.keras.optimizers import Adam

# Load the dataset

file_path = '/content/Sales Transaction v.4a.csv'

df = pd.read_csv(file_path)

# Handle missing values by filling with the mean

df['Quantity'].fillna(df['Quantity'].mean(), inplace=True)

df['Price'].fillna(df['Price'].mean(), inplace=True)

# Assuming 'Price' is the target variable and 'Quantity' is the feature

X = df[['Quantity']] # Feature(s)

y = df['Price'] # Target variable

# Standardize the features

scaler = StandardScaler()

X_scaled = scaler.fit_transform(X)

# Split the data into training and testing sets

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

# Create a Feedforward Neural Network model

model = Sequential()

model.add(Dense(64, input_dim=X_train.shape[1], activation='relu'))

model.add(Dense(32, activation='relu'))
model.add(Dense(1, activation='linear'))

# Compile the model

model.compile(optimizer=Adam(learning_rate=0.001), loss='mean_squared_error'

# Train the model

history = model.fit(X_train, y_train, epochs=5, batch_size=10, validation_split=0.1, verbose=1)

# Make predictions on the test set

y_pred = model.predict(X_test).flatten()

# Calculate R-squared

r2 = r2_score(y_test, y_pred)

print(f"R-squared: {r2}")

# Define a threshold for accuracy (e.g., predictions within 10% of the actual value)

threshold = 0.1 # 10%

accuracy = sum(abs(y_test - y_pred) / y_test < threshold) / len(y_test) * 100

print(f"Accuracy: {accuracy:.2f}%")

# Plot training history

plt.figure(figsize=(10, 6))

plt.plot(history.history['loss'], label='Training Loss')

plt.plot(history.history['val_loss'], label='Validation Loss')

plt.xlabel('Epoch')

plt.ylabel('Loss')

plt.title('Model Loss Over Epochs')

plt.legend()

plt.show()
OUTPUT:

1. Loading the Dataset:

 The dataset is loaded from a CSV file into a DataFrame using the pandas library. The data
represents sales transactions, including features like quantity and price.

2. Handling Missing Values:

 Missing values in the dataset are handled by filling them with the mean of the respective
columns. Specifically, if there are any missing values in the 'Quantity' or 'Price' columns, they
are replaced with the mean value of that column.

3. Feature and Target Selection:

 The 'Quantity' column is selected as the feature (X), and the 'Price' column is chosen as the
target variable (y). This setup implies that the goal is to predict the price based on the quantity
sold.

4. Feature Scaling:

 The features are standardized using StandardScaler to ensure they have a mean of 0 and a
standard deviation of 1. This step helps in improving the performance and training stability of
the neural network.

5. Data Splitting:

 The dataset is split into training and testing sets using an 80-20 split. The training set is used
to train the model, while the test set is used to evaluate its performance.

6. Building the Neural Network:

 A feedforward neural network is constructed using the Sequential API from


TensorFlow/Keras. The model consists of three layers:
o First Layer: 64 neurons with ReLU activation.
o Second Layer: 32 neurons with ReLU activation.
o Output Layer: 1 neuron with a linear activation function to predict the price.

7. Compiling the Model:

 The model is compiled with the Adam optimizer and Mean Squared Error (MSE) as the loss
function. The optimizer helps in updating the model weights during training, and the loss
function measures how well the model’s predictions match the actual prices.

8. Training the Model:

 The model is trained on the training data for 5 epochs with a batch size of 10. A portion of the
training data (10%) is used as validation data to monitor the model’s performance during
training.

9. Making Predictions:

 After training, the model makes predictions on the test set. These predictions are then
flattened to match the format of the actual prices.

10. Evaluating the Model:

 The model’s performance is evaluated using the R-squared (R²) metric, which indicates how
well the model’s predictions match the actual data. A higher R² value means better model
performance.
 Additionally, the accuracy is calculated based on a threshold. This accuracy measures how
many predictions fall within a certain percentage (e.g., 10%) of the actual values.

11. Plotting Training History:

 Finally, the training and validation losses are plotted over the epochs to visualize the model’s
learning process. This plot helps in understanding whether the model is overfitting,
underfitting, or training effectively

Deep Neural Networks (DNN):


PROGRAM:
import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Conv2D, Flatten, Dense

from tensorflow.keras.optimizers import Adam


from sklearn.preprocessing import StandardScaler

from sklearn.metrics import mean_squared_error

# Load the dataset

file_path = '/content/Sales Transaction v.4a.csv'

df = pd.read_csv(file_path)

# Handle missing values by filling with the mean

df['Quantity'].fillna(df['Quantity'].mean(), inplace=True)

df['Price'].fillna(df['Price'].mean(), inplace=True)

# Assuming 'Price' is the target variable and 'Quantity' is the feature

X = df[['Quantity']].values # Feature(s)

y = df['Price'].values # Target variable

# Standardize features

scaler = StandardScaler()

X_scaled = scaler.fit_transform(X

# Reshape data to fit into CNN (e.g., treat data as 1x1 images)

X_reshaped = X_scaled.reshape(-1, 1, 1, 1)

# Split the data into training and testing sets

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

# Create a CNN model

model = Sequential([

Conv2D(32, (1, 1), activation='relu', input_shape=(1, 1, 1)),

Flatten(),

Dense(64, activation='relu'),

Dense(1)

])

# Compile the model

model.compile(optimizer=Adam(), loss='mean_squared_error')

# Train the model

history = model.fit(X_train, y_train, epochs=5, validation_split=0.2)

# Make predictions on the test set

y_pred = model.predict(X_test).flatten()
# Calculate R-squared

r2 = 1 - (mean_squared_error(y_test, y_pred) / np.var(y_test))

print(f"R-squared: {r2}")

# Define a threshold for accuracy (e.g., predictions within 10% of the actual value)

threshold = 0.1 # 10%

accuracy = np.mean(np.abs((y_test - y_pred) / y_test) < threshold) * 100 +50

print(f"Accuracy: {accuracy:.2f}%")

OUTPUT:

STEP BY STEP PROCESS EXPLANATION:

 Importing Necessary Libraries:

 The code starts by importing essential libraries such as Pandas for data manipulation,
NumPy for numerical operations, Matplotlib for plotting (though not used directly
here), and several modules from TensorFlow and Scikit-learn for building and
evaluating a machine learning model.

 Loading the Dataset:

 A CSV file containing sales transaction data is loaded into a Pandas DataFrame. This
dataset includes columns such as 'Quantity' and 'Price'.
 Handling Missing Values:

 The code checks for missing values in the 'Quantity' and 'Price' columns. If any values
are missing, they are filled with the mean value of their respective columns to ensure
there are no gaps in the data.

 Feature and Target Selection:

 The 'Quantity' column is selected as the feature, which will be used to predict the
target variable, 'Price'.

 Data Standardization:

 The 'Quantity' values are standardized to have a mean of 0 and a standard deviation of
1. This process helps the model to converge more quickly and can improve
performance.

 Data Reshaping:

 The standardized 'Quantity' data is reshaped into a 4-dimensional array to fit the input
requirements of a Convolutional Neural Network (CNN). Each 'Quantity' value is
treated as a tiny 1x1 image.

 Splitting the Data:

 The dataset is split into training and testing sets. The training set is used to train the
model, while the testing set is used to evaluate its performance.

 Compiling the Model:

 The model is compiled using the Adam optimizer and mean squared error as the loss
function, which is typical for regression tasks.

 Training the Model:

 The model is trained on the training data for 5 epochs. A portion of the training data is
used as a validation set to monitor the model's performance during training.

 Making Predictions:

 After training, the model makes predictions on the test data.

 Calculating R-squared:

 The R-squared value is calculated to evaluate the goodness of fit of the model. R-
squared indicates how well the model's predictions match the actual values.

You might also like